@makefully/platypus 4.1.4 → 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 (134) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +4 -2
  3. package/lib/platypus.js +1 -1
  4. package/package.json +7 -2
  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
@@ -0,0 +1,161 @@
1
+ /* global platypus */
2
+ import Vector from '../Vector.js';
3
+ import createComponentClass from '../factory.js';
4
+
5
+ export default (function () {
6
+ return createComponentClass(/** @lends platypus.components.AIChaser.prototype */{
7
+
8
+ id: 'AIChaser',
9
+
10
+ properties: {
11
+ /**
12
+ * Sets whether the speed property should enact acceleration upon the entity rather than velocity.
13
+ *
14
+ * @property accelerate
15
+ * @type boolean
16
+ * @default false
17
+ */
18
+ accelerate: false,
19
+
20
+ /**
21
+ * Whether the entity is in a chasing state.
22
+ *
23
+ * @property chasing
24
+ * @type boolean
25
+ * @default true
26
+ */
27
+ chasing: true
28
+ },
29
+
30
+ publicProperties: {
31
+ /**
32
+ * Sets the velocity of the entity. This property is accessible on the entity as `entity.speed`.
33
+ *
34
+ * @property speed
35
+ * @type number
36
+ * @default 0.3
37
+ */
38
+ speed: 0.3
39
+ },
40
+
41
+ /**
42
+ * This component acts as a simple AI that will chase another entity.
43
+ *
44
+ * @memberof platypus.components
45
+ * @uses platypus.Component
46
+ * @constructs
47
+ * @listens platypus.Entity#load
48
+ * @fires platypus.Entity#chase
49
+ * @listens platypus.Entity#handle-ai
50
+ * @listens platypus.Entity#set-target
51
+ * @listens platypus.Entity#set-target-offset
52
+ * @listens platypus.Entity#start-chasing
53
+ * @listens platypus.Entity#stop-chasing
54
+ */
55
+ initialize: function () {
56
+ this.target = this.owner.target || null;
57
+ this.offset = Vector.setUp(0, 0);
58
+ this.state = this.owner.state;
59
+ this.state.set('chasing', false);
60
+ },
61
+
62
+ events: {
63
+ "load": function () {
64
+ if (!this.owner.addMover) {
65
+ platypus.debug.warn('The "AIChaser" component requires a "Mover" component to function correctly.');
66
+ return;
67
+ }
68
+
69
+ this.direction = this.owner.addMover({
70
+ vector: [this.speed, 0, 0],
71
+ event: "chase",
72
+ accelerator: this.accelerate
73
+ }).vector;
74
+ },
75
+
76
+ "handle-ai": function () {
77
+ let c = false;
78
+
79
+ if (this.target && this.chasing) {
80
+ const
81
+ v = Vector.setUp(this.offset).add(this.target.position).subtractVector(this.owner.position),
82
+ m = v.magnitude(2);
83
+
84
+ if (m) {
85
+ c = true;
86
+ this.direction.setVector(v).normalize().multiply(this.speed);
87
+ }
88
+
89
+ v.recycle();
90
+ }
91
+
92
+ if (c !== this.state.get('chasing')) {
93
+ this.state.set('chasing', c);
94
+
95
+ /**
96
+ * This event is triggered whenever the entity begins chasing another entity or stops chasing another entity.
97
+ *
98
+ * @event platypus.Entity#chase
99
+ * @param chasing {boolean} Whether the entity is chasing another entity.
100
+ */
101
+ this.owner.triggerEvent('chase', c);
102
+ }
103
+ },
104
+
105
+ /**
106
+ * On receiving this message, the component will change its target and begin chasing the new entity.
107
+ *
108
+ * @event platypus.Entity#set-target
109
+ * @param entity {platypus.Entity} Sets this entity's target to the provided entity.
110
+ */
111
+ "set-target": function (entity) {
112
+ this.target = entity;
113
+ this.offset.x = 0;
114
+ this.offset.y = 0;
115
+ },
116
+
117
+ /**
118
+ * On receiving this message, the component will change its target offset.
119
+ *
120
+ * @event platypus.Entity#set-target-offset
121
+ * @param offset {Object|Vector} Sets the chased entity's offset to the provided offset.
122
+ * @param offset.x {number} The offset along the x-axis.
123
+ * @param offset.y {number} The offset along the y-axis.
124
+ */
125
+ "set-target-offset": function (offset) {
126
+ this.offset.x = offset.x;
127
+ this.offset.y = offset.y;
128
+ },
129
+
130
+ /**
131
+ * On receiving this message, the component will begin chasing the entity.
132
+ *
133
+ * @event platypus.Entity#start-chasing
134
+ * @param [entity] {platypus.Entity} Sets the entity if it's provided.
135
+ */
136
+ "start-chasing": function (entity) {
137
+ if (entity) {
138
+ this.target = entity;
139
+ }
140
+ this.chasing = true;
141
+ },
142
+
143
+ /**
144
+ * On receiving this message, the component will cease chasing the entity.
145
+ *
146
+ * @event platypus.Entity#stop-chasing
147
+ */
148
+ "stop-chasing": function () {
149
+ this.chasing = false;
150
+ }
151
+ },
152
+
153
+ methods: {// These are methods that are called on the component
154
+ destroy: function () {
155
+ this.target = null;
156
+ this.offset.recycle();
157
+ this.state = null;
158
+ }
159
+ }
160
+ });
161
+ }());
@@ -0,0 +1,107 @@
1
+ import createComponentClass from '../factory.js';
2
+
3
+ export default (function () {
4
+ return createComponentClass(/** @lends platypus.components.AIPacer.prototype */{
5
+ id: "AIPacer",
6
+
7
+ properties: {
8
+ /**
9
+ * This determines the direction of movement. Can be "horizontal", "vertical", or "both".
10
+ *
11
+ * @property movement
12
+ * @type String
13
+ * @default "both"
14
+ */
15
+ movement: 'both',
16
+
17
+ /**
18
+ * This sets the initial direction of movement. Defaults to "up", or "left" if movement is horizontal.
19
+ *
20
+ * @property direction
21
+ * @type String
22
+ * @default "up"
23
+ */
24
+ direction: null
25
+ },
26
+
27
+ /**
28
+ * This component acts as a simple AI that will reverse the movement direction of an object when it collides with something.
29
+ *
30
+ * @memberof platypus.components
31
+ * @uses platypus.Component
32
+ * @constructs
33
+ * @listens platypus.Entity#handle-ai
34
+ * @listens platypus.Entity#turn-around
35
+ * @fires platypus.Entity#stop
36
+ * @fires platypus.Entity#go-left
37
+ * @fires platypus.Entity#go-right
38
+ * @fires platypus.Entity#go-down
39
+ * @fires platypus.Entity#go-up
40
+ */
41
+ initialize: function () {
42
+ this.lastDirection = '';
43
+ this.currentDirection = this.direction || ((this.movement === 'horizontal') ? 'left' : 'up');
44
+ },
45
+
46
+ events: {
47
+ "handle-ai": function () {
48
+ if (this.currentDirection !== this.lastDirection) {
49
+ this.lastDirection = this.currentDirection;
50
+
51
+ /**
52
+ * Stops motion in all directions until movement messages are again received.
53
+ *
54
+ * @event platypus.Entity#stop
55
+ * @param {boolean} [message.pressed] If `message` is included, the component checks the value of `pressed`: a value of false will not stop the entity.
56
+ */
57
+ this.owner.triggerEvent('stop');
58
+
59
+ /**
60
+ * Triggers this event when the entity is moving right and collides with something.
61
+ *
62
+ * @event platypus.Entity#go-left
63
+ */
64
+ /**
65
+ * Triggers this event when the entity is moving left and collides with something.
66
+ *
67
+ * @event platypus.Entity#go-right
68
+ */
69
+ /**
70
+ * Triggers this event when the entity is moving up and collides with something.
71
+ *
72
+ * @event platypus.Entity#go-down
73
+ */
74
+ /**
75
+ * Triggers this event when the entity is moving down and collides with something.
76
+ *
77
+ * @event platypus.Entity#go-up
78
+ */
79
+ this.owner.triggerEvent('go-' + this.currentDirection);
80
+ }
81
+ },
82
+
83
+ /**
84
+ * On receiving this message, the component will check the collision side and re-orient itself accordingly.
85
+ *
86
+ * @event platypus.Entity#turn-around
87
+ * @param collisionInfo {platypus.CollisionData} Uses direction of collision to determine whether to turn around.
88
+ */
89
+ "turn-around": function (collisionInfo) {
90
+ if ((this.movement === 'both') || (this.movement === 'horizontal')) {
91
+ if (collisionInfo.x > 0) {
92
+ this.currentDirection = 'left';
93
+ } else if (collisionInfo.x < 0) {
94
+ this.currentDirection = 'right';
95
+ }
96
+ }
97
+ if ((this.movement === 'both') || (this.movement === 'vertical')) {
98
+ if (collisionInfo.y > 0) {
99
+ this.currentDirection = 'up';
100
+ } else if (collisionInfo.y < 0) {
101
+ this.currentDirection = 'down';
102
+ }
103
+ }
104
+ }
105
+ }
106
+ });
107
+ }());
@@ -0,0 +1,151 @@
1
+ /**
2
+ * This component plays music or background ambiance.
3
+ *
4
+ * @memberof platypus.components
5
+ * @class AudioMusic
6
+ * @uses platypus.Component
7
+ */
8
+ /* global platypus */
9
+ import {arrayCache, greenSplice} from '../utils/array.js';
10
+ import createComponentClass from '../factory.js';
11
+
12
+ const
13
+ formatPath = (path) => {
14
+ if (path.indexOf('.mp3') === -1) {
15
+ return `${path}.mp3`;
16
+ } else {
17
+ return path;
18
+ }
19
+ },
20
+ activeTracks = {}; // List of actively-playing tracks.
21
+
22
+ export default createComponentClass(/** @lends platypus.components.AudioMusic.prototype */{
23
+ id: 'AudioMusic',
24
+
25
+ properties: {
26
+ /**
27
+ * Use the tracks property object to handle playing tracks or new tracks to load. Here is an example audioMap object:
28
+ * {
29
+ * "audio-1": "audio-id",
30
+ *
31
+ * "audio-2": {
32
+ * "sound": "another-audio-id",
33
+ * // Required. This is the audio clip to loop.
34
+ *
35
+ * "volume": 0.75,
36
+ * // Optional. Used to specify how loud to play audio on a range from 0 (mute) to 1 (full volume). Default is 1.
37
+ *
38
+ * "fade": 1000,
39
+ * // Optional. How long to fade to selected volume.
40
+ *
41
+ * "autoStart": true
42
+ * // Optional. Whether the music should play as soon as the component loads.
43
+ * }
44
+ * }
45
+ *
46
+ * Any tracks already playing and not defined here will fade out.
47
+ *
48
+ * @property tracks
49
+ * @type Object
50
+ * @default null
51
+ */
52
+ tracks: null,
53
+
54
+ /**
55
+ * The default fade for music track volume changes.
56
+ *
57
+ * @property fade
58
+ * @type number
59
+ * @default 1000
60
+ */
61
+ fade: 1000
62
+ },
63
+
64
+ initialize: function () {
65
+ this.player = platypus.game.musicPlayer;
66
+ this.changeMusicTracks(this.tracks);
67
+ },
68
+
69
+ events: {
70
+ 'change-music-tracks': function (tracks) {
71
+ this.changeMusicTracks(tracks);
72
+ }
73
+ },
74
+
75
+ methods: {
76
+ changeMusicTracks (tracks) {
77
+ const
78
+ {player} = this,
79
+ fadeOuts = Object.keys(activeTracks),
80
+ {fade} = this;
81
+
82
+ if (tracks) {
83
+ const
84
+ keys = Object.keys(tracks),
85
+ {length} = keys;
86
+
87
+ for (let j = 0; j < length; j++) {
88
+ const
89
+ key = keys[j],
90
+ fadeOut = fadeOuts.indexOf(key),
91
+ trackProperties = tracks[key];
92
+
93
+ if (trackProperties.autoStart !== false) {
94
+ let sound = activeTracks[key],
95
+ trackFade = trackProperties.fade ?? fade;
96
+
97
+ if (fadeOut >= 0) {
98
+ greenSplice(fadeOuts, fadeOut);
99
+ } else { // gotta load it because it's not there!
100
+ sound = activeTracks[key] = this.player.play(trackProperties.sound || trackProperties, {
101
+ loop: Infinity,
102
+ volume: trackFade ? 0 : (typeof trackProperties.volume === 'number' ? trackProperties.volume : 1)
103
+ });
104
+ }
105
+
106
+ if (trackFade) {
107
+
108
+ player.fade(sound, typeof trackProperties.volume === 'number' ? trackProperties.volume : 1, trackFade)
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ fadeOuts.forEach((value) => {
115
+ const
116
+ sound = activeTracks[value];
117
+
118
+ player.fade(sound, 0, fade, () => {
119
+ player.stop(sound);
120
+ //sound.unload();
121
+ });
122
+
123
+ delete activeTracks[value];
124
+ });
125
+ }
126
+ },
127
+
128
+ getAssetList: function (component, props, defaultProps) {
129
+ const
130
+ preload = arrayCache.setUp(),
131
+ tracks = component?.tracks ?? props?.tracks ?? defaultProps?.tracks;
132
+
133
+ if (tracks) {
134
+ const
135
+ keys = Object.keys(tracks),
136
+ {length} = keys;
137
+
138
+ for (let i = 0; i < length; i++) {
139
+ const
140
+ track = tracks[keys[i]],
141
+ item = formatPath(track.sound ?? track);
142
+
143
+ if (preload.indexOf(item) === -1) {
144
+ preload.push(item);
145
+ }
146
+ }
147
+ }
148
+
149
+ return preload;
150
+ }
151
+ });