@makefully/platypus 4.1.5 → 4.1.6
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 +10 -0
- package/README.md +3 -3
- package/lib/platypus.js +1 -1
- package/package.json +6 -5
- 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 +833 -0
- package/src/components/RenderSprite.js +527 -0
- package/src/components/RenderText.js +147 -0
- package/src/components/RenderTiles.js +1391 -0
- package/src/components/SceneChanger.js +128 -0
- package/src/components/TiledLoader.js +1451 -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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This component listens for certain messages, picks a message from a related list of events, and triggers it. This is useful for adding random behaviors to an entity, such as having an entity say one thing from a list of audio clips. For example, defining this component on an Entity may look like this:
|
|
3
|
+
*
|
|
4
|
+
* {
|
|
5
|
+
* "type": "RandomEvents",
|
|
6
|
+
* "trueRandom": "true",
|
|
7
|
+
* //If true, events will play completely randomly, otherwise all events in the set will fire before repeating.
|
|
8
|
+
*
|
|
9
|
+
* "events": {
|
|
10
|
+
* // This is a key/value list of events to listen for, with each event mapping to an array of events to pick from.
|
|
11
|
+
*
|
|
12
|
+
* "make-sound": ["scream", "whisper", "talk"]
|
|
13
|
+
* //on the component receiving the "make-sound" message, it will trigger one of the three possible messages listed here.
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @memberof platypus.components
|
|
18
|
+
* @class RandomEvents
|
|
19
|
+
* @uses platypus.Component
|
|
20
|
+
*/
|
|
21
|
+
import RandomSet from '../RandomSet.js';
|
|
22
|
+
import createComponentClass from '../factory.js';
|
|
23
|
+
|
|
24
|
+
const
|
|
25
|
+
createTrigger = function (eventSet) {
|
|
26
|
+
return function (value, debug) {
|
|
27
|
+
this.owner.trigger(eventSet.get(), value, debug);
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
createTrueRandomTrigger = function (eventList) {
|
|
31
|
+
return function (value, debug) {
|
|
32
|
+
this.owner.trigger(eventList[Math.floor(Math.random() * eventList.length)], value, debug);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default createComponentClass(/** @lends platypus.components.RandomEvents.prototype */{
|
|
37
|
+
id: 'RandomEvents',
|
|
38
|
+
|
|
39
|
+
properties: {
|
|
40
|
+
events: null,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether to cycle through all options (default) or just trigger any option.
|
|
44
|
+
*
|
|
45
|
+
* @property trueRandom
|
|
46
|
+
* @type boolean
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
trueRandom: false
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
initialize: function () {
|
|
53
|
+
const
|
|
54
|
+
events = this.events;
|
|
55
|
+
|
|
56
|
+
if (events) {
|
|
57
|
+
const
|
|
58
|
+
keys = Object.keys(events),
|
|
59
|
+
{length} = keys;
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < length; i++) {
|
|
62
|
+
const
|
|
63
|
+
key = keys[i];
|
|
64
|
+
|
|
65
|
+
if (this.trueRandom) {
|
|
66
|
+
this.addEventListener(key, createTrueRandomTrigger(events[key]));
|
|
67
|
+
} else {
|
|
68
|
+
this.addEventListener(key, createTrigger(RandomSet.setUp(events[key])));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import AABB from '../AABB.js';
|
|
2
|
+
import createComponentClass from '../factory.js';
|
|
3
|
+
|
|
4
|
+
export default (function () {
|
|
5
|
+
return createComponentClass(/** @lends platypus.components.RelativePosition.prototype */{
|
|
6
|
+
|
|
7
|
+
id: 'RelativePosition',
|
|
8
|
+
|
|
9
|
+
properties: {
|
|
10
|
+
/**
|
|
11
|
+
* This optional array sets varying properties depending on the aspect ratio of the camera. This is useful if the camera aspect ratio varies greatly and entities must be repositioned accordingly.
|
|
12
|
+
*
|
|
13
|
+
* In this example, the entity maintains a particular horizontal location until the camera viewport becomes narrower than 2:1, at which point it maintains a particular `left` value:
|
|
14
|
+
*
|
|
15
|
+
* "cameraSizes": [{
|
|
16
|
+
* "minRatio": 2, // This block applies for wide aspect ratios until 2:1 is reached.
|
|
17
|
+
* "x": -1226
|
|
18
|
+
* }, {
|
|
19
|
+
* "minRatio": 0, // This block applies for everything else.
|
|
20
|
+
* "left": 130
|
|
21
|
+
* }]
|
|
22
|
+
*
|
|
23
|
+
* @property cameraSizes
|
|
24
|
+
* @type Array
|
|
25
|
+
* @default null
|
|
26
|
+
*/
|
|
27
|
+
cameraSizes: null
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
publicProperties: {
|
|
31
|
+
/**
|
|
32
|
+
* This sets the distance in world units from the bottom of the camera's world viewport. If set, it will override the entity's y coordinate. This property is accessible on the entity as `entity.bottom`.
|
|
33
|
+
*
|
|
34
|
+
* @property bottom
|
|
35
|
+
* @type Number
|
|
36
|
+
* @default null
|
|
37
|
+
*/
|
|
38
|
+
bottom: null,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This sets the distance in world units from the left of the camera's world viewport. If set, it will override the entity's x coordinate. This property is accessible on the entity as `entity.left`.
|
|
42
|
+
*
|
|
43
|
+
* @property left
|
|
44
|
+
* @type Number
|
|
45
|
+
* @default null
|
|
46
|
+
*/
|
|
47
|
+
left: null,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* This sets the distance in world units from the right of the camera's world viewport. If set, it will override the entity's x coordinate. This property is accessible on the entity as `entity.right`.
|
|
51
|
+
*
|
|
52
|
+
* @property right
|
|
53
|
+
* @type Number
|
|
54
|
+
* @default null
|
|
55
|
+
*/
|
|
56
|
+
right: null,
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* This sets the distance in world units from the top of the camera's world viewport. If set, it will override the entity's y coordinate. This property is accessible on the entity as `entity.top`.
|
|
60
|
+
*
|
|
61
|
+
* @property top
|
|
62
|
+
* @type Number
|
|
63
|
+
* @default null
|
|
64
|
+
*/
|
|
65
|
+
top: null,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* This sets the scale in X of the entity.
|
|
69
|
+
*
|
|
70
|
+
* @property scaleX
|
|
71
|
+
* @type Number
|
|
72
|
+
* @default 1
|
|
73
|
+
*/
|
|
74
|
+
scaleX: 1,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* This sets the scale in Y of the entity.
|
|
78
|
+
*
|
|
79
|
+
* @property scaleY
|
|
80
|
+
* @type Number
|
|
81
|
+
* @default 1
|
|
82
|
+
*/
|
|
83
|
+
scaleY: 1,
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* This sets the `x` coordinate for the entity. It is overridden by `left` and `right` properties if supplied.
|
|
87
|
+
*
|
|
88
|
+
* @property x
|
|
89
|
+
* @type Number
|
|
90
|
+
* @default 0
|
|
91
|
+
*/
|
|
92
|
+
x: 0,
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* This sets the `y` coordinate for the entity. It is overridden by `top` and `bottom` properties if supplied.
|
|
96
|
+
*
|
|
97
|
+
* @property y
|
|
98
|
+
* @type Number
|
|
99
|
+
* @default 0
|
|
100
|
+
*/
|
|
101
|
+
y: 0
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* This component positions an entity relative to the camera viewport, according to `left`, `top`, `right`, and `left` properties.
|
|
106
|
+
*
|
|
107
|
+
* @memberof platypus.components
|
|
108
|
+
* @uses platypus.Component
|
|
109
|
+
* @constructs
|
|
110
|
+
* @listens platypus.Entity#camera-update
|
|
111
|
+
* @listens platypus.Entity#handle-logic
|
|
112
|
+
*/
|
|
113
|
+
initialize: function (/*definition, callback*/) {
|
|
114
|
+
this.aabb = AABB.setUp();
|
|
115
|
+
this.lastBottom = null;
|
|
116
|
+
this.lastLeft = null;
|
|
117
|
+
this.lastRight = null;
|
|
118
|
+
this.lastTop = null;
|
|
119
|
+
this.cameraSizesIndex = -1;
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
events: {
|
|
123
|
+
"handle-logic": function () {
|
|
124
|
+
const
|
|
125
|
+
{bottom, left, right, top} = this;
|
|
126
|
+
|
|
127
|
+
if ((this.lastBottom !== bottom) || (this.lastLeft !== left) || (this.lastRight !== right) || (this.lastTop !== top)) {
|
|
128
|
+
this.updatePosition(this.aabb);
|
|
129
|
+
this.lastBottom = bottom;
|
|
130
|
+
this.lastLeft = left;
|
|
131
|
+
this.lastRight = right;
|
|
132
|
+
this.lastTop = top;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
"camera-update": function (camera) {
|
|
137
|
+
this.aabb.set(camera.viewport);
|
|
138
|
+
if (this.cameraSizes) {
|
|
139
|
+
this.checkCamera(this.aabb);
|
|
140
|
+
}
|
|
141
|
+
this.updatePosition(this.aabb);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
methods: {// These are internal methods that are invoked by this component.
|
|
146
|
+
checkCamera: function (aabb) {
|
|
147
|
+
const
|
|
148
|
+
arr = this.cameraSizes,
|
|
149
|
+
ratio = aabb.width / aabb.height;
|
|
150
|
+
|
|
151
|
+
for (let i = 0; i < arr.length; i++) {
|
|
152
|
+
if (ratio > arr[i].minRatio) {
|
|
153
|
+
if (i !== this.cameraSizesIndex) {
|
|
154
|
+
this.updateProperties(arr[i]);
|
|
155
|
+
this.cameraSizesIndex = i;
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
updateProperties: function (props) {
|
|
163
|
+
this.right = (typeof props.right === 'number') ? props.right : null;
|
|
164
|
+
this.left = (typeof props.left === 'number') ? props.left : null;
|
|
165
|
+
this.top = (typeof props.top === 'number') ? props.top : null;
|
|
166
|
+
this.bottom = (typeof props.bottom === 'number') ? props.bottom : null;
|
|
167
|
+
if (typeof props.x === 'number') {
|
|
168
|
+
this.x = props.x;
|
|
169
|
+
}
|
|
170
|
+
if (typeof props.y === 'number') {
|
|
171
|
+
this.y = props.y;
|
|
172
|
+
}
|
|
173
|
+
if (typeof props.scaleX === 'number') {
|
|
174
|
+
this.scaleX = props.scaleX;
|
|
175
|
+
}
|
|
176
|
+
if (typeof props.scaleY === 'number') {
|
|
177
|
+
this.scaleY = props.scaleY;
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
updatePosition: function (vp) {
|
|
182
|
+
const
|
|
183
|
+
{bottom, left, owner, right, top} = this;
|
|
184
|
+
|
|
185
|
+
if (typeof left === 'number') {
|
|
186
|
+
owner.x = vp.left + left;
|
|
187
|
+
} else if (typeof right === 'number') {
|
|
188
|
+
owner.x = vp.right - right;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (typeof top === 'number') {
|
|
192
|
+
owner.y = vp.top + top;
|
|
193
|
+
} else if (typeof bottom === 'number') {
|
|
194
|
+
owner.y = vp.bottom - bottom;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
destroy: function () {
|
|
199
|
+
this.aabb.recycle();
|
|
200
|
+
this.aabb = null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}());
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import {arrayCache, greenSlice, greenSplice, union} from '../utils/array.js';
|
|
3
|
+
import createComponentClass from '../factory.js';
|
|
4
|
+
|
|
5
|
+
export default (function () {
|
|
6
|
+
return createComponentClass(/** @lends platypus.components.RelayFamily.prototype */{
|
|
7
|
+
id: 'RelayFamily',
|
|
8
|
+
|
|
9
|
+
properties: {
|
|
10
|
+
/**
|
|
11
|
+
* This is an object of key/value pairs. The keys are events this component is listening for locally, the value is the event that will be broadcast to its linked entities. The value can also be an array of events to be fired on linked entities.
|
|
12
|
+
*
|
|
13
|
+
* "events": {
|
|
14
|
+
* "sleeping": "good-night",
|
|
15
|
+
* "awake": ["alarm", "get-up"]
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @property events
|
|
19
|
+
* @type Object
|
|
20
|
+
* @default null
|
|
21
|
+
*/
|
|
22
|
+
events: null
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This component allows an entity to communicate directly with one or more entities via the message model, by passing local messages directly to entities in the same family as new triggered events. This component is placed on a single entity and all entities created by this entity become part of its "family".
|
|
27
|
+
*
|
|
28
|
+
* @memberof platypus.components
|
|
29
|
+
* @uses platypus.Component
|
|
30
|
+
* @constructs
|
|
31
|
+
* @listens platypus.Entity#entity-created
|
|
32
|
+
* @listens platypus.Entity#link-family
|
|
33
|
+
* @fires platypus.Entity#link-family
|
|
34
|
+
*/
|
|
35
|
+
initialize: function () {
|
|
36
|
+
const
|
|
37
|
+
events = this.events;
|
|
38
|
+
|
|
39
|
+
if (events) {
|
|
40
|
+
const
|
|
41
|
+
keys = Object.keys(events),
|
|
42
|
+
{length} = keys;
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < length; i++) {
|
|
45
|
+
const
|
|
46
|
+
key = keys[i];
|
|
47
|
+
|
|
48
|
+
this.addEventListener(key, this.broadcast.bind(this, null, events[key]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.owner.familyLinks = arrayCache.setUp(this.owner);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
events: {
|
|
56
|
+
"link-family": function (links) {
|
|
57
|
+
const
|
|
58
|
+
oldList = this.owner.familyLinks,
|
|
59
|
+
newList = union(union(arrayCache.setUp(), links), oldList);
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < newList.length; i++) {
|
|
62
|
+
newList[i].familyLinks = newList;
|
|
63
|
+
}
|
|
64
|
+
this.broadcast(links, 'family-members-added', oldList);
|
|
65
|
+
this.broadcast(oldList, 'family-members-added', links);
|
|
66
|
+
arrayCache.recycle(oldList);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
"entity-created": function (entity) {
|
|
70
|
+
/**
|
|
71
|
+
* Called when linking a new member to the family, this event accepts a list of family members from the new member and uses it to link all the family members together.
|
|
72
|
+
*
|
|
73
|
+
* @event platypus.Entity#link-family
|
|
74
|
+
* @param links {Array|Entities} An array of entities.
|
|
75
|
+
*/
|
|
76
|
+
if (!entity.triggerEvent('link-family', this.owner.familyLinks)) {
|
|
77
|
+
entity.addComponent(new platypus.components.RelayFamily(entity, {}));
|
|
78
|
+
entity.triggerEvent('link-family', this.owner.familyLinks);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
methods: {
|
|
84
|
+
broadcast: function (links, ...args) {
|
|
85
|
+
const
|
|
86
|
+
entities = links || this.owner.familyLinks;
|
|
87
|
+
|
|
88
|
+
for (let i = 0; i < entities.length; i++) {
|
|
89
|
+
entities[i].trigger.apply(entities[i], args);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
destroy: function () {
|
|
94
|
+
const
|
|
95
|
+
{familyLinks} = this.owner,
|
|
96
|
+
i = familyLinks.indexOf(this.owner);
|
|
97
|
+
|
|
98
|
+
if (i >= 0) {
|
|
99
|
+
greenSplice(familyLinks, i);
|
|
100
|
+
}
|
|
101
|
+
this.broadcast(familyLinks, 'family-member-removed', this.owner);
|
|
102
|
+
this.events = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}());
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This component listens for specified local entity messages and re-broadcasts them at the scene level.
|
|
3
|
+
*
|
|
4
|
+
* @memberof platypus.components
|
|
5
|
+
* @class RelayGame
|
|
6
|
+
* @uses platypus.Component
|
|
7
|
+
*/
|
|
8
|
+
/* global platypus */
|
|
9
|
+
import createComponentClass from '../factory.js';
|
|
10
|
+
|
|
11
|
+
const
|
|
12
|
+
broadcast = function () {
|
|
13
|
+
platypus.game.triggerOnChildren.apply(platypus.game, arguments);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default createComponentClass(/** @lends platypus.components.RelayGame.prototype */{
|
|
17
|
+
id: 'RelayGame',
|
|
18
|
+
|
|
19
|
+
properties: {
|
|
20
|
+
/**
|
|
21
|
+
* This is an object of key/value pairs. The keys are events this component is listening for locally, and the value is the event to be broadcast to the scene. The value can also be an array of events to be fired on the scene.
|
|
22
|
+
*
|
|
23
|
+
* "events": {
|
|
24
|
+
* "sleeping": "good-night",
|
|
25
|
+
* "awake": ["alarm", "get-up"]
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @property events
|
|
29
|
+
* @type Object
|
|
30
|
+
* @default null
|
|
31
|
+
*/
|
|
32
|
+
events: null
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
initialize: function () {
|
|
36
|
+
const
|
|
37
|
+
events = this.events;
|
|
38
|
+
|
|
39
|
+
// Messages that this component listens for and then broadcasts to all layers.
|
|
40
|
+
if (events) {
|
|
41
|
+
const
|
|
42
|
+
keys = Object.keys(events),
|
|
43
|
+
{length} = keys;
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < length; i++) {
|
|
46
|
+
const
|
|
47
|
+
key = keys[i];
|
|
48
|
+
|
|
49
|
+
this.addEventListener(key, broadcast.bind(this, events[key]));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import createComponentClass from '../factory.js';
|
|
3
|
+
import {greenSplice} from '../utils/array.js';
|
|
4
|
+
|
|
5
|
+
const
|
|
6
|
+
channels = {},
|
|
7
|
+
broadcast = function (...args) {
|
|
8
|
+
const channel = this.channel;
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < channel.length; i++) {
|
|
11
|
+
channel[i].trigger(...args);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default createComponentClass(/** @lends platypus.components.RelayLinker.prototype */{
|
|
16
|
+
id: 'RelayLinker',
|
|
17
|
+
|
|
18
|
+
properties: {
|
|
19
|
+
/**
|
|
20
|
+
* The id that defines the 'channel' the linkers are talking on. This should be matched on the entity/entities you want to talk between.
|
|
21
|
+
*
|
|
22
|
+
* @property linkId
|
|
23
|
+
* @type String
|
|
24
|
+
* @default 'linked'
|
|
25
|
+
*/
|
|
26
|
+
linkId: 'linked',
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This is an object of key/value pairs. The keys are events this component is listening for locally, the value is the event to be broadcast to its linked entities. The value can also be an array of events to be fired on linked entities.
|
|
30
|
+
*
|
|
31
|
+
* "events": {
|
|
32
|
+
* "sleeping": "good-night",
|
|
33
|
+
* "awake": ["alarm", "get-up"]
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* @property events
|
|
37
|
+
* @type Object
|
|
38
|
+
* @default null
|
|
39
|
+
*/
|
|
40
|
+
events: null
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Allows an entity to communicate directly with one or more entities via the message model by passing local events directly to the linked entities as new triggered events.
|
|
45
|
+
*
|
|
46
|
+
* @memberof platypus.components
|
|
47
|
+
* @uses platypus.Component
|
|
48
|
+
* @constructs
|
|
49
|
+
* @listens platypus.Entity#load
|
|
50
|
+
*/
|
|
51
|
+
initialize: function () {
|
|
52
|
+
const
|
|
53
|
+
{events, linkId} = this;
|
|
54
|
+
|
|
55
|
+
if (events) {
|
|
56
|
+
const
|
|
57
|
+
keys = Object.keys(events),
|
|
58
|
+
{length} = keys;
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < length; i++) {
|
|
61
|
+
const
|
|
62
|
+
key = keys[i];
|
|
63
|
+
|
|
64
|
+
this.addEventListener(key, broadcast.bind(this, events[key]));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!this.owner.linkId) {
|
|
69
|
+
this.owner.linkId = linkId;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Connect channel, or create if it doesn't exist.
|
|
73
|
+
this.channel = channels[linkId] = channels[linkId] ?? [];
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
events: {
|
|
77
|
+
"load": function () {
|
|
78
|
+
this.channel.push(this.owner);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
methods: {
|
|
83
|
+
destroy: function () {
|
|
84
|
+
const index = this.channel.indexOf(this.owner);
|
|
85
|
+
|
|
86
|
+
if (index >= 0) {
|
|
87
|
+
greenSplice(this.channel, index);
|
|
88
|
+
} else {
|
|
89
|
+
platypus.debug.warn('RelayLinker: Component destroyed, but entity not found on channel.');
|
|
90
|
+
}
|
|
91
|
+
this.events = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This component listens for specified local entity messages and re-broadcasts them on its parent entity.
|
|
3
|
+
*
|
|
4
|
+
* @memberof platypus.components
|
|
5
|
+
* @class RelayParent
|
|
6
|
+
* @uses platypus.Component
|
|
7
|
+
*/
|
|
8
|
+
import createComponentClass from '../factory.js';
|
|
9
|
+
|
|
10
|
+
const
|
|
11
|
+
broadcast = function () {
|
|
12
|
+
const
|
|
13
|
+
{parent} = this.owner;
|
|
14
|
+
|
|
15
|
+
if (parent) {
|
|
16
|
+
parent.trigger.apply(parent, arguments);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default createComponentClass(/** @lends platypus.components.RelayParent.prototype */{
|
|
21
|
+
id: 'RelayParent',
|
|
22
|
+
|
|
23
|
+
properties: {
|
|
24
|
+
/**
|
|
25
|
+
* This is an object of key/value pairs. The keys are events this component is listening for locally, and the value is the event to be broadcast on the parent. The value can also be an array of events to be triggered on the parent.
|
|
26
|
+
*
|
|
27
|
+
* "events": {
|
|
28
|
+
* "sleeping": "good-night",
|
|
29
|
+
* "awake": ["alarm", "get-up"]
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @property events
|
|
33
|
+
* @type Object
|
|
34
|
+
* @default null
|
|
35
|
+
*/
|
|
36
|
+
events: null
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
initialize: function () {
|
|
40
|
+
const
|
|
41
|
+
events = this.events;
|
|
42
|
+
|
|
43
|
+
// Messages that this component listens for and then broadcasts to parent.
|
|
44
|
+
if (events) {
|
|
45
|
+
const
|
|
46
|
+
keys = Object.keys(events),
|
|
47
|
+
{length} = keys;
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < length; i++) {
|
|
50
|
+
const
|
|
51
|
+
key = keys[i];
|
|
52
|
+
|
|
53
|
+
this.addEventListener(key, broadcast.bind(this, events[key]));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This component listens for specified local entity messages and re-broadcasts them on itself as other messages.
|
|
3
|
+
*
|
|
4
|
+
* @memberof platypus.components
|
|
5
|
+
* @class RelaySelf
|
|
6
|
+
* @uses platypus.Component
|
|
7
|
+
*/
|
|
8
|
+
import createComponentClass from '../factory.js';
|
|
9
|
+
|
|
10
|
+
const
|
|
11
|
+
trigger = function () {
|
|
12
|
+
const
|
|
13
|
+
{owner} = this;
|
|
14
|
+
|
|
15
|
+
owner.trigger.apply(owner, arguments);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default createComponentClass(/** @lends platypus.components.RelaySelf.prototype */{
|
|
19
|
+
id: 'RelaySelf',
|
|
20
|
+
|
|
21
|
+
properties: {
|
|
22
|
+
/**
|
|
23
|
+
* This is an object of key/value pairs. The keys are events this component is listening for locally, the value is the new event to be broadcast on this entity. The value can also be an array of events to be fired.
|
|
24
|
+
*
|
|
25
|
+
* "events": {
|
|
26
|
+
* "sleeping": "good-night",
|
|
27
|
+
* "awake": ["alarm", "get-up"]
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @property events
|
|
31
|
+
* @type Object
|
|
32
|
+
* @default null
|
|
33
|
+
*/
|
|
34
|
+
events: null
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
initialize: function () {
|
|
38
|
+
const
|
|
39
|
+
events = this.events;
|
|
40
|
+
|
|
41
|
+
// Messages that this component listens for and then triggers on itself as a renamed message - useful as a logic place-holder for simple entities.
|
|
42
|
+
if (events) {
|
|
43
|
+
const
|
|
44
|
+
keys = Object.keys(events),
|
|
45
|
+
{length} = keys;
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < length; i++) {
|
|
48
|
+
const
|
|
49
|
+
key = keys[i];
|
|
50
|
+
|
|
51
|
+
this.addEventListener(key, trigger.bind(this, events[key]));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|