wgge 0.0.1

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 (107) hide show
  1. package/core/ActivatedTreeNode.js +187 -0
  2. package/core/Collection.js +156 -0
  3. package/core/Dictionary.js +83 -0
  4. package/core/animation/3d/AnimatedVector3.js +35 -0
  5. package/core/animation/3d/AnimationHelper.js +103 -0
  6. package/core/animation/3d/ProgressVector3.js +26 -0
  7. package/core/animation/AnimatedRotation.js +44 -0
  8. package/core/animation/AnimatedValue.js +33 -0
  9. package/core/animation/AnimatedVector2.js +35 -0
  10. package/core/animation/ProgressRotation.js +40 -0
  11. package/core/animation/ProgressValue.js +27 -0
  12. package/core/animation/ProgressVector2.js +23 -0
  13. package/core/audio/AudioModel.js +36 -0
  14. package/core/audio/AudioRenderer.js +120 -0
  15. package/core/audio/global/GlobalAudioModel.js +88 -0
  16. package/core/audio/global/GlobalAudioRenderer.js +108 -0
  17. package/core/controller/AnimationController.js +37 -0
  18. package/core/controller/AnimationFloatController.js +39 -0
  19. package/core/controller/AnimationVector2Controller.js +39 -0
  20. package/core/controller/CollectionController.js +47 -0
  21. package/core/controller/ConditionalNodeController.js +51 -0
  22. package/core/controller/ControllerBase.js +64 -0
  23. package/core/controller/ControllerWithSaveGame.js +27 -0
  24. package/core/controller/ControllerWithTimeout.js +10 -0
  25. package/core/controller/NullableNodeController.js +35 -0
  26. package/core/controller/TimeoutController.js +26 -0
  27. package/core/helper/ArrayHelper.js +19 -0
  28. package/core/helper/DOMHelper.js +167 -0
  29. package/core/helper/GUIHelper.js +53 -0
  30. package/core/helper/HttpHelper.js +33 -0
  31. package/core/helper/ImageHelper.js +36 -0
  32. package/core/helper/NumberHelper.js +28 -0
  33. package/core/helper/ObjectHelper.js +10 -0
  34. package/core/helper/StringHelper.js +59 -0
  35. package/core/model/ModelBase.js +91 -0
  36. package/core/model/ObjectModel.js +97 -0
  37. package/core/model/collection/ModelNodeCollection.js +232 -0
  38. package/core/model/collection/table/IdentifiedModelNode.js +24 -0
  39. package/core/model/collection/table/ModelNodeTable.js +53 -0
  40. package/core/model/event/ChangeEvent.js +24 -0
  41. package/core/model/event/EventManager.js +44 -0
  42. package/core/model/event/NodeWithEvents.js +32 -0
  43. package/core/model/template/TemplateNode.js +45 -0
  44. package/core/model/value/BoolValue.js +17 -0
  45. package/core/model/value/CapacityValue.js +49 -0
  46. package/core/model/value/DirtyValue.js +66 -0
  47. package/core/model/value/FloatValue.js +8 -0
  48. package/core/model/value/IntValue.js +20 -0
  49. package/core/model/value/NullableNode.js +66 -0
  50. package/core/model/value/StringValue.js +21 -0
  51. package/core/model/vector/Quaternion.js +82 -0
  52. package/core/model/vector/Rotation.js +61 -0
  53. package/core/model/vector/Vector2.js +177 -0
  54. package/core/model/vector/Vector3.js +98 -0
  55. package/core/renderer/RendererBase.js +46 -0
  56. package/core/renderer/canvas/CanvasRenderer.js +60 -0
  57. package/core/renderer/canvas/ImageToCanvasRenderer.js +94 -0
  58. package/core/renderer/dom/DirtyValueRenderer.js +36 -0
  59. package/core/renderer/dom/DomRenderer.js +32 -0
  60. package/core/renderer/dom/ImageRenderer.js +41 -0
  61. package/core/renderer/dom/Vector2Renderer.js +37 -0
  62. package/core/renderer/generic/CollectionRenderer.js +50 -0
  63. package/core/renderer/generic/ConditionalNodeRenderer.js +57 -0
  64. package/core/renderer/generic/NullableNodeRenderer.js +43 -0
  65. package/core/renderer/svg/SvgRenderer.js +130 -0
  66. package/editor/EditorController.js +135 -0
  67. package/editor/EditorModel.js +38 -0
  68. package/editor/EditorRenderer.js +116 -0
  69. package/editor/form/NodeFormRenderer.js +180 -0
  70. package/editor/material/MaterialPreviewRenderer.js +136 -0
  71. package/editor/table/TableRenderer.js +123 -0
  72. package/editor/table/lookup/TableLookupRenderer.js +120 -0
  73. package/editor/table/row/TableRowRenderer.js +97 -0
  74. package/game/GameController.js +144 -0
  75. package/game/GameModel.js +73 -0
  76. package/game/GameRenderer.js +108 -0
  77. package/game/controls/ControlsController.js +104 -0
  78. package/game/controls/ControlsModel.js +60 -0
  79. package/game/menu/MenuModel.js +25 -0
  80. package/game/menu/MenuRenderer.js +37 -0
  81. package/game/menu/item/MenuItemModel.js +31 -0
  82. package/game/menu/item/MenuItemRenderer.js +40 -0
  83. package/game/resources/3d/3DModel.js +30 -0
  84. package/game/resources/ResourcesModel.js +26 -0
  85. package/game/resources/assets/AssetCache.js +193 -0
  86. package/game/resources/assets/loader/AssetLoader.js +56 -0
  87. package/game/resources/assets/loader/AudioLoader.js +15 -0
  88. package/game/resources/assets/loader/GlbLoader.js +16 -0
  89. package/game/resources/assets/loader/ImageLoader.js +15 -0
  90. package/game/resources/assets/loader/MaterialLoader.js +49 -0
  91. package/game/resources/assets/loader/Model3dLoader.js +21 -0
  92. package/game/resources/assets/loader/SpriteLoader.js +40 -0
  93. package/game/resources/image/DualImageModel.js +34 -0
  94. package/game/resources/image/ImageModel.js +43 -0
  95. package/game/resources/material/MaterialModel.js +69 -0
  96. package/game/save/SaveGameController.js +21 -0
  97. package/game/save/SaveGameModel.js +5 -0
  98. package/game/save/SaveGameRenderer.js +17 -0
  99. package/game/save/editor/SaveGameEditorRenderer.js +17 -0
  100. package/index.html +42 -0
  101. package/index.js +73 -0
  102. package/package.json +35 -0
  103. package/style/basic/editor.less +290 -0
  104. package/style/basic/game.less +149 -0
  105. package/style/basic/utilities.less +215 -0
  106. package/style/style.less +3 -0
  107. package/webpack.config.js +29 -0
