@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.
Files changed (136) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +3 -3
  3. package/lib/platypus.js +1 -1
  4. package/package.json +6 -5
  5. package/src/AABB.js +685 -0
  6. package/src/ActionState.js +121 -0
  7. package/src/AssetManager.js +206 -0
  8. package/src/CollisionData.js +96 -0
  9. package/src/CollisionDataContainer.js +127 -0
  10. package/src/CollisionShape.js +315 -0
  11. package/src/Component.js +231 -0
  12. package/src/Data.js +64 -0
  13. package/src/DataMap.js +204 -0
  14. package/src/Entity.js +404 -0
  15. package/src/EntityLinker.js +113 -0
  16. package/src/EventHandler.js +115 -0
  17. package/src/EventHandlerList.js +251 -0
  18. package/src/Game.js +840 -0
  19. package/src/Gamepad.js +175 -0
  20. package/src/ID3CaptionPlayer.js +61 -0
  21. package/src/Messenger.js +365 -0
  22. package/src/PIXIAnimation.js +622 -0
  23. package/src/RandomSet.js +140 -0
  24. package/src/SFXPlayer.js +120 -0
  25. package/src/StateMap.js +252 -0
  26. package/src/Storage.js +152 -0
  27. package/src/TickerClient.js +48 -0
  28. package/src/TickerServer.js +23 -0
  29. package/src/TimeEvent.js +50 -0
  30. package/src/TimeEventList.js +100 -0
  31. package/src/VOPlayer.js +684 -0
  32. package/src/Vector.js +702 -0
  33. package/src/components/AIChaser.js +161 -0
  34. package/src/components/AIPacer.js +107 -0
  35. package/src/components/AudioMusic.js +151 -0
  36. package/src/components/AudioSFX.js +673 -0
  37. package/src/components/AudioVO.js +301 -0
  38. package/src/components/CollisionBasic.js +826 -0
  39. package/src/components/CollisionFilter.js +74 -0
  40. package/src/components/CollisionGroup.js +448 -0
  41. package/src/components/CollisionTiles.js +608 -0
  42. package/src/components/ComponentSwitcher.js +173 -0
  43. package/src/components/ControllerInput.js +65 -0
  44. package/src/components/Counter.js +165 -0
  45. package/src/components/EntityCamera.js +215 -0
  46. package/src/components/EntityContainer.js +549 -0
  47. package/src/components/EntityController.js +541 -0
  48. package/src/components/HandlerCamera.js +1052 -0
  49. package/src/components/HandlerCollision.js +1318 -0
  50. package/src/components/HandlerController.js +291 -0
  51. package/src/components/HandlerLogic.js +394 -0
  52. package/src/components/HandlerRender.js +217 -0
  53. package/src/components/Interactive.js +502 -0
  54. package/src/components/LevelBuilder.js +524 -0
  55. package/src/components/LogicAngularMovement.js +154 -0
  56. package/src/components/LogicAttachment.js +265 -0
  57. package/src/components/LogicButton.js +466 -0
  58. package/src/components/LogicCarrier.js +39 -0
  59. package/src/components/LogicDestroyMe.js +58 -0
  60. package/src/components/LogicDirectionalMovement.js +325 -0
  61. package/src/components/LogicDragDrop.js +371 -0
  62. package/src/components/LogicImpactLaunch.js +144 -0
  63. package/src/components/LogicPacingPlatform.js +64 -0
  64. package/src/components/LogicPortable.js +112 -0
  65. package/src/components/LogicPortal.js +115 -0
  66. package/src/components/LogicPushable.js +98 -0
  67. package/src/components/LogicRebounder.js +136 -0
  68. package/src/components/LogicRegionSpawner.js +139 -0
  69. package/src/components/LogicRotationalMovement.js +205 -0
  70. package/src/components/LogicSpawner.js +159 -0
  71. package/src/components/LogicStateMachine.js +382 -0
  72. package/src/components/LogicSwitch.js +77 -0
  73. package/src/components/LogicTeleportee.js +68 -0
  74. package/src/components/LogicTeleporter.js +93 -0
  75. package/src/components/LogicTimer.js +178 -0
  76. package/src/components/LogicWindUpRacer.js +179 -0
  77. package/src/components/Motion.js +371 -0
  78. package/src/components/Mover.js +566 -0
  79. package/src/components/Node.js +289 -0
  80. package/src/components/NodeMap.js +295 -0
  81. package/src/components/NodeResident.js +636 -0
  82. package/src/components/Orientation.js +697 -0
  83. package/src/components/RandomEvents.js +73 -0
  84. package/src/components/RelativePosition.js +204 -0
  85. package/src/components/RelayFamily.js +106 -0
  86. package/src/components/RelayGame.js +53 -0
  87. package/src/components/RelayLinker.js +94 -0
  88. package/src/components/RelayParent.js +57 -0
  89. package/src/components/RelaySelf.js +55 -0
  90. package/src/components/Render.js +178 -0
  91. package/src/components/RenderAnimator.js +275 -0
  92. package/src/components/RenderContainer.js +646 -0
  93. package/src/components/RenderDebug.js +319 -0
  94. package/src/components/RenderDestroyMe.js +59 -0
  95. package/src/components/RenderLottie.js +149 -0
  96. package/src/components/RenderProgress.js +120 -0
  97. package/src/components/RenderSpine.js +833 -0
  98. package/src/components/RenderSprite.js +527 -0
  99. package/src/components/RenderText.js +147 -0
  100. package/src/components/RenderTiles.js +1391 -0
  101. package/src/components/SceneChanger.js +128 -0
  102. package/src/components/TiledLoader.js +1451 -0
  103. package/src/components/Timeline.js +314 -0
  104. package/src/components/Tutorial.js +267 -0
  105. package/src/components/Tween.js +296 -0
  106. package/src/components/VoiceOver.js +373 -0
  107. package/src/components/XHR.js +129 -0
  108. package/src/components/index.js +79 -0
  109. package/src/factory.js +305 -0
  110. package/src/index.js +159 -0
  111. package/src/mixins/PIXI.Graphics.js +41 -0
  112. package/src/platypus.css +68 -0
  113. package/src/sayHello.js +50 -0
  114. package/src/shapes/Capsule.js +74 -0
  115. package/src/shapes/Circle.js +43 -0
  116. package/src/shapes/Ellipse.js +117 -0
  117. package/src/shapes/Point.js +191 -0
  118. package/src/shapes/Polygon.js +112 -0
  119. package/src/shapes/Polyline.js +97 -0
  120. package/src/shapes/Rectangle.js +78 -0
  121. package/src/shapes/RoundedRectangle.js +33 -0
  122. package/src/shapes/Segment.js +346 -0
  123. package/src/shapes/adjustedXY.js +19 -0
  124. package/src/shapes/castFromBox2D.js +92 -0
  125. package/src/shapes/castFromObject.js +53 -0
  126. package/src/shapes/castFromPixiGraphics.js +6 -0
  127. package/src/shapes/castFromPixiShape.js +89 -0
  128. package/src/shapes/castToBox2D.js +190 -0
  129. package/src/shapes/castToPixiGraphics.js +100 -0
  130. package/src/shapes/castToPixiShape.js +61 -0
  131. package/src/shapes/checkPointsMap.js +313 -0
  132. package/src/shapes/index.js +35 -0
  133. package/src/utils/array.js +73 -0
  134. package/src/utils/string.js +39 -0
  135. package/lib/243.platypus.mjs +0 -1
  136. package/lib/platypus.mjs +0 -1
