@makefully/platypus 4.1.5 → 4.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +3 -3
- package/lib/platypus.js +1 -1
- package/package.json +7 -6
- package/src/AABB.js +685 -0
- package/src/ActionState.js +121 -0
- package/src/AssetManager.js +206 -0
- package/src/CollisionData.js +96 -0
- package/src/CollisionDataContainer.js +127 -0
- package/src/CollisionShape.js +315 -0
- package/src/Component.js +231 -0
- package/src/Data.js +64 -0
- package/src/DataMap.js +204 -0
- package/src/Entity.js +404 -0
- package/src/EntityLinker.js +113 -0
- package/src/EventHandler.js +115 -0
- package/src/EventHandlerList.js +251 -0
- package/src/Game.js +840 -0
- package/src/Gamepad.js +175 -0
- package/src/ID3CaptionPlayer.js +61 -0
- package/src/Messenger.js +365 -0
- package/src/PIXIAnimation.js +622 -0
- package/src/RandomSet.js +140 -0
- package/src/SFXPlayer.js +120 -0
- package/src/StateMap.js +252 -0
- package/src/Storage.js +152 -0
- package/src/TickerClient.js +48 -0
- package/src/TickerServer.js +23 -0
- package/src/TimeEvent.js +50 -0
- package/src/TimeEventList.js +100 -0
- package/src/VOPlayer.js +684 -0
- package/src/Vector.js +702 -0
- package/src/components/AIChaser.js +161 -0
- package/src/components/AIPacer.js +107 -0
- package/src/components/AudioMusic.js +151 -0
- package/src/components/AudioSFX.js +673 -0
- package/src/components/AudioVO.js +301 -0
- package/src/components/CollisionBasic.js +826 -0
- package/src/components/CollisionFilter.js +74 -0
- package/src/components/CollisionGroup.js +448 -0
- package/src/components/CollisionTiles.js +608 -0
- package/src/components/ComponentSwitcher.js +173 -0
- package/src/components/ControllerInput.js +65 -0
- package/src/components/Counter.js +165 -0
- package/src/components/EntityCamera.js +215 -0
- package/src/components/EntityContainer.js +549 -0
- package/src/components/EntityController.js +541 -0
- package/src/components/HandlerCamera.js +1052 -0
- package/src/components/HandlerCollision.js +1318 -0
- package/src/components/HandlerController.js +291 -0
- package/src/components/HandlerLogic.js +394 -0
- package/src/components/HandlerRender.js +217 -0
- package/src/components/Interactive.js +502 -0
- package/src/components/LevelBuilder.js +524 -0
- package/src/components/LogicAngularMovement.js +154 -0
- package/src/components/LogicAttachment.js +265 -0
- package/src/components/LogicButton.js +466 -0
- package/src/components/LogicCarrier.js +39 -0
- package/src/components/LogicDestroyMe.js +58 -0
- package/src/components/LogicDirectionalMovement.js +325 -0
- package/src/components/LogicDragDrop.js +371 -0
- package/src/components/LogicImpactLaunch.js +144 -0
- package/src/components/LogicPacingPlatform.js +64 -0
- package/src/components/LogicPortable.js +112 -0
- package/src/components/LogicPortal.js +115 -0
- package/src/components/LogicPushable.js +98 -0
- package/src/components/LogicRebounder.js +136 -0
- package/src/components/LogicRegionSpawner.js +139 -0
- package/src/components/LogicRotationalMovement.js +205 -0
- package/src/components/LogicSpawner.js +159 -0
- package/src/components/LogicStateMachine.js +382 -0
- package/src/components/LogicSwitch.js +77 -0
- package/src/components/LogicTeleportee.js +68 -0
- package/src/components/LogicTeleporter.js +93 -0
- package/src/components/LogicTimer.js +178 -0
- package/src/components/LogicWindUpRacer.js +179 -0
- package/src/components/Motion.js +371 -0
- package/src/components/Mover.js +566 -0
- package/src/components/Node.js +289 -0
- package/src/components/NodeMap.js +295 -0
- package/src/components/NodeResident.js +636 -0
- package/src/components/Orientation.js +697 -0
- package/src/components/RandomEvents.js +73 -0
- package/src/components/RelativePosition.js +204 -0
- package/src/components/RelayFamily.js +106 -0
- package/src/components/RelayGame.js +53 -0
- package/src/components/RelayLinker.js +94 -0
- package/src/components/RelayParent.js +57 -0
- package/src/components/RelaySelf.js +55 -0
- package/src/components/Render.js +178 -0
- package/src/components/RenderAnimator.js +275 -0
- package/src/components/RenderContainer.js +646 -0
- package/src/components/RenderDebug.js +319 -0
- package/src/components/RenderDestroyMe.js +59 -0
- package/src/components/RenderLottie.js +149 -0
- package/src/components/RenderProgress.js +120 -0
- package/src/components/RenderSpine.js +840 -0
- package/src/components/RenderSprite.js +527 -0
- package/src/components/RenderText.js +147 -0
- package/src/components/RenderTiles.js +1440 -0
- package/src/components/SceneChanger.js +128 -0
- package/src/components/TiledLoader.js +1459 -0
- package/src/components/Timeline.js +314 -0
- package/src/components/Tutorial.js +267 -0
- package/src/components/Tween.js +296 -0
- package/src/components/VoiceOver.js +373 -0
- package/src/components/XHR.js +129 -0
- package/src/components/index.js +79 -0
- package/src/factory.js +305 -0
- package/src/index.js +159 -0
- package/src/mixins/PIXI.Graphics.js +41 -0
- package/src/platypus.css +68 -0
- package/src/sayHello.js +50 -0
- package/src/shapes/Capsule.js +74 -0
- package/src/shapes/Circle.js +43 -0
- package/src/shapes/Ellipse.js +117 -0
- package/src/shapes/Point.js +191 -0
- package/src/shapes/Polygon.js +112 -0
- package/src/shapes/Polyline.js +97 -0
- package/src/shapes/Rectangle.js +78 -0
- package/src/shapes/RoundedRectangle.js +33 -0
- package/src/shapes/Segment.js +346 -0
- package/src/shapes/adjustedXY.js +19 -0
- package/src/shapes/castFromBox2D.js +92 -0
- package/src/shapes/castFromObject.js +53 -0
- package/src/shapes/castFromPixiGraphics.js +6 -0
- package/src/shapes/castFromPixiShape.js +89 -0
- package/src/shapes/castToBox2D.js +190 -0
- package/src/shapes/castToPixiGraphics.js +100 -0
- package/src/shapes/castToPixiShape.js +61 -0
- package/src/shapes/checkPointsMap.js +313 -0
- package/src/shapes/index.js +35 -0
- package/src/utils/array.js +73 -0
- package/src/utils/string.js +39 -0
- package/lib/243.platypus.mjs +0 -1
- package/lib/platypus.mjs +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/* global window */
|
|
2
|
+
import createComponentClass from '../factory.js';
|
|
3
|
+
|
|
4
|
+
const
|
|
5
|
+
XMLHttpRequest = window.XMLHttpRequest;
|
|
6
|
+
|
|
7
|
+
export default createComponentClass(/** @lends platypus.components.XHR.prototype */{
|
|
8
|
+
id: 'XHR',
|
|
9
|
+
|
|
10
|
+
properties: {
|
|
11
|
+
/**
|
|
12
|
+
* Sets the XHR method to use.
|
|
13
|
+
*
|
|
14
|
+
* @property method
|
|
15
|
+
* @type String
|
|
16
|
+
* @default "GET"
|
|
17
|
+
*/
|
|
18
|
+
method: "GET",
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Sets the path to connect to the server.
|
|
22
|
+
*
|
|
23
|
+
* @property path
|
|
24
|
+
* @type String
|
|
25
|
+
* @default ""
|
|
26
|
+
*/
|
|
27
|
+
path: "",
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Sets the XHR response type.
|
|
31
|
+
*
|
|
32
|
+
* @property responseType
|
|
33
|
+
* @type String
|
|
34
|
+
* @default "text"
|
|
35
|
+
*/
|
|
36
|
+
responseType: "text",
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Whether cookies should be retained on cross-domain calls.
|
|
40
|
+
*
|
|
41
|
+
* @property withCredentials
|
|
42
|
+
* @type boolean
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
withCredentials: false
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* This component provides component-based XHR communication with a server.
|
|
50
|
+
*
|
|
51
|
+
* @memberof platypus.components
|
|
52
|
+
* @uses platypus.Component
|
|
53
|
+
* @constructs
|
|
54
|
+
* @param {*} definition
|
|
55
|
+
* @listens platypus.Entity#request
|
|
56
|
+
* @fires platypus.Entity#response
|
|
57
|
+
*/
|
|
58
|
+
initialize: function (definition) {
|
|
59
|
+
this.setProperties(definition);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
events: {// These are messages that this component listens for
|
|
63
|
+
/**
|
|
64
|
+
* On receiving this message, this component makes a request from the server using the provided information. Note that properties set here will reset the properties set by this component's JSON definition.
|
|
65
|
+
*
|
|
66
|
+
* @event platypus.Entity#request
|
|
67
|
+
* @property {Object} message
|
|
68
|
+
* @property {String} message.method XHR method to use: must be "GET" or "POST".
|
|
69
|
+
* @property {String} message.path The path to the server resource.
|
|
70
|
+
* @property {String} [message.responseType="text"] Response type expected.
|
|
71
|
+
* @property {Object} [message.data] An object of string key/value pairs to be transmitted to the server.
|
|
72
|
+
* @property {Function} message.onload A function that should be run on receiving a response from the server. This defaults to triggering a "response" message containing the responseText value.
|
|
73
|
+
*/
|
|
74
|
+
"request": function (resp) {
|
|
75
|
+
this.setProperties(resp);
|
|
76
|
+
|
|
77
|
+
if (this.method === "GET") {
|
|
78
|
+
this.get();
|
|
79
|
+
} else if (this.method === "POST") {
|
|
80
|
+
this.post();
|
|
81
|
+
} else {
|
|
82
|
+
throw "Method must be GET or POST";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
methods: {// These are methods that are called on the component
|
|
88
|
+
setProperties: function (props = {}) {
|
|
89
|
+
this.method = props.method ?? this.method ?? "GET";
|
|
90
|
+
this.path = props.path ?? this.path ?? null;
|
|
91
|
+
this.responseType = props.responseType ?? this.responseType ?? "text";
|
|
92
|
+
this.withCredentials = props.withCredentials ?? this.withCredentials ?? false;
|
|
93
|
+
this.data = props.data ? (new URLSearchParams(props.data)).toString() : '';
|
|
94
|
+
this.onload = props.onload ?? this.onload ?? (() => {
|
|
95
|
+
if (this.status === 200) {
|
|
96
|
+
/**
|
|
97
|
+
* This message is triggered on receiving a response from the server (if "onload" is not set by the original "request" message).
|
|
98
|
+
*
|
|
99
|
+
* @event platypus.Entity#response
|
|
100
|
+
* @param message {String} The message contains the responseText returned by the server.
|
|
101
|
+
*/
|
|
102
|
+
this.owner.triggerEvent('response', this.responseText);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
get: function () {
|
|
107
|
+
const
|
|
108
|
+
xhr = new XMLHttpRequest(),
|
|
109
|
+
path = this.data ? `${this.path}?${this.data}` : this.path;
|
|
110
|
+
|
|
111
|
+
xhr.open(this.method, path, true);
|
|
112
|
+
xhr.withCredentials = this.withCredentials;
|
|
113
|
+
xhr.responseType = this.responseType;
|
|
114
|
+
xhr.onload = this.onload;
|
|
115
|
+
xhr.send();
|
|
116
|
+
},
|
|
117
|
+
post: function () {
|
|
118
|
+
const
|
|
119
|
+
xhr = new XMLHttpRequest();
|
|
120
|
+
|
|
121
|
+
xhr.open(this.method, this.path, true);
|
|
122
|
+
xhr.withCredentials = this.withCredentials;
|
|
123
|
+
xhr.responseType = this.responseType;
|
|
124
|
+
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
125
|
+
xhr.onload = this.onload;
|
|
126
|
+
xhr.send(this.data);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @namespace platypus.components
|
|
3
|
+
* @memberof platypus
|
|
4
|
+
*/
|
|
5
|
+
export {default as Interactive} from "./Interactive.js";
|
|
6
|
+
export {default as AIChaser} from "./AIChaser.js";
|
|
7
|
+
export {default as AIPacer} from "./AIPacer.js";
|
|
8
|
+
export {default as AudioMusic} from "./AudioMusic.js";
|
|
9
|
+
export {default as AudioSFX} from "./AudioSFX.js";
|
|
10
|
+
export {default as AudioVO} from "./AudioVO.js";
|
|
11
|
+
export {default as Camera} from "./HandlerCamera.js";
|
|
12
|
+
export {default as HandlerCamera} from "./HandlerCamera.js";
|
|
13
|
+
export {default as EntityCamera} from "./EntityCamera.js";
|
|
14
|
+
export {default as CollisionBasic} from "./CollisionBasic.js";
|
|
15
|
+
export {default as CollisionFilter} from "./CollisionFilter.js";
|
|
16
|
+
export {default as CollisionGroup} from "./CollisionGroup.js";
|
|
17
|
+
export {default as CollisionTiles} from "./CollisionTiles.js";
|
|
18
|
+
export {default as ComponentSwitcher} from "./ComponentSwitcher.js";
|
|
19
|
+
export {default as ControllerInput} from "./ControllerInput.js";
|
|
20
|
+
export {default as Counter} from "./Counter.js";
|
|
21
|
+
export {default as EntityContainer} from "./EntityContainer.js";
|
|
22
|
+
export {default as EntityController} from "./EntityController.js";
|
|
23
|
+
export {default as HandlerCollision} from "./HandlerCollision.js";
|
|
24
|
+
export {default as HandlerController} from "./HandlerController.js";
|
|
25
|
+
export {default as HandlerLogic} from "./HandlerLogic.js";
|
|
26
|
+
export {default as HandlerRender} from "./HandlerRender.js";
|
|
27
|
+
export {default as LevelBuilder} from "./LevelBuilder.js";
|
|
28
|
+
export {default as LogicAngularMovement} from "./LogicAngularMovement.js";
|
|
29
|
+
export {default as LogicAttachment} from "./LogicAttachment.js";
|
|
30
|
+
export {default as LogicButton} from "./LogicButton.js";
|
|
31
|
+
export {default as LogicCarrier} from "./LogicCarrier.js";
|
|
32
|
+
export {default as LogicDestroyMe} from "./LogicDestroyMe.js";
|
|
33
|
+
export {default as LogicDirectionalMovement} from "./LogicDirectionalMovement.js";
|
|
34
|
+
export {default as LogicDragDrop} from "./LogicDragDrop.js";
|
|
35
|
+
export {default as LogicImpactLaunch} from "./LogicImpactLaunch.js";
|
|
36
|
+
export {default as LogicPacingPlatform} from "./LogicPacingPlatform.js";
|
|
37
|
+
export {default as LogicPortable} from "./LogicPortable.js";
|
|
38
|
+
export {default as LogicPortal} from "./LogicPortal.js";
|
|
39
|
+
export {default as LogicPushable} from "./LogicPushable.js";
|
|
40
|
+
export {default as LogicRebounder} from "./LogicRebounder.js";
|
|
41
|
+
export {default as LogicRegionSpawner} from "./LogicRegionSpawner.js";
|
|
42
|
+
export {default as LogicRotationalMovement} from "./LogicRotationalMovement.js";
|
|
43
|
+
export {default as LogicSpawner} from "./LogicSpawner.js";
|
|
44
|
+
export {default as LogicStateMachine} from "./LogicStateMachine.js";
|
|
45
|
+
export {default as LogicSwitch} from "./LogicSwitch.js";
|
|
46
|
+
export {default as LogicTeleportee} from "./LogicTeleportee.js";
|
|
47
|
+
export {default as LogicTeleporter} from "./LogicTeleporter.js";
|
|
48
|
+
export {default as LogicTimer} from "./LogicTimer.js";
|
|
49
|
+
export {default as LogicWindUpRacer} from "./LogicWindUpRacer.js";
|
|
50
|
+
export {default as Motion} from "./Motion.js";
|
|
51
|
+
export {default as Mover} from "./Mover.js";
|
|
52
|
+
export {default as Node} from "./Node.js";
|
|
53
|
+
export {default as NodeMap} from "./NodeMap.js";
|
|
54
|
+
export {default as NodeResident} from "./NodeResident.js";
|
|
55
|
+
export {default as Orientation} from "./Orientation.js";
|
|
56
|
+
export {default as RandomEvents} from "./RandomEvents.js";
|
|
57
|
+
export {default as RelativePosition} from "./RelativePosition.js";
|
|
58
|
+
export {default as RelayFamily} from "./RelayFamily.js";
|
|
59
|
+
export {default as RelayGame} from "./RelayGame.js";
|
|
60
|
+
export {default as RelayLinker} from "./RelayLinker.js";
|
|
61
|
+
export {default as RelayParent} from "./RelayParent.js";
|
|
62
|
+
export {default as RelaySelf} from "./RelaySelf.js";
|
|
63
|
+
export {default as Render} from "./Render.js";
|
|
64
|
+
export {default as RenderAnimator} from "./RenderAnimator.js";
|
|
65
|
+
export {default as RenderContainer} from "./RenderContainer.js";
|
|
66
|
+
export {default as RenderDebug} from "./RenderDebug.js";
|
|
67
|
+
export {default as RenderDestroyMe} from "./RenderDestroyMe.js";
|
|
68
|
+
export {default as RenderProgress} from "./RenderProgress.js";
|
|
69
|
+
export {default as RenderSpine} from "./RenderSpine.js";
|
|
70
|
+
export {default as RenderSprite} from "./RenderSprite.js";
|
|
71
|
+
export {default as RenderText} from "./RenderText.js";
|
|
72
|
+
export {default as RenderTiles} from "./RenderTiles.js";
|
|
73
|
+
export {default as SceneChanger} from "./SceneChanger.js";
|
|
74
|
+
export {default as TiledLoader} from "./TiledLoader.js";
|
|
75
|
+
export {default as Timeline} from "./Timeline.js";
|
|
76
|
+
export {default as Tutorial} from "./Tutorial.js";
|
|
77
|
+
export {default as Tween} from "./Tween.js";
|
|
78
|
+
export {default as VoiceOver} from "./VoiceOver.js";
|
|
79
|
+
export {default as XHR} from "./XHR.js";
|
package/src/factory.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component factory takes in component definitions and creates component classes that can be used to create components by entities. It adds properties and methods that are common to all components so that component definitions can focus on unique properties and methods.
|
|
3
|
+
*
|
|
4
|
+
* To create an extended component class, use the following syntax:
|
|
5
|
+
*
|
|
6
|
+
* platypus.createComponentClass(componentDefinition);
|
|
7
|
+
*
|
|
8
|
+
* * `componentDefinition` is list of key/value pairs that describe the component's behavior.
|
|
9
|
+
*
|
|
10
|
+
* See ComponentExample.js for an example componentDefinition that can be sent into this component class factory.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
/* global platypus */
|
|
14
|
+
import {arrayCache, greenSlice} from './utils/array.js';
|
|
15
|
+
import Component from './Component.js';
|
|
16
|
+
|
|
17
|
+
const
|
|
18
|
+
getId = (type) => {
|
|
19
|
+
if (typeof ids[type] === 'number') {
|
|
20
|
+
ids[type] += 1;
|
|
21
|
+
} else {
|
|
22
|
+
ids[type] = 0;
|
|
23
|
+
}
|
|
24
|
+
return `${type}-${ids[type]}`;
|
|
25
|
+
};
|
|
26
|
+
let ids = {};
|
|
27
|
+
|
|
28
|
+
export default function (componentDefinition = {}) {
|
|
29
|
+
const
|
|
30
|
+
{events, getAssetList, id, initialize, methods, properties, publicMethods, publicProperties} = componentDefinition,
|
|
31
|
+
|
|
32
|
+
// Not sure if this is future-proof, but putting in object to create dynamic name.
|
|
33
|
+
NewComponent = ({[id]: class extends Component {
|
|
34
|
+
constructor (owner, definition = {}, callback) {
|
|
35
|
+
const
|
|
36
|
+
{aliases, id: componentId = getId(id)} = definition;
|
|
37
|
+
|
|
38
|
+
super(id, owner, componentId);
|
|
39
|
+
|
|
40
|
+
// Set up properties, prioritizing component settings, entity settings, and finally defaults.
|
|
41
|
+
if (properties) {
|
|
42
|
+
const
|
|
43
|
+
keys = Object.keys(properties),
|
|
44
|
+
{length} = keys;
|
|
45
|
+
|
|
46
|
+
for (let i = 0; i < length; i++) {
|
|
47
|
+
const
|
|
48
|
+
key = keys[i];
|
|
49
|
+
|
|
50
|
+
this[key] = definition[key] ?? owner[key] ?? properties[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// These component properties are equivalent with `entity.property`
|
|
55
|
+
if (publicProperties) {
|
|
56
|
+
const
|
|
57
|
+
keys = Object.keys(publicProperties),
|
|
58
|
+
{length} = keys;
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < length; i++) {
|
|
61
|
+
const
|
|
62
|
+
key = keys[i];
|
|
63
|
+
|
|
64
|
+
Object.defineProperty(this, key, {
|
|
65
|
+
get: function () {
|
|
66
|
+
return owner[key];
|
|
67
|
+
},
|
|
68
|
+
set: function (value) {
|
|
69
|
+
owner[key] = value;
|
|
70
|
+
},
|
|
71
|
+
enumerable: true
|
|
72
|
+
});
|
|
73
|
+
this[key] = definition[key] ?? owner[key] ?? publicProperties[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (events) {
|
|
78
|
+
const
|
|
79
|
+
keys = Object.keys(events),
|
|
80
|
+
{length} = keys;
|
|
81
|
+
|
|
82
|
+
for (let i = 0; i < length; i++) {
|
|
83
|
+
const
|
|
84
|
+
key = keys[i];
|
|
85
|
+
|
|
86
|
+
this.addEventListener(key, events[key]);
|
|
87
|
+
if (aliases) {
|
|
88
|
+
const
|
|
89
|
+
aliasKeys = Object.keys(aliases),
|
|
90
|
+
{length} = aliasKeys;
|
|
91
|
+
|
|
92
|
+
for (let j = 0; j < length; j++) {
|
|
93
|
+
const
|
|
94
|
+
alias = aliasKeys[j];
|
|
95
|
+
|
|
96
|
+
if (aliases[alias] === key) {
|
|
97
|
+
this.addEventListener(alias, events[key]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (publicMethods) {
|
|
105
|
+
const
|
|
106
|
+
keys = Object.keys(publicMethods),
|
|
107
|
+
{length} = keys;
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < length; i++) {
|
|
110
|
+
const
|
|
111
|
+
key = keys[i];
|
|
112
|
+
let name = key;
|
|
113
|
+
|
|
114
|
+
if (aliases) {
|
|
115
|
+
const
|
|
116
|
+
aliasKeys = Object.keys(aliases),
|
|
117
|
+
{length} = aliasKeys;
|
|
118
|
+
|
|
119
|
+
for (let j = 0; j < length; j++) {
|
|
120
|
+
const
|
|
121
|
+
alias = aliasKeys[j];
|
|
122
|
+
|
|
123
|
+
if (aliases[alias] === key) {
|
|
124
|
+
name = alias;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this.addMethod(name, publicMethods[key]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!this.initialize(definition, callback) && callback) { // whether the callback will be used; if not, we run immediately.
|
|
133
|
+
callback();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}})[id],
|
|
137
|
+
proto = NewComponent.prototype;
|
|
138
|
+
|
|
139
|
+
if (initialize) {
|
|
140
|
+
proto.initialize = initialize;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns a JSON structure describing this componet. This can be overridden by a "toJSON" method in the component definition. This is by design.
|
|
145
|
+
*
|
|
146
|
+
* @method toJSON
|
|
147
|
+
* @return {Object}
|
|
148
|
+
*/
|
|
149
|
+
proto.toJSON = (function () {
|
|
150
|
+
const
|
|
151
|
+
valid = function (value, depthArray) {
|
|
152
|
+
const
|
|
153
|
+
type = typeof value;
|
|
154
|
+
let depth = null,
|
|
155
|
+
root = false,
|
|
156
|
+
invalid = false;
|
|
157
|
+
|
|
158
|
+
if (!validating) { // prevents endless validation during recursion.
|
|
159
|
+
validating = true;
|
|
160
|
+
root = true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (type === 'function') {
|
|
164
|
+
invalid = true;
|
|
165
|
+
} else if ((type === 'object') && (value !== null)) {
|
|
166
|
+
if (value.toJSON) { // We know it's valid but we run this for the depth check to make sure that there is no recursion.
|
|
167
|
+
depth = depthArray ? greenSlice(depthArray) : arrayCache.setUp();
|
|
168
|
+
depth.push(value);
|
|
169
|
+
if (!valid(value.toJSON(), depth)) {
|
|
170
|
+
invalid = true;
|
|
171
|
+
}
|
|
172
|
+
} else if (Array.isArray(value)) {
|
|
173
|
+
let i = value.length;
|
|
174
|
+
|
|
175
|
+
while (i--) {
|
|
176
|
+
const
|
|
177
|
+
propValue = value[i];
|
|
178
|
+
|
|
179
|
+
if (depthArray && depthArray.indexOf(propValue) >= 0) {
|
|
180
|
+
invalid = true;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
depth = depthArray ? greenSlice(depthArray) : arrayCache.setUp();
|
|
184
|
+
depth.push(propValue);
|
|
185
|
+
if (!valid(propValue, depth)) {
|
|
186
|
+
invalid = true;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
const
|
|
192
|
+
keys = Object.keys(value),
|
|
193
|
+
{length} = keys;
|
|
194
|
+
|
|
195
|
+
for (let i = 0; i < length; i++) {
|
|
196
|
+
const
|
|
197
|
+
propValue = value[keys[i]];
|
|
198
|
+
|
|
199
|
+
if (depthArray && depthArray.indexOf(propValue) >= 0) {
|
|
200
|
+
invalid = true;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
depth = depthArray ? greenSlice(depthArray) : arrayCache.setUp();
|
|
204
|
+
depth.push(propValue);
|
|
205
|
+
if (!valid(propValue, depth)) {
|
|
206
|
+
invalid = true;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (depthArray) {
|
|
214
|
+
arrayCache.recycle(depthArray);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (root) {
|
|
218
|
+
validating = false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return !invalid;
|
|
222
|
+
};
|
|
223
|
+
let validating = false;
|
|
224
|
+
|
|
225
|
+
return function (propertiesDefinition, debug) {
|
|
226
|
+
const
|
|
227
|
+
component = {
|
|
228
|
+
type: this.type
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
if (properties) {
|
|
232
|
+
const
|
|
233
|
+
keys = Object.keys(properties),
|
|
234
|
+
{length} = keys;
|
|
235
|
+
|
|
236
|
+
for (let i = 0; i < length; i++) {
|
|
237
|
+
const
|
|
238
|
+
key = keys[i];
|
|
239
|
+
|
|
240
|
+
if (properties[key] !== this[key]) {
|
|
241
|
+
if (debug && !validating && !valid(this[key])) {
|
|
242
|
+
platypus.debug.warn('Component "' + this.type + '" includes a non-JSON property value for "' + key + '" (type "' + (typeof this[key]) + '"). You may want to create a custom `toJSON` method for this component.', this[key]);
|
|
243
|
+
}
|
|
244
|
+
component[key] = this[key];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (publicProperties) {
|
|
250
|
+
const
|
|
251
|
+
keys = Object.keys(publicProperties),
|
|
252
|
+
{length} = keys;
|
|
253
|
+
|
|
254
|
+
for (let i = 0; i < length; i++) {
|
|
255
|
+
const
|
|
256
|
+
key = keys[i];
|
|
257
|
+
|
|
258
|
+
if ((publicProperties[key] !== this.owner[key]) && (typeof propertiesDefinition[key] === 'undefined')) {
|
|
259
|
+
if (debug && !validating && !valid(this.owner[key])) {
|
|
260
|
+
platypus.debug.warn('Component "' + this.type + '" includes a non-JSON public property value for "' + key + '" (type "' + (typeof this.owner[key]) + '"). You may want to create a custom `toJSON` method for this component.', this.owner[key]);
|
|
261
|
+
}
|
|
262
|
+
propertiesDefinition[key] = this.owner[key];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return component;
|
|
268
|
+
};
|
|
269
|
+
}());
|
|
270
|
+
|
|
271
|
+
if (methods) {
|
|
272
|
+
const
|
|
273
|
+
keys = Object.keys(methods),
|
|
274
|
+
{length} = keys;
|
|
275
|
+
|
|
276
|
+
for (let i = 0; i < length; i++) {
|
|
277
|
+
const
|
|
278
|
+
key = keys[i];
|
|
279
|
+
|
|
280
|
+
if (key === 'destroy') {
|
|
281
|
+
proto._destroy = methods[key];
|
|
282
|
+
} else {
|
|
283
|
+
proto[key] = methods[key];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (publicMethods) {
|
|
288
|
+
const
|
|
289
|
+
keys = Object.keys(publicMethods),
|
|
290
|
+
{length} = keys;
|
|
291
|
+
|
|
292
|
+
for (let i = 0; i < length; i++) {
|
|
293
|
+
const
|
|
294
|
+
key = keys[i];
|
|
295
|
+
|
|
296
|
+
proto[key] = publicMethods[key];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (getAssetList) {
|
|
301
|
+
NewComponent.getAssetList = getAssetList;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return NewComponent;
|
|
305
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* eslint-disable sort-imports */
|
|
2
|
+
/**
|
|
3
|
+
* @namespace window
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @namespace platypus
|
|
7
|
+
*/
|
|
8
|
+
/* global global, navigator, window */
|
|
9
|
+
|
|
10
|
+
import AssetManager from './AssetManager.js';
|
|
11
|
+
import {Debugger} from 'springroll';
|
|
12
|
+
import Game from './Game.js';
|
|
13
|
+
import createComponentClass from './factory.js';
|
|
14
|
+
import pkg from '../package.json';
|
|
15
|
+
import * as components from './components/index.js';
|
|
16
|
+
|
|
17
|
+
export * from './utils/array.js';
|
|
18
|
+
export * from './utils/string.js';
|
|
19
|
+
export {default as recycle} from 'recycle';
|
|
20
|
+
|
|
21
|
+
// Classes
|
|
22
|
+
export {default as AABB} from './AABB.js';
|
|
23
|
+
export {default as ActionState} from './ActionState.js';
|
|
24
|
+
export {Application as Application} from 'springroll';
|
|
25
|
+
export {default as CollisionData} from './CollisionData.js';
|
|
26
|
+
export {default as CollisionDataContainer} from './CollisionDataContainer.js';
|
|
27
|
+
export {default as CollisionShape} from './CollisionShape.js';
|
|
28
|
+
export {default as Component} from './Component.js';
|
|
29
|
+
export {default as Data} from './Data.js';
|
|
30
|
+
export {default as DataMap} from './DataMap.js';
|
|
31
|
+
export {default as Entity} from './Entity.js';
|
|
32
|
+
export {default as Game} from './Game.js';
|
|
33
|
+
export {default as Messenger} from './Messenger.js';
|
|
34
|
+
export {default as PIXIAnimation} from './PIXIAnimation.js';
|
|
35
|
+
export {default as RandomSet} from './RandomSet.js';
|
|
36
|
+
export {default as StateMap} from './StateMap.js';
|
|
37
|
+
export {default as Vector} from './Vector.js';
|
|
38
|
+
export * from './shapes/index.js';
|
|
39
|
+
|
|
40
|
+
// Component creator
|
|
41
|
+
export {default as createComponentClass} from './factory.js';
|
|
42
|
+
|
|
43
|
+
const
|
|
44
|
+
platypus = global.platypus = {
|
|
45
|
+
createComponentClass,
|
|
46
|
+
components
|
|
47
|
+
},
|
|
48
|
+
uagent = navigator.userAgent.toLowerCase(),
|
|
49
|
+
isEdge = (uagent.search('edge') > -1),
|
|
50
|
+
isIPod = (uagent.search('ipod') > -1),
|
|
51
|
+
isIPhone = (uagent.search('iphone') > -1),
|
|
52
|
+
isIPad = (uagent.search('ipad') > -1) || (uagent.search('mac') > -1 && navigator.maxTouchPoints > 2 && !isIPhone),
|
|
53
|
+
isAndroid = (uagent.search('android') > -1),
|
|
54
|
+
isSilk = (uagent.search('silk') > -1),
|
|
55
|
+
isIOS = isIPod || isIPhone || isIPad,
|
|
56
|
+
isMobile = isIOS || isAndroid || isSilk,
|
|
57
|
+
logToDiv = isMobile ? (() => {
|
|
58
|
+
const
|
|
59
|
+
logDiv = document.createElement('ul'),
|
|
60
|
+
toggleLogDiv = document.createElement('button');
|
|
61
|
+
let firstTime = true;
|
|
62
|
+
|
|
63
|
+
logDiv.style.display = 'none';
|
|
64
|
+
logDiv.id = "platypus-logging";
|
|
65
|
+
logDiv.classList.add('platypus-debugging');
|
|
66
|
+
document.body.appendChild(logDiv);
|
|
67
|
+
|
|
68
|
+
toggleLogDiv.style.display = 'none';
|
|
69
|
+
toggleLogDiv.id = 'toggle-platypus-debugging';
|
|
70
|
+
toggleLogDiv.innerText = 'log';
|
|
71
|
+
toggleLogDiv.addEventListener('click', () => {
|
|
72
|
+
if (logDiv.style.display === 'none') {
|
|
73
|
+
logDiv.style.display = 'block';
|
|
74
|
+
toggleLogDiv.innerText = 'X';
|
|
75
|
+
} else {
|
|
76
|
+
logDiv.style.display = 'none';
|
|
77
|
+
toggleLogDiv.innerText = 'log';
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
document.body.appendChild(toggleLogDiv);
|
|
81
|
+
|
|
82
|
+
return (method, ...args) => {
|
|
83
|
+
const
|
|
84
|
+
newLog = document.createElement('li');
|
|
85
|
+
|
|
86
|
+
newLog.classList.add(method);
|
|
87
|
+
args.forEach((arg) => {
|
|
88
|
+
const
|
|
89
|
+
newArg = document.createElement('span');
|
|
90
|
+
|
|
91
|
+
newArg.innerText = arg;
|
|
92
|
+
newLog.appendChild(newArg);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
logDiv.appendChild(newLog);
|
|
96
|
+
|
|
97
|
+
if (firstTime) {
|
|
98
|
+
firstTime = false;
|
|
99
|
+
toggleLogDiv.style.display = 'block';
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
})() : () => {},
|
|
103
|
+
debugWrapper = function (method, ...args) {
|
|
104
|
+
if (platypus.game?.settings?.debug) {
|
|
105
|
+
Debugger.log(method, ...args);
|
|
106
|
+
logToDiv(method, ...args);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* This is an object of boolean key/value pairs describing the current browser's properties.
|
|
112
|
+
* @property supports
|
|
113
|
+
* @type Object
|
|
114
|
+
**/
|
|
115
|
+
platypus.supports = {
|
|
116
|
+
touch: (window.ontouchstart !== 'undefined'),
|
|
117
|
+
edge: isEdge,
|
|
118
|
+
iPod: isIPod,
|
|
119
|
+
iPhone: isIPhone,
|
|
120
|
+
iPad: isIPad,
|
|
121
|
+
safari: (uagent.search('safari') > -1) && !isEdge,
|
|
122
|
+
ie: (uagent.search('msie') > -1) || (uagent.search('trident') > -1),
|
|
123
|
+
firefox: (uagent.search('firefox') > -1),
|
|
124
|
+
android: isAndroid,
|
|
125
|
+
chrome: (uagent.search('chrome') > -1) && !isEdge,
|
|
126
|
+
silk: isSilk,
|
|
127
|
+
iOS: isIOS,
|
|
128
|
+
mobile: isMobile,
|
|
129
|
+
desktop: !isMobile
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* This method defines platypus.debug and uses springroll.Debug if available. If springroll.Debug is not loaded, platypus.debug provides inactive stubs for console methods.
|
|
134
|
+
*
|
|
135
|
+
* @property debug
|
|
136
|
+
* @type Object
|
|
137
|
+
*/
|
|
138
|
+
platypus.debug = {
|
|
139
|
+
general: debugWrapper.bind(null, 'log'),
|
|
140
|
+
log: debugWrapper.bind(null, 'log'),
|
|
141
|
+
warn: debugWrapper.bind(null, 'warn'),
|
|
142
|
+
debug: debugWrapper.bind(null, 'debug'),
|
|
143
|
+
error: debugWrapper.bind(null, 'error')
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
platypus.assetCache = new AssetManager();
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The version string for this release.
|
|
150
|
+
* @property version
|
|
151
|
+
* @type String
|
|
152
|
+
* @static
|
|
153
|
+
**/
|
|
154
|
+
platypus.version = pkg.version;
|
|
155
|
+
|
|
156
|
+
platypus.Game = Game;
|
|
157
|
+
|
|
158
|
+
export {components};
|
|
159
|
+
export default platypus;
|