@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,173 @@
1
+ /* global platypus */
2
+ import {arrayCache, union} from '../utils/array.js';
3
+ import createComponentClass from '../factory.js';
4
+
5
+ export default createComponentClass(/** @lends platypus.components.ComponentSwitcher.prototype */{
6
+ id: 'ComponentSwitcher',
7
+
8
+ properties: {
9
+ /**
10
+ * This is the list of messages to listen for (as the keys) with the settings as two arrays of components to add and components to remove.
11
+ *
12
+ {
13
+ "found-pogostick":{
14
+ "add":[
15
+ // This is a list of components to add when "found-pogostick" is triggered on the entity. If it's adding a single component, "add" can be a reference to the component definition itself rather than an array of one object.
16
+ {"type": "Mover"},
17
+ {"type": "HeadGear"}
18
+ ]
19
+
20
+ "remove": ["CarSeat"]
21
+ // This is a string list of component ids to remove when "found-pogostick" is triggered on the entity. It will ignore listed components that are not connected to the entity.
22
+ },
23
+
24
+ // Multiple events can cause unique components to be added or removed
25
+ "walking-indoors":{
26
+ "remove": ["HeadGear"]
27
+ },
28
+
29
+ "contemplate":{
30
+ "add": {"type": "AIPacer"}
31
+ }
32
+ }
33
+ }
34
+ *
35
+ * @property componentMap
36
+ * @type Object
37
+ * @default null
38
+ */
39
+ componentMap: null
40
+ },
41
+
42
+ /**
43
+ * This component listens for messages and, according to its preset settings, will remove and add components to the entity. This is useful if certain events should modify the behavior of the entity in some way: for example, acquiring a pogo-stick might add a jumping component so the hero can jump.
44
+ *
45
+ * @memberof platypus.components
46
+ * @uses platypus.Component
47
+ * @constructs
48
+ * @listens platypus.Entity#prepare-logic
49
+ * @fires platypus.Entity#child-entity-updated
50
+ * @fires platypus.Entity#add-remove-component-complete
51
+ */
52
+ initialize: function () {
53
+ const
54
+ {componentMap} = this,
55
+ switches = this.switches = arrayCache.setUp(); // The list of switches to make.
56
+
57
+ if (componentMap) {
58
+ const
59
+ keys = Object.keys(componentMap),
60
+ {length} = keys;
61
+
62
+ for (let i = 0; i < length; i++) {
63
+ const
64
+ key = keys[i];
65
+
66
+ // Message(s) listed by `componentMap` will add or remove components.
67
+ this.addEventListener(key, (event) => {
68
+ switches.push(event);
69
+ });
70
+ }
71
+ }
72
+ },
73
+
74
+ events: {
75
+ "prepare-logic": function () {
76
+ if (this.switches.length) {
77
+ for (let i = 0; i < this.switches.length; i++) {
78
+ this.switchComponents(this.componentMap[this.switches[i]]);
79
+ }
80
+ this.switches.length = 0;
81
+ }
82
+ }
83
+ },
84
+
85
+ methods: {
86
+ switchComponents: function (definition) {
87
+ const
88
+ owner = this.owner,
89
+ components = owner.components,
90
+ remove = definition.remove,
91
+ add = definition.add;
92
+
93
+ if (remove) {
94
+ if (!Array.isArray(remove)) {
95
+ for (let i = components.length - 1; i > -1; i--) {
96
+ if (components[i].type === remove) {
97
+ owner.removeComponent(components[i]);
98
+ }
99
+ }
100
+ } else {
101
+ for (let i = 0; i < remove.length; i++) {
102
+ for (let j = components.length - 1; j > -1; j--) {
103
+ if (components[j].type === remove[i]) {
104
+ owner.removeComponent(components[j]);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ if (add) {
112
+ if (!Array.isArray(add)) {
113
+ owner.addComponent(new platypus.components[add.type](owner, add));
114
+ } else {
115
+ for (let i = 0; i < add.length; i++) {
116
+ owner.addComponent(new platypus.components[add[i].type](owner, add[i]));
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * This message is triggered on the parent when the entity's components change.
123
+ *
124
+ * @event platypus.Entity#child-entity-updated
125
+ * @param entity {platypus.Entity} This is the entity itself.
126
+ */
127
+ owner.parent.triggerEvent('child-entity-updated', owner);
128
+
129
+ /**
130
+ * This message is triggered on the entity itself when its components change.
131
+ *
132
+ * @event platypus.Entity#add-remove-component-complete
133
+ */
134
+ owner.triggerEvent('add-remove-component-complete');
135
+ },
136
+
137
+ destroy: function () {
138
+ arrayCache.recycle(this.switches);
139
+ }
140
+ },
141
+
142
+ getAssetList: function (def, props, defaultProps) {
143
+ const
144
+ componentMap = def?.componentMap ?? props?.componentMap ?? defaultProps?.componentMap,
145
+ assets = arrayCache.setUp();
146
+
147
+ if (componentMap) {
148
+ const
149
+ keys = Object.keys(componentMap),
150
+ {length} = keys;
151
+
152
+ for (let i = 0; i < length; i++) {
153
+ const
154
+ adds = map[keys[i]].add;
155
+
156
+ for (let j = 0; j < adds.length; j++) {
157
+ const
158
+ component = platypus.components[adds[j].type];
159
+
160
+ if (component) {
161
+ const
162
+ arr = component.getAssetList(adds[j], props, defaultProps);
163
+
164
+ union(assets, arr);
165
+ arrayCache.recycle(arr);
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ return assets;
172
+ }
173
+ });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Maps pointer presses on this entity to game-wide controller events consumed by {@link platypus.components.HandlerController}.
3
+ * Add {@link platypus.components.Interactive} (or another source of pointer events) on the same entity so presses hit the control.
4
+ *
5
+ * @memberof platypus.components
6
+ * @class ControllerInput
7
+ * @uses platypus.Component
8
+ */
9
+ /* global platypus */
10
+ import createComponentClass from '../factory.js';
11
+
12
+ export default createComponentClass(/** @lends platypus.components.ControllerInput.prototype */{
13
+ id: 'ControllerInput',
14
+
15
+ properties: {
16
+ /**
17
+ * Control code passed to `HandlerController` (for example `jump` or `menu-select`).
18
+ * Defaults to the entity's `type` when unset.
19
+ *
20
+ * @property code
21
+ * @type String
22
+ * @default null
23
+ */
24
+ code: null,
25
+
26
+ /**
27
+ * Input device style. Only `button` is supported: `pointerdown` / `pointerup` (and cancel/outside) map to controller down/up.
28
+ *
29
+ * @property controllerType
30
+ * @type String
31
+ * @default button
32
+ */
33
+ controllerType: 'button'
34
+ },
35
+
36
+ initialize () {
37
+ const
38
+ {code, controllerType, owner: entity} = this,
39
+ onUp = () => platypus.game.triggerOnChildren('controller-input-up', {
40
+ code: code ?? entity.type,
41
+ entity
42
+ }),
43
+ onDown = () => platypus.game.triggerOnChildren('controller-input-down', {
44
+ code: code ?? entity.type,
45
+ entity
46
+ });
47
+
48
+ switch (controllerType) {
49
+ default: {
50
+ const
51
+ down = this.addEventListener('pointerdown', onDown),
52
+ up = this.addEventListener('pointerup', onUp),
53
+ upOutside = this.addEventListener('pointerupoutside', onUp),
54
+ cancel = this.addEventListener('pointercancel', onUp);
55
+
56
+ this.unattachControls = () => {
57
+ this.removeEventListener('pointerdown', down);
58
+ this.removeEventListener('pointerup', up);
59
+ this.removeEventListener('pointerupoutside', upOutside);
60
+ this.removeEventListener('pointercancel', cancel);
61
+ };
62
+ }
63
+ }
64
+ }
65
+ });
@@ -0,0 +1,165 @@
1
+ import Data from '../Data.js';
2
+ import createComponentClass from '../factory.js';
3
+
4
+ /* global platypus */
5
+ export default (function () {
6
+ return createComponentClass(/** @lends platypus.components.Counter.prototype */{
7
+
8
+ id: 'Counter',
9
+
10
+ properties: {
11
+ /**
12
+ * Sets whether count is stored permanently. Can be set to a storage key or if `true` will use entity's type.
13
+ *
14
+ * @property persistentStorage
15
+ * @type Boolean|String
16
+ * @default false
17
+ */
18
+ persistentStorage: false
19
+ },
20
+
21
+ publicProperties: {
22
+ /**
23
+ * Specifies the current count.
24
+ *
25
+ * @property count
26
+ * @type number
27
+ * @default 0
28
+ */
29
+ count: 0,
30
+
31
+ /**
32
+ * If total is supplied, progress reports part complete, 0-1.
33
+ *
34
+ * @property progress
35
+ * @type number
36
+ * @default 0
37
+ */
38
+ progress: 0,
39
+
40
+ /**
41
+ * A total the counter is incrementing toward.
42
+ *
43
+ * @property total
44
+ * @type number
45
+ * @default 0
46
+ */
47
+ total: 0
48
+ },
49
+
50
+ /**
51
+ * A simple component that keeps count of something and sends messages each time the count changes. Can also have a total. When it does it will display 'count / total'.
52
+ *
53
+ * @memberof platypus.components
54
+ * @uses platypus.Component
55
+ * @constructs
56
+ * @listens platypus.Entity#change-total
57
+ * @listens platypus.Entity#change-count
58
+ * @listens platypus.Entity#handle-logic
59
+ * @listens platypus.Entity#increment-count
60
+ * @fires platypus.Entity#update-content
61
+ */
62
+ initialize: function () {
63
+ this.lastTotal = -1;
64
+ this.lastCount = -1;
65
+ this.message = Data.setUp(
66
+ "text", ""
67
+ );
68
+ if (this.persistentStorage) {
69
+ const
70
+ storage = this.storage = platypus.game.storage;
71
+
72
+ if (this.persistentStorage === true) {
73
+ this.persistentStorage = this.owner.type;
74
+ }
75
+
76
+ this.count = storage.get(this.persistentStorage) || 0;
77
+ }
78
+ },
79
+
80
+ events: {
81
+ "handle-logic": function () {
82
+ const
83
+ msg = this.message;
84
+ let update = false;
85
+
86
+ if (this.total !== this.lastTotal) {
87
+ this.lastTotal = this.total;
88
+ update = true;
89
+ }
90
+
91
+ if (this.count !== this.lastCount) {
92
+ this.lastCount = this.count;
93
+ if (this.persistentStorage) {
94
+ this.storage.set(this.persistentStorage, this.count);
95
+ }
96
+ update = true;
97
+ }
98
+
99
+ if (update) {
100
+ if (this.total) {
101
+ msg.text = String(this.count) + "/" + String(this.total);
102
+ } else {
103
+ msg.text = String(this.count);
104
+ }
105
+
106
+ /**
107
+ * A call used to notify other components that the count or total has changed.
108
+ *
109
+ * @event platypus.Entity#update-content
110
+ * @param update.text {string} String describing the current count.
111
+ */
112
+ this.owner.triggerEvent('update-content', msg);
113
+
114
+ if (this.total) {
115
+ this.progress = this.count / this.total;
116
+ }
117
+ }
118
+ },
119
+
120
+ /**
121
+ * Changes the total to the given value.
122
+ *
123
+ * @event platypus.Entity#change-total
124
+ * @param data.total {number} The new total value.
125
+ */
126
+ "change-total": function (total) {
127
+ this.total = total;
128
+ },
129
+
130
+ /**
131
+ * Changes the count to the given value.
132
+ *
133
+ * @event platypus.Entity#change-count
134
+ * @param data.count {number} The new count value.
135
+ */
136
+ "change-count": function (count) {
137
+ this.count = count;
138
+ },
139
+
140
+ /**
141
+ * Increments the count by 1.
142
+ *
143
+ * @event platypus.Entity#increment-count
144
+ */
145
+ "increment-count": function () {
146
+ this.count += 1;
147
+ },
148
+
149
+ /**
150
+ * Decrements the count by 1.
151
+ *
152
+ * @event platypus.Entity#decrement-count
153
+ */
154
+ "decrement-count": function () {
155
+ this.count -= 1;
156
+ }
157
+ },
158
+
159
+ methods: {
160
+ destroy: function () {
161
+ this.message.recycle();
162
+ }
163
+ }
164
+ });
165
+ }());
@@ -0,0 +1,215 @@
1
+ import AABB from '../AABB.js';
2
+ import Data from '../Data.js';
3
+ import createComponentClass from '../factory.js';
4
+ import Vector from '../Vector.js';
5
+
6
+ const
7
+ DEFAULT_SIZE = 100;
8
+
9
+ export default (function () {
10
+ return createComponentClass(/** @lends platypus.components.CameraFollowMe.prototype */{
11
+ id: 'EntityCamera',
12
+
13
+ properties: {
14
+ /**
15
+ * Sets initial camera settings when the entity is being followed. This can be over-written by the "follow-me" call itself. If any of these attributes are not provided, the following are used by default:
16
+ *
17
+ {
18
+ "time": 500,
19
+ // Optional. Time in milliseconds that the camera should focus before returning to the original focus.
20
+
21
+ "mode": "forward",
22
+ // Optional. Camera mode that the camera should use.
23
+
24
+ "top": 100,
25
+ // Optional number specifying top of viewport in world coordinates
26
+
27
+ "left": 100,
28
+ // Optional number specifying left of viewport in world coordinates
29
+
30
+ "width": 100,
31
+ // Optional number specifying width of viewport in world coordinates
32
+
33
+ "height": 100,
34
+ // Optional number specifying height of viewport in world coordinates
35
+
36
+ "offsetX": 20,
37
+ // Optional number setting how far to offset the camera from the entity horizontally.
38
+
39
+ "offsetY": 40
40
+ // Optional number setting how far to offset the camera from the entity vertically.
41
+ }
42
+ *
43
+ * @property camera
44
+ * @type Object
45
+ * @default {}
46
+ */
47
+ camera: {},
48
+
49
+ /**
50
+ * Camera mode that the camera should use.
51
+ *
52
+ * @property mode
53
+ * @type String
54
+ * @default "forward"
55
+ */
56
+ mode: "forward",
57
+
58
+ /**
59
+ * Whether to pause the game while the camera is focused.
60
+ *
61
+ * @property pause
62
+ * @type boolean
63
+ * @default false
64
+ */
65
+ pause: false
66
+ },
67
+
68
+ publicProperties: {
69
+ cameraBounds: null,
70
+ cameraFocus: 1,
71
+ cameraOffset: null,
72
+ cameraOffsetX: 0,
73
+ cameraOffsetY: 0,
74
+ cameraSize: null,
75
+ cameraWidth: 0,
76
+ cameraHeight: 0,
77
+ x: 0,
78
+ y: 0
79
+ },
80
+
81
+ /**
82
+ * This component can request that the camera focus on this entity.
83
+ *
84
+ * @memberof platypus.components
85
+ * @uses platypus.Component
86
+ * @constructs
87
+ * @listens platypus.Entity#follow-me
88
+ * @fires platypus.Entity#follow
89
+ * @fires platypus.Entity#pause-logic
90
+ * @fires platypus.Entity#pause-render
91
+ */
92
+ initialize: function () {
93
+ const
94
+ {cameraOffsetX, cameraOffsetY, cameraHeight, cameraWidth, x, y} = this;
95
+
96
+ this.pauseGame = (this.pause && this.camera.time) ? {
97
+ time: this.camera.time
98
+ } : null;
99
+
100
+ Vector.assign(this.owner, 'cameraOffset', 'cameraOffsetX', 'cameraOffsetY');
101
+ Vector.assign(this.owner, 'cameraSize', 'cameraWidth', 'cameraHeight');
102
+ this.cameraBounds = AABB.setUp(x + cameraOffsetX, y + cameraOffsetY, cameraWidth, cameraHeight);
103
+
104
+ if (!this.cameraWidth) {
105
+ this.cameraWidth = this.owner.width || DEFAULT_SIZE;
106
+ }
107
+ if (!this.cameraHeight) {
108
+ this.cameraHeight = this.owner.height || DEFAULT_SIZE;
109
+ }
110
+
111
+ this.camera = Data.setUp(
112
+ "entity", this.owner,
113
+ "mode", this.camera.mode || this.mode,
114
+ "top", this.camera.top,
115
+ "left", this.camera.left,
116
+ "offsetX", this.camera.offsetX,
117
+ "offsetY", this.camera.offsetY,
118
+ "width", this.camera.width,
119
+ "height", this.camera.height,
120
+ "time", this.camera.time
121
+ );
122
+ },
123
+
124
+ events: {
125
+ 'handle-movement': function () {
126
+ const
127
+ {cameraBounds, cameraOffsetX, cameraOffsetY, cameraHeight, cameraWidth, x, y} = this;
128
+
129
+ cameraBounds.setAll(x + cameraOffsetX, y + cameraOffsetY, cameraWidth, cameraHeight);
130
+ },
131
+
132
+ /**
133
+ * On receiving this message, the component will trigger a message requesting that the parent camera begin following this entity.
134
+ *
135
+ * @event platypus.Entity#follow-me
136
+ * @param {Object} [options] A list of key/value paris describing camera options to set.
137
+ * @param {String} [options.mode] Camera following mode.
138
+ * @param {number} [options.top] The top of a bounding box.
139
+ * @param {number} [options.left] The left of a bounding box.
140
+ * @param {number} [options.width] The width of a bounding box.
141
+ * @param {number} [options.height] The height of a bounding box.
142
+ * @param {number} [options.offsetX] How far to offset the camera from the entity horizontally.
143
+ * @param {number} [options.offsetY] How far to offset the camera from the entity vertically.
144
+ * @param {number} [options.time] How many milliseconds to follow the entity.
145
+ */
146
+ "follow-me": function (options) {
147
+ let msg = null;
148
+
149
+ if (options) {
150
+ msg = Data.setUp(
151
+ "entity", this.owner,
152
+ "mode", options.mode || this.camera.mode,
153
+ "top", options.top || this.camera.top,
154
+ "left", options.left || this.camera.left,
155
+ "offsetX", options.offsetX || this.camera.offsetX,
156
+ "offsetY", options.offsetY || this.camera.offsetY,
157
+ "width", options.width || this.camera.width,
158
+ "height", options.height || this.camera.height,
159
+ "time", options.time || this.camera.time
160
+ );
161
+ } else {
162
+ msg = Data.setUp(this.camera);
163
+ }
164
+
165
+ if (this.pauseGame) {
166
+
167
+ /**
168
+ * This component fires this message on the parent entity to pause logic if required.
169
+ *
170
+ * @event platypus.Entity#pause-logic
171
+ * @param options {Object}
172
+ * @param options.time {number} The amount of time to pause before re-enabling logic.
173
+ */
174
+ this.owner.parent.triggerEvent('pause-logic', this.pauseGame);
175
+
176
+ /**
177
+ * This component fires this message on the parent entity to pause rendering if required.
178
+ *
179
+ * @event platypus.Entity#pause-render
180
+ * @param options {Object}
181
+ * @param options.time {number} The amount of time to pause before re-enabling render updates.
182
+ */
183
+ this.owner.parent.triggerEvent('pause-render', this.pauseGame);
184
+ }
185
+
186
+ /**
187
+ * This component fires this message on this entity's parent so the camera will begin following this entity.
188
+ *
189
+ * @event platypus.Entity#follow
190
+ * @param {Object} message
191
+ * @param {String} message.mode Can be "locked", "forward", "bounding", "anchor-bound", or "static". "static" suspends following, but the other three settings require that the entity parameter be defined. Also set the bounding area parameters if sending "bounding" as the following method and the movement parameters if sending "forward" as the following method.
192
+ * @param {platypus.Entity} [message.entity] The entity that the camera should commence following.
193
+ * @param {number} [message.top] The top of a bounding box following an entity.
194
+ * @param {number} [message.left] The left of a bounding box following an entity.
195
+ * @param {number} [message.width] The width of a bounding box following an entity.
196
+ * @param {number} [message.height] The height of a bounding box following an entity.
197
+ * @param {number} [message.movementX] Movement multiplier for focusing the camera ahead of a moving entity in the horizontal direction.
198
+ * @param {number} [message.movementY] Movement multiplier for focusing the camera ahead of a moving entity in the vertical direction.
199
+ * @param {number} [message.offsetX] How far to offset the camera from the entity horizontally.
200
+ * @param {number} [message.offsetY] How far to offset the camera from the entity vertically.
201
+ * @param {number} [message.time] How many milliseconds to follow the entity.
202
+ */
203
+ this.owner.parent.triggerEvent('follow', msg);
204
+
205
+ msg.recycle();
206
+ }
207
+ },
208
+
209
+ methods: {
210
+ destroy: function () {
211
+ this.camera.recycle();
212
+ }
213
+ }
214
+ });
215
+ }());