@@ -0,0 +1,113 @@
1
+ import {arrayCache, greenSplice} from './utils/array';
2
+ import Data from './Data';
3
+ import DataMap from './DataMap';
4
+ import recycle from 'recycle';
5
+
6
+ const
7
+ /**
8
+ * This class defines a linker for TiledLoader to connect entity pointer properties as soon as both entities are created.
9
+ *
10
+ * @memberof platypus
11
+ * @class EntityLinker
12
+ * @return {EntityLinker} Returns the new EntityLinker object.
13
+ */
14
+ EntityLinker = function () {
15
+ this.ids = this.ids || arrayCache.setUp();
16
+ this.entities = this.entities || DataMap.setUp();
17
+ this.currentId = 0;
18
+ this.count = 1;
19
+ },
20
+ proto = EntityLinker.prototype;
21
+
22
+ proto.attemptRecycle = function () {
23
+ this.count -= 1;
24
+ if (this.count === 0) {
25
+ this.recycle();
26
+ }
27
+ };
28
+
29
+ proto.linkObject = function (id) {
30
+ this.currentId = id;
31
+ this.count += 1;
32
+ };
33
+
34
+ proto.linkEntity = function (entity) {
35
+ const
36
+ id = entity.tiledId,
37
+ list = this.ids;
38
+ let i = list.length;
39
+
40
+ while (i--) {
41
+ const
42
+ item = list[i];
43
+ let updated = false;
44
+
45
+ if (item.onEntity === entity.tiledId) {
46
+ item.onEntity = entity;
47
+ updated = true;
48
+ }
49
+ if (item.toEntity === entity.tiledId) {
50
+ item.toEntity = entity;
51
+ updated = true;
52
+ }
53
+ if (updated && typeof item.onEntity === 'object' && typeof item.toEntity === 'object') {
54
+ item.onEntity[item.property] = item.toEntity;
55
+ item.recycle();
56
+ greenSplice(list, i);
57
+ }
58
+ }
59
+
60
+ this.entities[id] = entity;
61
+ this.attemptRecycle();
62
+
63
+ return entity;
64
+ };
65
+
66
+ proto.getEntity = function (id, property) {
67
+ const entity = this.entities[id];
68
+
69
+ if (entity) {
70
+ return entity;
71
+ } else {
72
+ this.ids.push(Data.setUp(
73
+ 'onEntity', this.currentId,
74
+ 'toEntity', id,
75
+ 'property', property
76
+ ));
77
+ return null;
78
+ }
79
+ };
80
+
81
+ /**
82
+ * Returns EntityLinker from cache or creates a new one if none are available.
83
+ *
84
+ * @method platypus.EntityLinker.setUp
85
+ * @return {platypus.EntityLinker} The instantiated EntityLinker.
86
+ */
87
+ /**
88
+ * Returns EntityLinker back to the cache. Prefer the EntityLinker's recycle method since it recycles property objects as well.
89
+ *
90
+ * @method platypus.EntityLinker.recycle
91
+ * @param {platypus.EntityLinker} The EntityLinker to be recycled.
92
+ */
93
+ /**
94
+ * Relinquishes EntityLinker properties and recycles it.
95
+ *
96
+ * @method platypus.EntityLinker#recycle
97
+ */
98
+ recycle.add(EntityLinker, 'EntityLinker', EntityLinker, function () {
99
+ const
100
+ entities = this.entities,
101
+ keys = Object.keys(entities),
102
+ ids = this.ids;
103
+
104
+ for (let i = 0; i < keys.length; i++) {
105
+ delete entities[keys[i]];
106
+ }
107
+ for (let i = 0; i < ids.length; i++) {
108
+ ids[i].recycle();
109
+ }
110
+ ids.length = 0;
111
+ }, true);
112
+
113
+ export default EntityLinker;
@@ -0,0 +1,115 @@
1
+ import recycle from 'recycle';
2
+
3
+ /**
4
+ * Represents a single event subscription entry used by the event system.
5
+ *
6
+ * EventHandler instances are stored inside event emitter structures and
7
+ * sorted using `priority` and `order` to determine execution sequence.
8
+ *
9
+ * Higher priority values execute before lower ones. When priorities match,
10
+ * `order` acts as a stable tie-breaker preserving insertion sequence.
11
+ *
12
+ * Instances are pooled through `recycle` to reduce GC pressure in hot loops.
13
+ *
14
+ * @memberof platypus
15
+ * @class EventHandler
16
+ *
17
+ * @param {Function} callback Function invoked when the event fires.
18
+ * @param {Object} context Value used as `this` inside callback execution.
19
+ * @param {Number} priority Execution priority (higher runs first).
20
+ * @param {Number} order Stable ordering index used when priorities match.
21
+ *
22
+ * @property {Function} callback
23
+ * @property {Object} context
24
+ * @property {Number} priority
25
+ * @property {Number} order
26
+ */
27
+ const EventHandler = function (callback, context = null, once = false, priority = 0, order = 0) {
28
+ this.callback = callback;
29
+ this.context = context;
30
+ this.once = once;
31
+ this.priority = priority;
32
+ this.order = order;
33
+ };
34
+
35
+ const { prototype } = EventHandler;
36
+
37
+ /**
38
+ * Comparator used for sorting event handlers.
39
+ *
40
+ * Returns a negative number if this handler should run before the other.
41
+ * Returns a positive number if it should run after.
42
+ * Returns 0 when equivalent.
43
+ *
44
+ * Sorting rule:
45
+ * 1. higher priority runs first
46
+ * 2. if equal, lower order runs first
47
+ */
48
+ prototype.sortPriority = function (eventHandler) {
49
+ return (this.priority - eventHandler.priority) || (this.order - eventHandler.order);
50
+ };
51
+
52
+ /**
53
+ * Returns EventHandler from cache or creates a new one.
54
+ *
55
+ * @method platypus.EventHandler.setUp
56
+ * @return {platypus.EventHandler}
57
+ */
58
+
59
+ /**
60
+ * Returns EventHandler back to cache. If the instance has
61
+ * outstanding holds, the recycle is deferred until all holds
62
+ * are released.
63
+ *
64
+ * Prefer calling `eventHandler.recycle()`
65
+ * instead of direct pool access.
66
+ *
67
+ * @method platypus.EventHandler.recycle
68
+ * @param {platypus.EventHandler} eventHandler
69
+ */
70
+
71
+ /**
72
+ * Increments the hold count on the instance, preventing recycling
73
+ * until all holds are released. Returns the instance for chaining.
74
+ *
75
+ * @method platypus.EventHandler.recycleHold
76
+ * @param {platypus.EventHandler} eventHandler
77
+ * @return {platypus.EventHandler}
78
+ */
79
+
80
+ /**
81
+ * Decrements the hold count. When it reaches zero, any pending
82
+ * recycle is flushed. Returns the instance for chaining.
83
+ *
84
+ * @method platypus.EventHandler.recycleRelease
85
+ * @param {platypus.EventHandler} eventHandler
86
+ * @return {platypus.EventHandler}
87
+ */
88
+
89
+ /**
90
+ * Clears internal references and recycles the instance. If the
91
+ * instance has outstanding holds, the recycle is deferred until
92
+ * all holds are released.
93
+ *
94
+ * @method platypus.EventHandler#recycle
95
+ */
96
+
97
+ /**
98
+ * Increments the hold count on the instance, preventing recycling
99
+ * until all holds are released. Returns the instance for chaining.
100
+ *
101
+ * @method platypus.EventHandler#recycleHold
102
+ * @return {platypus.EventHandler}
103
+ */
104
+
105
+ /**
106
+ * Decrements the hold count. When it reaches zero, any pending
107
+ * recycle is flushed. Returns the instance for chaining.
108
+ *
109
+ * @method platypus.EventHandler#recycleRelease
110
+ * @return {platypus.EventHandler}
111
+ */
112
+
113
+ recycle.add(EventHandler, 'EventHandler', EventHandler, null, true);
114
+
115
+ export default EventHandler;
@@ -0,0 +1,251 @@
1
+ import recycle from 'recycle';
2
+ import EventHandler from './EventHandler';
3
+ import { arrayCache, greenSlice, greenSplice } from './utils/array';
4
+
5
+ /**
6
+ * Maintains an ordered list of event handlers for a single event type.
7
+ *
8
+ * EventHandlerList supports:
9
+ * - listener priorities
10
+ * - deterministic insertion ordering
11
+ * - safe mutation during dispatch
12
+ * - one-time listeners
13
+ * - recyclable pooled handlers
14
+ *
15
+ * Handlers are lazily sorted on first dispatch after modification.
16
+ *
17
+ * @memberof platypus
18
+ * @class EventHandlerList
19
+ */
20
+ const EventHandlerList = function () {
21
+ /**
22
+ * Whether the handler list requires resorting.
23
+ *
24
+ * @property dirty
25
+ * @type Boolean
26
+ * @default false
27
+ */
28
+ this.dirty = false;
29
+
30
+ /**
31
+ * The ordered list of EventHandler objects.
32
+ *
33
+ * @property handlers
34
+ * @type Array
35
+ */
36
+ this.handlers = arrayCache.setUp();
37
+
38
+ /**
39
+ * Incrementing insertion index used to preserve
40
+ * deterministic ordering between equal priorities.
41
+ *
42
+ * @property orderIndex
43
+ * @type Number
44
+ * @default 0
45
+ */
46
+ this.orderIndex = 0;
47
+ };
48
+
49
+ const { prototype } = EventHandlerList;
50
+
51
+ /**
52
+ * Adds a new handler to the list.
53
+ *
54
+ * Handlers are not immediately sorted. Sorting occurs lazily
55
+ * during the next dispatch.
56
+ *
57
+ * @method add
58
+ * @param callback {Function}
59
+ * The listener callback function.
60
+ *
61
+ * @param [context=null] {Object}
62
+ * The callback execution context.
63
+ *
64
+ * @param [priority=0] {Number}
65
+ * Lower numbers execute first.
66
+ *
67
+ * @return {platypus.EventHandler}
68
+ * Returns the created EventHandler instance.
69
+ */
70
+ prototype.add = function (callback, context, once, priority) {
71
+ for (let i = 0; i < this.handlers.length; i++) {
72
+ const existing = this.handlers[i];
73
+
74
+ if (
75
+ existing.callback === callback &&
76
+ existing.context === context
77
+ ) {
78
+ return null;
79
+ }
80
+ }
81
+
82
+ const
83
+ eventHandler = EventHandler.setUp(
84
+ callback,
85
+ context,
86
+ once,
87
+ priority,
88
+ this.orderIndex++
89
+ );
90
+
91
+ this.handlers.push(eventHandler);
92
+ this.dirty = true;
93
+
94
+ return eventHandler;
95
+ };
96
+
97
+ /**
98
+ * Removes all handlers matching the supplied callback.
99
+ *
100
+ * @method remove
101
+ * @param callback {Function}
102
+ * @param context {Object}
103
+ * The callback function to remove.
104
+ */
105
+ prototype.remove = function (callback, context) {
106
+ const
107
+ {handlers} = this;
108
+ let i = handlers.length;
109
+
110
+ while (i--) {
111
+ const
112
+ handler = handlers[i];
113
+
114
+ if (
115
+ handler.callback === callback &&
116
+ (
117
+ typeof context === 'undefined' ||
118
+ handler.context === context
119
+ )
120
+ ) {
121
+ handler.recycle();
122
+ greenSplice(handlers, i);
123
+ }
124
+ }
125
+ };
126
+
127
+ /**
128
+ * Dispatches the event to all registered handlers.
129
+ *
130
+ * The handler list is shallow-copied before iteration
131
+ * so listeners may safely remove themselves during dispatch.
132
+ *
133
+ * @method trigger
134
+ * @param [args] {Array}
135
+ * The arguments passed to listener callbacks.
136
+ *
137
+ * @return {Number}
138
+ * Returns the number of handlers triggered.
139
+ */
140
+ prototype.trigger = function (args) {
141
+ if (this.dirty) {
142
+ this.handlers.sort((a, b) => a.sortPriority(b));
143
+ this.dirty = false;
144
+ }
145
+
146
+ const
147
+ handlers = greenSlice(this.handlers),
148
+ {length} = handlers;
149
+
150
+ // This prevents event handlers from getting recycled in the handlers copy.
151
+ for (let i = 0; i < length; i++) {
152
+ handlers[i].recycleHold();
153
+ }
154
+
155
+ for (let i = 0; i < length; i++) {
156
+ const
157
+ {callback, context, once} = handlers[i];
158
+
159
+ if (once) {
160
+ this.remove(callback);
161
+ }
162
+
163
+ callback.apply(context, args);
164
+ }
165
+
166
+ for (let i = 0; i < length; i++) {
167
+ handlers[i].recycleRelease();
168
+ }
169
+
170
+ arrayCache.recycle(handlers);
171
+
172
+ return length;
173
+ };
174
+
175
+ /**
176
+ * Returns EventHandlerList from cache or creates a new one.
177
+ *
178
+ * @method platypus.EventHandlerList.setUp
179
+ * @return {platypus.EventHandlerList}
180
+ */
181
+
182
+ /**
183
+ * Returns EventHandlerList back to cache. If the instance has
184
+ * outstanding holds, the recycle is deferred until all holds
185
+ * are released.
186
+ *
187
+ * Prefer calling `eventHandlerList.recycle()`
188
+ * instead of direct pool access.
189
+ *
190
+ * @method platypus.EventHandlerList.recycle
191
+ * @param {platypus.EventHandlerList} eventHandlerList
192
+ */
193
+
194
+ /**
195
+ * Increments the hold count on the instance, preventing recycling
196
+ * until all holds are released. Returns the instance for chaining.
197
+ *
198
+ * @method platypus.EventHandlerList.recycleHold
199
+ * @param {platypus.EventHandlerList} eventHandlerList
200
+ * @return {platypus.EventHandlerList}
201
+ */
202
+
203
+ /**
204
+ * Decrements the hold count. When it reaches zero, any pending
205
+ * recycle is flushed. Returns the instance for chaining.
206
+ *
207
+ * @method platypus.EventHandlerList.recycleRelease
208
+ * @param {platypus.EventHandlerList} eventHandlerList
209
+ * @return {platypus.EventHandlerList}
210
+ */
211
+
212
+ /**
213
+ * Clears internal references and recycles the instance. If the
214
+ * instance has outstanding holds, the recycle is deferred until
215
+ * all holds are released.
216
+ *
217
+ * @method platypus.EventHandlerList#recycle
218
+ */
219
+
220
+ /**
221
+ * Increments the hold count on the instance, preventing recycling
222
+ * until all holds are released. Returns the instance for chaining.
223
+ *
224
+ * @method platypus.EventHandlerList#recycleHold
225
+ * @return {platypus.EventHandlerList}
226
+ */
227
+
228
+ /**
229
+ * Decrements the hold count. When it reaches zero, any pending
230
+ * recycle is flushed. Returns the instance for chaining.
231
+ *
232
+ * @method platypus.EventHandlerList#recycleRelease
233
+ * @return {platypus.EventHandlerList}
234
+ */
235
+ recycle.add(
236
+ EventHandlerList,
237
+ 'EventHandlerList',
238
+ EventHandlerList,
239
+ function () {
240
+ this.handlers.forEach((handler) => handler.recycle());
241
+
242
+ arrayCache.recycle(this.handlers);
243
+
244
+ this.handlers = null;
245
+ this.dirty = false;
246
+ this.orderIndex = 0;
247
+ },
248
+ true
249
+ );
250
+
251
+ export default EventHandlerList;