@@ -0,0 +1,187 @@
1
+ import NumberHelper from "./helper/NumberHelper";
2
+
3
+ export default class ActivatedTreeNode {
4
+
5
+ /**
6
+ * @type ActivatedTreeNode[]
7
+ */
8
+ children;
9
+
10
+ /**
11
+ * @type ActivatedTreeNode
12
+ */
13
+ parent;
14
+
15
+ /**
16
+ * @type boolean
17
+ */
18
+ isActivated;
19
+
20
+ /**
21
+ *
22
+ * @type {[{param}]}
23
+ * @type param.node {ModelNode}
24
+ * @type param.event {string}
25
+ * @type param.handler {(ep) => any}
26
+ */
27
+ autoRegisterEvents = null;
28
+
29
+ constructor() {
30
+ this.isActivated = false;
31
+ this.parent = null;
32
+ this.children = [];
33
+ }
34
+
35
+ isRoot() {
36
+ return (this.parent === null);
37
+ }
38
+
39
+ findRoot() {
40
+ return (this.isRoot()) ? this : this.parent.findRoot();
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param node ActivatedTreeNode
46
+ * @returns ActivatedTreeNode
47
+ */
48
+ addChild(node) {
49
+ node.parent = this;
50
+ this.children.push(node);
51
+ if (this.isActivated) {
52
+ node.activate();
53
+ }
54
+ return node;
55
+ }
56
+
57
+ hasChildren() {
58
+ return this.children.length > 0;
59
+ }
60
+
61
+ removeChild(node) {
62
+ const index = this.children.indexOf(node);
63
+ if (index >= 0) {
64
+ this.children.splice(index, 1);
65
+ node.deactivate();
66
+ node.parent = null;
67
+ return node;
68
+ }
69
+ for (let i = 0, max = this.children.length; i < max; i++) {
70
+ const child = this.children[i];
71
+ const result = child.removeChild(node);
72
+ if (result) {
73
+ return result;
74
+ }
75
+ }
76
+ }
77
+
78
+ removeMyself() {
79
+ if (this.parent) {
80
+ this.parent.removeChild(this);
81
+ } else {
82
+ this.deactivate();
83
+ }
84
+ }
85
+
86
+ resetChildren() {
87
+ this.children.forEach((child) => child.deactivate());
88
+ this.children = [];
89
+ }
90
+
91
+ forEach(func) {
92
+ func(this);
93
+ for (let i = 0, max = this.children.length; i < max; i++) {
94
+ const child = this.children[i];
95
+ child.forEach(func);
96
+ }
97
+ }
98
+
99
+ activate() {
100
+ if (!this.isActivated) {
101
+ this.activateInternal();
102
+
103
+ if (this.autoRegisterEvents) {
104
+ this.autoRegisterEvents.forEach((event) => {
105
+ event.node.addEventListener(event.name, event.handler);
106
+ if (event.runOnActivate) {
107
+ event.handler();
108
+ }
109
+ });
110
+ }
111
+
112
+ this.children.forEach((c) => c.activate());
113
+ this.isActivated = true;
114
+
115
+ this.afterActivatedInternal();
116
+ }
117
+ }
118
+
119
+ activateInternal() {
120
+
121
+ }
122
+
123
+ afterActivatedInternal() {
124
+
125
+ }
126
+
127
+ deactivate() {
128
+ if (this.isActivated) {
129
+ if (this.autoRegisterEvents) {
130
+ this.autoRegisterEvents.forEach((event) => {
131
+ event.node.removeEventListener(event.name, event.handler);
132
+ });
133
+ }
134
+
135
+ this.children.forEach((c) => c.deactivate());
136
+ this.deactivateInternal();
137
+ this.isActivated = false;
138
+ }
139
+ }
140
+
141
+ deactivateInternal() {
142
+
143
+ }
144
+
145
+ /**
146
+ *
147
+ * @param node ModelNode
148
+ * @param event string
149
+ * @param handler (param) => any
150
+ * @param runOnActivate bool
151
+ */
152
+ addAutoEvent(node, event, handler, runOnActivate = false) {
153
+ if ((!node) || typeof node.addEventListener !== 'function') {
154
+ console.error('Node with addEventListener was not provided!', node);
155
+ }
156
+ if (!this.autoRegisterEvents) {
157
+ this.autoRegisterEvents = [];
158
+ }
159
+ this.autoRegisterEvents.push({node: node, name: event, handler: handler, runOnActivate: runOnActivate});
160
+ }
161
+
162
+ addAutoEvents(node, events, handler, runOnActivate = false) {
163
+ events.forEach((event) => this.addAutoEvent(node, event, handler, runOnActivate));
164
+ }
165
+
166
+ addAutoEventMultiple(nodes, event, handler, runOnActivate = false) {
167
+ if (!Array.isArray(nodes)) {
168
+ console.error('Node array was not provided!');
169
+ }
170
+ nodes.forEach((n, i) => this.addAutoEvent(n, event, handler, i === 0 && runOnActivate));
171
+ }
172
+
173
+ addAutoEventsMultiple(nodes, events, handler, runOnActivate = false) {
174
+ events.forEach((event) => this.addAutoEventMultiple(nodes, event, handler, runOnActivate));
175
+ }
176
+
177
+ removeAutoEvent(node, name, handler) {
178
+ if (!this.autoRegisterEvents) {
179
+ return;
180
+ }
181
+ const event = this.autoRegisterEvents.find((e) => e.handler === handler && e.name === name && e.node === node);
182
+ if (event) {
183
+ NumberHelper.arrayRemove(this.autoRegisterEvents, event);
184
+ }
185
+ }
186
+
187
+ }
@@ -0,0 +1,156 @@
1
+ import NodeWithEvents from "./model/event/NodeWithEvents";
2
+
3
+ export default class Collection extends NodeWithEvents {
4
+
5
+ /**
6
+ * @type array
7
+ */
8
+ items;
9
+
10
+ constructor() {
11
+ super();
12
+ this.items = [];
13
+ }
14
+
15
+ asArray() {
16
+ return this.items;
17
+ }
18
+
19
+ add(element) {
20
+ this.items.push(element);
21
+ this.triggerEvent('add', element);
22
+ this.triggerEvent('change');
23
+ return element;
24
+ }
25
+
26
+ insert(element, index) {
27
+ this.items.splice(index, 0, element);
28
+ this.triggerEvent('insert', element);
29
+ this.triggerEvent('change');
30
+ return element;
31
+ }
32
+
33
+ prepend(element) {
34
+ return this.insert(element, 0);
35
+ }
36
+
37
+ remove(element) {
38
+ const index = this.items.indexOf(element);
39
+ return this.removeInternal(index, element);
40
+ }
41
+
42
+ removeByIndex(index) {
43
+ if (index >= 0 && index < this.count()) {
44
+ return this.removeInternal(index, this.items[index]);
45
+ }
46
+ return false;
47
+ }
48
+
49
+ removeInternal(index, element) {
50
+ if (index >= 0) {
51
+ this.items.splice(index, 1);
52
+ }
53
+ if (element) {
54
+ this.triggerEvent('remove', element);
55
+ this.triggerEvent('change');
56
+ return element;
57
+ }
58
+ return false;
59
+ }
60
+
61
+ reset() {
62
+ while (this.removeFirst()) {
63
+ }
64
+ }
65
+
66
+ isEmpty() {
67
+ return this.count() <= 0;
68
+ }
69
+
70
+ count() {
71
+ return this.items.length;
72
+ }
73
+
74
+ contains(item) {
75
+ return this.items.includes(item);
76
+ }
77
+
78
+ removeFirst() {
79
+ return this.removeByIndex(0);
80
+ }
81
+
82
+ removeLast() {
83
+ return this.removeByIndex(this.count() - 1);
84
+ }
85
+
86
+ swap(childA, childB) {
87
+ const indexA = this.items.indexOf(childA);
88
+ if (indexA < 0) {
89
+ return;
90
+ }
91
+ this.removeInternal(indexA, childA);
92
+
93
+ const indexB = this.items.indexOf(childB);
94
+ if (indexB < 0) {
95
+ this.insert(childA, indexA);
96
+ return;
97
+ }
98
+ this.removeInternal(indexB, childB);
99
+
100
+ this.insert(childA, indexB);
101
+ this.insert(childB, indexA);
102
+ }
103
+
104
+ first() {
105
+ return this.items[0];
106
+ }
107
+
108
+ last() {
109
+ return this.items[this.items.length - 1];
110
+ }
111
+
112
+ forEach(func) {
113
+ this.items.forEach(func);
114
+ }
115
+
116
+ filter(func) {
117
+ return this.items.filter(func);
118
+ }
119
+
120
+ find(func) {
121
+ return this.items.find(func);
122
+ }
123
+
124
+ exists(func) {
125
+ return (this.find(func) !== undefined);
126
+ }
127
+
128
+ map(transform) {
129
+ return this.items.map(transform);
130
+ }
131
+
132
+ reduce(callback, initial) {
133
+ return this.items.reduce(callback, initial);
134
+ }
135
+
136
+ sort(sortFunc) {
137
+ return this.items.sort(sortFunc);
138
+ }
139
+
140
+ addOnRemoveListener(listener) {
141
+ this.addEventListener('remove', listener);
142
+ }
143
+
144
+ removeOnRemoveListener(listener) {
145
+ this.removeEventListener('remove', listener);
146
+ }
147
+
148
+ addOnAddListener(listener) {
149
+ this.addEventListener('add', listener);
150
+ }
151
+
152
+ removeOnAddListener(listener) {
153
+ this.removeEventListener('add', listener);
154
+ }
155
+
156
+ }
@@ -0,0 +1,83 @@
1
+ import NodeWithEvents from "./model/event/NodeWithEvents";
2
+ import ChangeEvent from "./model/event/ChangeEvent";
3
+
4
+ const DEBUG_HASH_TABLE = false;
5
+
6
+ /**
7
+ * Triggers Events: add, set, remove
8
+ */
9
+ export default class Dictionary extends NodeWithEvents {
10
+
11
+ /**
12
+ * @type object
13
+ */
14
+ keyValues;
15
+
16
+ constructor(init = {}) {
17
+ super();
18
+ this.keyValues = init;
19
+ }
20
+
21
+ get(key) {
22
+ return this.keyValues[key];
23
+ }
24
+
25
+ exists(key) {
26
+ return (this.keyValues[key] !== undefined);
27
+ }
28
+
29
+ add(key, value = null) {
30
+ return this.set(key, value);
31
+ }
32
+
33
+ set(key, value = null) {
34
+ const old = this.get(key);
35
+ const existed = old !== undefined;
36
+ this.keyValues[key] = value;
37
+
38
+ if (existed) {
39
+ this.triggerEvent('set', new ChangeEvent(value, old, key));
40
+ } else {
41
+ this.triggerEvent('add', new ChangeEvent(value, undefined, key));
42
+ }
43
+ return value;
44
+ }
45
+
46
+ remove(key) {
47
+ if (!this.exists(key)) return;
48
+
49
+ const element = this.get(key);
50
+ delete this.keyValues[key];
51
+ this.triggerEvent('remove', new ChangeEvent(undefined, element, key));
52
+ return element;
53
+ }
54
+
55
+ rename(key, newKey) {
56
+ this.add(newKey, this.remove(key));
57
+ }
58
+
59
+ reset() {
60
+ const keys = this.keys();
61
+ keys.forEach((key) => this.remove(key));
62
+ this.keyValues = {};
63
+ }
64
+
65
+ count() {
66
+ return this.keys().length;
67
+ }
68
+
69
+ isEmpty() {
70
+ return (this.count() === 0);
71
+ }
72
+
73
+ keys() {
74
+ return Object.keys(this.keyValues);
75
+ }
76
+
77
+ forEach(func) {
78
+ for (let key in this.keyValues) {
79
+ func(key, this.keyValues[key]);
80
+ }
81
+ }
82
+
83
+ }
@@ -0,0 +1,35 @@
1
+ import NumberHelper from "../../helper/NumberHelper";
2
+ import ProgressVector3 from "./ProgressVector3";
3
+ import {EASING_FLAT} from "../ProgressValue";
4
+
5
+ export default class AnimatedVector3 {
6
+ progressVector;
7
+ duration;
8
+ elapsed;
9
+
10
+ constructor(start, end, duration, easing = EASING_FLAT, elapsed = 0) {
11
+ this.progressVector = new ProgressVector3(start, end, easing, elapsed);
12
+ this.duration = duration;
13
+ this.elapsed = elapsed;
14
+ this.updateProgress();
15
+ }
16
+
17
+ addElapsed(delta) {
18
+ this.elapsed += delta;
19
+ this.updateProgress();
20
+ }
21
+
22
+ updateProgress() {
23
+ this.progressVector.setProgress(NumberHelper.between(0, 1, this.elapsed / this.duration));
24
+ }
25
+
26
+ get(delta = null) {
27
+ if (delta !== null) this.addElapsed(delta);
28
+ return this.progressVector.get();
29
+ }
30
+
31
+ isFinished() {
32
+ return (this.elapsed >= this.duration);
33
+ }
34
+
35
+ }
@@ -0,0 +1,103 @@
1
+ import * as THREE from "three";
2
+
3
+ export default class AnimationHelper {
4
+
5
+ constructor(mesh, animations) {
6
+ this.mesh = mesh;
7
+ this.actions = [];
8
+ this.currentAction = null;
9
+ this.speed = 1;
10
+ this.lastUpdated = null;
11
+
12
+ this.mesh.traverse( function (object ) {
13
+ if (object.isMesh) {
14
+ object.castShadow = true;
15
+ object.receiveShadow = true;
16
+ object.frustumCulled = false;
17
+ }
18
+ });
19
+
20
+ this.mixer = new THREE.AnimationMixer(this.mesh);
21
+
22
+ for (let i = 0; i < animations.length; i++) {
23
+ let animation = animations[i];
24
+ let action = this.mixer.clipAction(animation);
25
+ this.actions[animation.name] = action;
26
+ action.play();
27
+ if (!this.currentAction) {
28
+ this.currentAction = action;
29
+ this.setWeight(this.currentAction, 1);
30
+ } else {
31
+ this.setWeight(action, 0);
32
+ }
33
+ }
34
+
35
+ //console.log(this.actions);
36
+ }
37
+
38
+ update() {
39
+ if (this.mixer && this.currentAction) {
40
+ const now = performance.now();
41
+ const delta = (this.lastUpdated) ? (now - this.lastUpdated) : 1;
42
+ this.lastUpdated = now;
43
+ this.mixer.update(this.speed * delta / 1000);
44
+ }
45
+ }
46
+
47
+ activateAction(name, duration, synchronize) {
48
+ const action = this.actions[name];
49
+ if (this.currentAction === action) {
50
+ this.currentAction.reset();
51
+ return;
52
+ }
53
+
54
+ if (synchronize)
55
+ this.synchronizeCrossFade(this.currentAction, action, duration);
56
+ else
57
+ this.executeCrossFade(this.currentAction, action, duration);
58
+ }
59
+
60
+ synchronizeCrossFade(startAction, endAction, duration) {
61
+ this.mixer.addEventListener('loop', onLoopFinished );
62
+ const _this = this;
63
+ function onLoopFinished(event) {
64
+ if (event.action === startAction) {
65
+ _this.mixer.removeEventListener('loop', onLoopFinished);
66
+ _this.executeCrossFade(startAction, endAction, duration);
67
+ }
68
+ }
69
+ }
70
+
71
+ executeCrossFade(startAction, endAction, duration) {
72
+ //console.log(endAction._clip.name);
73
+
74
+ // Not only the start action, but also the end action must get a weight of 1 before fading
75
+ if (startAction) this.setWeight(startAction, 1);
76
+
77
+ const durationSecs = duration / 1000;
78
+
79
+ if (endAction) {
80
+ this.setWeight(endAction, 1);
81
+ endAction.time = 0;
82
+
83
+ if (startAction) {
84
+ // Crossfade with warping
85
+ startAction.crossFadeTo(endAction, durationSecs, true);
86
+ } else {
87
+ endAction.fadeIn(durationSecs);
88
+ }
89
+ this.currentAction = endAction;
90
+ } else if (startAction) {
91
+ startAction.fadeOut(durationSecs);
92
+ }
93
+ }
94
+
95
+ // This function is needed, since animationAction.crossFadeTo() disables its start action and sets
96
+ // the start action's timeScale to ((start animation's duration) / (end animation's duration))
97
+ setWeight(action, weight) {
98
+ action.enabled = true;
99
+ action.setEffectiveTimeScale(1);
100
+ action.setEffectiveWeight(weight);
101
+ }
102
+
103
+ }
@@ -0,0 +1,26 @@
1
+ import ProgressValue, {EASING_FLAT} from "../ProgressValue";
2
+ import Vector3 from "../../model/vector/Vector3";
3
+
4
+ export default class ProgressVector3 {
5
+ progressX;
6
+ progressY;
7
+ progressZ;
8
+
9
+ constructor(start, end, easing = EASING_FLAT, progress = 0) {
10
+ this.progressX = new ProgressValue(start.x, end.x, easing, progress);
11
+ this.progressY = new ProgressValue(start.y, end.y, easing, progress);
12
+ this.progressZ = new ProgressValue(start.z, end.z, easing, progress);
13
+ }
14
+
15
+ setProgress(progress) {
16
+ this.progressX.progress = progress;
17
+ this.progressY.progress = progress;
18
+ this.progressZ.progress = progress;
19
+ }
20
+
21
+ get(progress = null) {
22
+ if (progress !== null) this.setProgress(progress);
23
+ return new Vector3(this.progressX.get(), this.progressY.get(), this.progressZ.get());
24
+ }
25
+
26
+ }
@@ -0,0 +1,44 @@
1
+ import NumberHelper from "../helper/NumberHelper";
2
+ import ProgressRotation from "./ProgressRotation";
3
+ import {EASING_FLAT} from "./ProgressValue";
4
+
5
+ export default class AnimatedRotation {
6
+
7
+ /**
8
+ * @type ProgressRotation
9
+ */
10
+ progress;
11
+
12
+ /**
13
+ * @type Number
14
+ */
15
+ duration;
16
+
17
+ /**
18
+ * @type Number
19
+ */
20
+ elapsed;
21
+
22
+ /**
23
+ *
24
+ * @param {Number} start
25
+ * @param {Number} end
26
+ * @param {Number} duration
27
+ * @param {Number} elapsed
28
+ */
29
+ constructor(start, end, duration, easing = EASING_FLAT, elapsed = 0) {
30
+ this.progress = new ProgressRotation(start, end, easing);
31
+ this.duration = duration;
32
+ this.elapsed = elapsed;
33
+ }
34
+
35
+ get(delta = null) {
36
+ if (delta !== null) this.elapsed += delta;
37
+ return this.progress.get(NumberHelper.between(0, 1, this.elapsed / this.duration));
38
+ }
39
+
40
+ isFinished() {
41
+ return (this.elapsed >= this.duration);
42
+ }
43
+
44
+ }
@@ -0,0 +1,33 @@
1
+ import ProgressValue, {EASING_FLAT} from "./ProgressValue";
2
+ import NumberHelper from "../helper/NumberHelper";
3
+
4
+ export default class AnimatedValue {
5
+ progressValue;
6
+ duration;
7
+
8
+ constructor(start, end, duration, easing = EASING_FLAT, elapsed = 0) {
9
+ this.progressValue = new ProgressValue(start, end, easing, elapsed);
10
+ this.duration = duration;
11
+ this.elapsed = elapsed;
12
+ this.updateProgress();
13
+ }
14
+
15
+ addElapsed(delta) {
16
+ this.elapsed += delta;
17
+ this.updateProgress();
18
+ }
19
+
20
+ updateProgress() {
21
+ this.progressValue.progress = NumberHelper.between(0, 1, this.elapsed / this.duration);
22
+ }
23
+
24
+ get(delta = null) {
25
+ if (delta !== null) this.addElapsed(delta);
26
+ return this.progressValue.get();
27
+ }
28
+
29
+ isFinished() {
30
+ return (this.elapsed >= this.duration);
31
+ }
32
+
33
+ }
@@ -0,0 +1,35 @@
1
+ import ProgressVector2 from "./ProgressVector2";
2
+ import NumberHelper from "../helper/NumberHelper";
3
+ import {EASING_FLAT} from "./ProgressValue";
4
+
5
+ export default class AnimatedVector2 {
6
+ progressVector;
7
+ duration;
8
+ elapsed;
9
+
10
+ constructor(start, end, duration, easing = EASING_FLAT, elapsed = 0) {
11
+ this.progressVector = new ProgressVector2(start, end, easing, elapsed);
12
+ this.duration = duration;
13
+ this.elapsed = elapsed;
14
+ this.updateProgress();
15
+ }
16
+
17
+ addElapsed(delta) {
18
+ this.elapsed += delta;
19
+ this.updateProgress();
20
+ }
21
+
22
+ updateProgress() {
23
+ this.progressVector.setProgress(NumberHelper.between(0, 1, this.elapsed / this.duration));
24
+ }
25
+
26
+ get(delta = null) {
27
+ if (delta !== null) this.addElapsed(delta);
28
+ return this.progressVector.get();
29
+ }
30
+
31
+ isFinished() {
32
+ return (this.elapsed >= this.duration);
33
+ }
34
+
35
+ }