@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,139 @@
1
+ /**
2
+ ## JSON Definition
3
+ {
4
+ "type": "LogicRegionSpawner",
5
+ // List all additional parameters and their possible values here.
6
+
7
+ "spawn": "teddy-bear",
8
+ // Required. String identifying the type of entity to spawn.
9
+
10
+ "interval": 30000,
11
+ // Optional. Time in milliseconds between spawning an entity. Defaults to 1000.
12
+
13
+ "regions": {
14
+ // If spawning entity covers a large area, the spawned entities can be randomly spawned over a regional grid, so that the whole area gets a somewhat uniform coverage of spawned entities
15
+
16
+ "width": 4000,
17
+ "height": 5000,
18
+ // Optional. Dimensions of a spawning region in world units. Defaults to entity's dimensions. The entity's dimensions are sliced into chunks of this size for spawn distribution.
19
+ }
20
+ }
21
+ */
22
+ import Entity from '../Entity.js';
23
+ import {arrayCache} from '../utils/array.js';
24
+ import createComponentClass from '../factory.js';
25
+
26
+ export default (function () {
27
+ return createComponentClass(/** @lends platypus.components.LogicRegionSpawner.prototype */{
28
+
29
+ id: 'LogicRegionSpawner',
30
+
31
+ /**
32
+ * This component spawns new entities within a given area at set intervals.
33
+ *
34
+ * @memberof platypus.components
35
+ * @uses platypus.Component
36
+ * @constructs
37
+ * @param {*} definition
38
+ * @listens platypus.Entity#handle-logic
39
+ */
40
+ initialize: function (definition) {
41
+ this.spawnPosition = {
42
+ x: 0,
43
+ y: 0
44
+ };
45
+ this.spawnProperties = {
46
+ type: definition.spawn,
47
+ properties: this.spawnPosition
48
+ };
49
+
50
+ this.regions = null;
51
+ this.usedRegions = null;
52
+ this.regionWidth = 0;
53
+ this.regionHeight = 0;
54
+ if (definition.regions) {
55
+ const
56
+ width = definition.regions.width || this.owner.width,
57
+ height = definition.regions.height || this.owner.height,
58
+ columns = Math.round(this.owner.width / width),
59
+ rows = Math.round(this.owner.height / height);
60
+
61
+ this.regions = arrayCache.setUp();
62
+ this.usedRegions = arrayCache.setUp();
63
+ this.regionWidth = width;
64
+ this.regionHeight = height;
65
+
66
+ for (let x = 0; x < columns; x++) {
67
+ for (let y = 0; y < rows; y++) {
68
+ const
69
+ rw = Math.min(width, this.owner.width - x * width),
70
+ rh = Math.min(height, this.owner.height - y * height);
71
+
72
+ this.regions.push({
73
+ x: x * width,
74
+ y: y * height,
75
+ width: rw,
76
+ height: rh
77
+ });
78
+ }
79
+ }
80
+ }
81
+
82
+ this.interval = this.owner.interval || definition.interval || 1000;
83
+ this.time = 0;
84
+ },
85
+
86
+ events: {// These are messages that this component listens for
87
+ "handle-logic": function ({delta}) {
88
+ this.time += delta;
89
+
90
+ if (this.time > this.interval) {
91
+ let regions = this.regions,
92
+ region = null;
93
+
94
+ this.time -= this.interval;
95
+
96
+ if (regions) {
97
+ if (!regions.length) {
98
+ this.regions = this.usedRegions;
99
+ this.usedRegions = regions;
100
+ regions = this.regions;
101
+ }
102
+
103
+ region = regions[Math.floor(regions.length * Math.random())];
104
+
105
+ this.spawnPosition.x = this.owner.x - (this.owner.regX || 0) + (region.x + (Math.random() * region.width));
106
+ this.spawnPosition.y = this.owner.y - (this.owner.regY || 0) + (region.y + (Math.random() * region.height));
107
+ } else {
108
+ this.spawnPosition.x = this.owner.x - (this.owner.regX || 0) + (Math.random() * this.owner.width);
109
+ this.spawnPosition.y = this.owner.y - (this.owner.regY || 0) + (Math.random() * this.owner.height);
110
+ }
111
+
112
+ this.owner.parent.addEntity(this.spawnProperties);
113
+ }
114
+ }
115
+ },
116
+
117
+ methods: {
118
+ destroy: function () {
119
+ if (this.regions) {
120
+ arrayCache.recycle(this.regions);
121
+ arrayCache.recycle(this.usedRegions);
122
+ }
123
+ }
124
+ },
125
+
126
+ getAssetList: function (def, props, defaultProps) {
127
+ const
128
+ spawn = def?.spawn ?? props?.spawn ?? defaultProps?.spawn;
129
+
130
+ if (spawn) {
131
+ return Entity.getAssetList({
132
+ type: spawn
133
+ });
134
+ }
135
+
136
+ return arrayCache.setUp();
137
+ }
138
+ });
139
+ }());
@@ -0,0 +1,205 @@
1
+ import createComponentClass from '../factory.js';
2
+
3
+ export default (function () {
4
+ const
5
+ cos = Math.cos,
6
+ sin = Math.sin,
7
+ polarToCartesianX = function (m, a) {
8
+ return m * cos(a);
9
+ },
10
+ polarToCartesianY = function (m, a) {
11
+ return m * sin(a);
12
+ };
13
+
14
+ return createComponentClass(/** @lends platypus.components.LogicRotationalMovement.prototype */{
15
+ id: 'LogicRotationalMovement',
16
+
17
+ properties: {
18
+ /**
19
+ * Defines the distance in world units that the entity should be moved per millisecond.
20
+ *
21
+ * @property speed
22
+ * @type Number
23
+ * @default 0.3
24
+ */
25
+ "speed": 0.3,
26
+
27
+ /**
28
+ * Radian orientation that entity should begin in. Defaults to 0 (facing right).
29
+ *
30
+ * @property angle
31
+ * @type Number
32
+ * @default 0
33
+ */
34
+ "angle": 0,
35
+
36
+ /**
37
+ * Unit in radians that the angle should change per millisecond.
38
+ *
39
+ * @property degree
40
+ * @type Number
41
+ * @default 1
42
+ */
43
+ "degree": 1
44
+ },
45
+
46
+ /**
47
+ * This component changes the (x, y) position of an object according to its current speed and heading. It maintains its own heading information independent of other components allowing it to be used simultaneously with other logic components like [[Logic-Pushable]]. It accepts directional messages that can stand alone, or come from a mapped controller, in which case it checks the `pressed` value of the message before changing its course accordingly.
48
+ *
49
+ * @memberof platypus.components
50
+ * @uses platypus.Component
51
+ * @constructs
52
+ * @listens platypus.Entity#handle-logic
53
+ * @listens platypus.Entity#stop
54
+ * @listens platypus.Entity#go-forward
55
+ * @listens platypus.Entity#go-backward
56
+ * @listens platypus.Entity#rotate
57
+ * @listens platypus.Entity#turn-right
58
+ * @listens platypus.Entity#turn-left
59
+ * @listens platypus.Entity#stop-moving
60
+ * @listens platypus.Entity#stop-turning
61
+ * @fires platypus.Entity#orientation-updated
62
+ */
63
+ initialize: function () {
64
+ const
65
+ state = this.owner.state;
66
+
67
+ this.magnitude = 0;
68
+
69
+ this.state = state;
70
+ state.set('moving', false);
71
+ state.set('turningRight', false);
72
+ state.set('turningLeft', false);
73
+
74
+ this.owner.orientation = 0;
75
+
76
+ this.moving = false;
77
+ this.turningRight = false;
78
+ this.turningLeft = false;
79
+ },
80
+
81
+ events: {
82
+ "handle-logic": function (tick) {
83
+ const
84
+ state = this.state;
85
+
86
+ if (this.turningRight) {
87
+ this.angle += this.degree * tick.delta / 15;
88
+ }
89
+
90
+ if (this.turningLeft) {
91
+ this.angle -= this.degree * tick.delta / 15;
92
+ }
93
+
94
+ if (this.moving) {
95
+ this.owner.x += (polarToCartesianX(this.magnitude, this.angle) * tick.delta);
96
+ this.owner.y += (polarToCartesianY(this.magnitude, this.angle) * tick.delta);
97
+ }
98
+
99
+ state.set('moving', this.moving);
100
+ state.set('turningLeft', this.turningLeft);
101
+ state.set('turningRight', this.turningRight);
102
+
103
+ if (this.owner.orientation !== this.angle * Math.PI / 180) {
104
+ this.owner.orientation = this.angle * Math.PI / 180;
105
+ this.owner.triggerEvent('orientation-updated');
106
+ }
107
+ },
108
+
109
+ /**
110
+ * This rotates the entity by a delta in radians.
111
+ *
112
+ * @event platypus.Entity#rotate
113
+ * @param angleDelta {Number} The change in angle.
114
+ */
115
+ "rotate": function (angleDelta) {
116
+ this.angle += angleDelta;
117
+ },
118
+
119
+ /**
120
+ * On receiving this event, the entity turns right.
121
+ *
122
+ * @event platypus.Entity#turn-right
123
+ * @param [state.pressed] {boolean} If `state` is included, the component checks the value of `pressed`: true causes movement in the triggered direction, false turns off movement in that direction. Note that if no message is included, the only way to stop movement in a particular direction is to trigger `stop` on the entity before progressing in a new orientation.
124
+ */
125
+ "turn-right": function (state) {
126
+ if (state) {
127
+ this.turningRight = state.pressed;
128
+ } else {
129
+ this.turningRight = true;
130
+ }
131
+ },
132
+
133
+ /**
134
+ * On receiving this event, the entity turns left.
135
+ *
136
+ * @event platypus.Entity#turn-left
137
+ * @param [state.pressed] {boolean} If `state` is included, the component checks the value of `pressed`: true causes movement in the triggered direction, false turns off movement in that direction. Note that if no message is included, the only way to stop movement in a particular direction is to trigger `stop` on the entity before progressing in a new orientation.
138
+ */
139
+ "turn-left": function (state) {
140
+ if (state) {
141
+ this.turningLeft = state.pressed;
142
+ } else {
143
+ this.turningLeft = true;
144
+ }
145
+ },
146
+
147
+ "go-forward": function (state) {
148
+ if (!state || state.pressed) {
149
+ this.moving = true;
150
+ this.magnitude = this.speed;
151
+ } else {
152
+ this.moving = false;
153
+ }
154
+ },
155
+
156
+ "go-backward": function (state) {
157
+ if (!state || state.pressed) {
158
+ this.moving = true;
159
+ this.magnitude = -this.speed;
160
+ } else {
161
+ this.moving = false;
162
+ }
163
+ },
164
+
165
+ "stop": function (state) {
166
+ if (!state || state.pressed) {
167
+ this.moving = false;
168
+ this.turningLeft = false;
169
+ this.turningRight = false;
170
+ }
171
+ },
172
+
173
+ /**
174
+ * Stops linear motion until movement messages are again received.
175
+ *
176
+ * @event platypus.Entity#stop-moving
177
+ * @param [state.pressed] {Boolean} If `state` is included, the component checks the value of `pressed`: a value of false will not stop the entity.
178
+ */
179
+ "stop-moving": function (state) {
180
+ if (!state || state.pressed) {
181
+ this.moving = false;
182
+ }
183
+ },
184
+
185
+ /**
186
+ * Stops rotational motion until movement messages are again received.
187
+ *
188
+ * @event platypus.Entity#stop-turning
189
+ * @param [state.pressed] {Boolean} If `state` is included, the component checks the value of `pressed`: a value of false will not stop the entity.
190
+ */
191
+ "stop-turning": function (state) {
192
+ if (!state || state.pressed) {
193
+ this.turningLeft = false;
194
+ this.turningRight = false;
195
+ }
196
+ }
197
+ },
198
+
199
+ methods: {
200
+ destroy: function () {
201
+ this.state = null;
202
+ }
203
+ }
204
+ });
205
+ }());
@@ -0,0 +1,159 @@
1
+ /**
2
+ ## JSON Definition
3
+ {
4
+ "type": "LogicSpawner"
5
+ // List all additional parameters and their possible values here.
6
+
7
+ "spawneeClass": "wet-noodle",
8
+ // Required: string identifying the type of entity to create.
9
+
10
+ "state": "tossing",
11
+ // Optional. The entity state that should be true while entities are being created. Defaults to "firing".
12
+
13
+ "speed": 4,
14
+ // Optional. The velocity with which the entity should start. Initial direction is determined by this entity's facing states ("top", "right", etc).
15
+
16
+ "offsetX": 45,
17
+ "offsetY": -20,
18
+ // Optional. Location relative to the entity where the should be located once created. Defaults to (0, 0).
19
+ }
20
+ */
21
+ /* global platypus */
22
+ import Entity from '../Entity.js';
23
+ import {arrayCache} from '../utils/array.js';
24
+ import createComponentClass from '../factory.js';
25
+
26
+ export default (function () {
27
+ return createComponentClass(/** @lends platypus.components.LogicSpawner.prototype */{
28
+
29
+ id: 'LogicSpawner',
30
+
31
+ /**
32
+ * This component creates an entity and propels it away. This is useful for casting, firing, tossing, and related behaviors.
33
+ *
34
+ * @memberof platypus.components
35
+ * @uses platypus.Component
36
+ * @constructs
37
+ * @param {*} definition
38
+ * @listens platypus.Entity#handle-logic
39
+ */
40
+ initialize: function (definition) {
41
+ const
42
+ className = this.owner.spawneeClass || definition.spawneeClass;
43
+
44
+ this.state = this.owner.state;
45
+ this.stateName = definition.state || 'spawning';
46
+ this.originalZ = (platypus.game.settings.entities[className] && platypus.game.settings.entities[className].properties && platypus.game.settings.entities[className].properties.z) || 0;
47
+ this.speed = definition.speed || this.owner.speed || 0;
48
+
49
+ this.state.set(this.stateName, false);
50
+
51
+ this.spawneeProperties = {
52
+ x: 0,
53
+ y: 0,
54
+ z: 0,
55
+ dx: 0,
56
+ dy: 0,
57
+ spawner: this.owner
58
+ };
59
+
60
+ if (definition.passOnProperties) {
61
+ for (let x = 0; x < definition.passOnProperties.length; x++) {
62
+ const
63
+ prop = definition.passOnProperties[x];
64
+
65
+ if (this.owner[prop]) {
66
+ this.spawneeProperties[prop] = this.owner[prop];
67
+ }
68
+ }
69
+ }
70
+
71
+ this.propertiesContainer = {
72
+ type: className,
73
+ properties: this.spawneeProperties
74
+ };
75
+
76
+ this.offsetX = this.owner.offsetX || definition.offsetX || 0;
77
+ this.offsetY = this.owner.offsetY || definition.offsetY || 0;
78
+
79
+ this.firing = false;
80
+ },
81
+
82
+ events: {// These are messages that this component listens for
83
+ "handle-logic": function () {
84
+ const
85
+ state = this.state;
86
+
87
+ if (this.firing) {
88
+ let offset = 0;
89
+
90
+ this.spawneeProperties.x = this.owner.x;
91
+ this.spawneeProperties.y = this.owner.y;
92
+ this.spawneeProperties.z = this.owner.z + this.originalZ;
93
+
94
+ offset = this.offsetX;
95
+ if (state.get('left')) {
96
+ offset *= -1;
97
+ }
98
+ this.spawneeProperties.x += offset;
99
+
100
+ offset = this.offsetY;
101
+ if (state.get('top')) {
102
+ offset *= -1;
103
+ }
104
+ this.spawneeProperties.y += offset;
105
+
106
+ if (this.speed) {
107
+ if (state.get('top')) {
108
+ this.spawneeProperties.dy = -this.speed;
109
+ } else if (state.get('bottom')) {
110
+ this.spawneeProperties.dy = this.speed;
111
+ } else {
112
+ delete this.spawneeProperties.dy;
113
+ }
114
+ if (state.get('left')) {
115
+ this.spawneeProperties.dx = -this.speed;
116
+ } else if (state.get('right')) {
117
+ this.spawneeProperties.dx = this.speed;
118
+ } else {
119
+ delete this.spawneeProperties.dx;
120
+ }
121
+ } else {
122
+ delete this.spawneeProperties.dx;
123
+ delete this.spawneeProperties.dy;
124
+ }
125
+
126
+ this.parent.addEntity(this.propertiesContainer);
127
+ }
128
+
129
+ state.set(this.stateName, this.firing);
130
+
131
+ this.firing = false;
132
+ },
133
+ "spawn": function (value) {
134
+ this.firing = !value || (value.pressed !== false);
135
+
136
+ this.parent = this.owner.parent; //proofing against this entity being destroyed prior to spawned entity. For example, when a destroyed entity spawns a drop.
137
+ }
138
+ },
139
+
140
+ methods: {
141
+ destroy: function () {
142
+ this.state = null;
143
+ }
144
+ },
145
+
146
+ getAssetList: function (def, props, defaultProps) {
147
+ const
148
+ spawn = def?.spawneeClass ?? props?.spawneeClass ?? defaultProps?.spawneeClass;
149
+
150
+ if (spawn) {
151
+ return Entity.getAssetList({
152
+ type: spawn
153
+ });
154
+ }
155
+
156
+ return arrayCache.setUp();
157
+ }
158
+ });
159
+ }());