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.
- package/core/ActivatedTreeNode.js +187 -0
- package/core/Collection.js +156 -0
- package/core/Dictionary.js +83 -0
- package/core/animation/3d/AnimatedVector3.js +35 -0
- package/core/animation/3d/AnimationHelper.js +103 -0
- package/core/animation/3d/ProgressVector3.js +26 -0
- package/core/animation/AnimatedRotation.js +44 -0
- package/core/animation/AnimatedValue.js +33 -0
- package/core/animation/AnimatedVector2.js +35 -0
- package/core/animation/ProgressRotation.js +40 -0
- package/core/animation/ProgressValue.js +27 -0
- package/core/animation/ProgressVector2.js +23 -0
- package/core/audio/AudioModel.js +36 -0
- package/core/audio/AudioRenderer.js +120 -0
- package/core/audio/global/GlobalAudioModel.js +88 -0
- package/core/audio/global/GlobalAudioRenderer.js +108 -0
- package/core/controller/AnimationController.js +37 -0
- package/core/controller/AnimationFloatController.js +39 -0
- package/core/controller/AnimationVector2Controller.js +39 -0
- package/core/controller/CollectionController.js +47 -0
- package/core/controller/ConditionalNodeController.js +51 -0
- package/core/controller/ControllerBase.js +64 -0
- package/core/controller/ControllerWithSaveGame.js +27 -0
- package/core/controller/ControllerWithTimeout.js +10 -0
- package/core/controller/NullableNodeController.js +35 -0
- package/core/controller/TimeoutController.js +26 -0
- package/core/helper/ArrayHelper.js +19 -0
- package/core/helper/DOMHelper.js +167 -0
- package/core/helper/GUIHelper.js +53 -0
- package/core/helper/HttpHelper.js +33 -0
- package/core/helper/ImageHelper.js +36 -0
- package/core/helper/NumberHelper.js +28 -0
- package/core/helper/ObjectHelper.js +10 -0
- package/core/helper/StringHelper.js +59 -0
- package/core/model/ModelBase.js +91 -0
- package/core/model/ObjectModel.js +97 -0
- package/core/model/collection/ModelNodeCollection.js +232 -0
- package/core/model/collection/table/IdentifiedModelNode.js +24 -0
- package/core/model/collection/table/ModelNodeTable.js +53 -0
- package/core/model/event/ChangeEvent.js +24 -0
- package/core/model/event/EventManager.js +44 -0
- package/core/model/event/NodeWithEvents.js +32 -0
- package/core/model/template/TemplateNode.js +45 -0
- package/core/model/value/BoolValue.js +17 -0
- package/core/model/value/CapacityValue.js +49 -0
- package/core/model/value/DirtyValue.js +66 -0
- package/core/model/value/FloatValue.js +8 -0
- package/core/model/value/IntValue.js +20 -0
- package/core/model/value/NullableNode.js +66 -0
- package/core/model/value/StringValue.js +21 -0
- package/core/model/vector/Quaternion.js +82 -0
- package/core/model/vector/Rotation.js +61 -0
- package/core/model/vector/Vector2.js +177 -0
- package/core/model/vector/Vector3.js +98 -0
- package/core/renderer/RendererBase.js +46 -0
- package/core/renderer/canvas/CanvasRenderer.js +60 -0
- package/core/renderer/canvas/ImageToCanvasRenderer.js +94 -0
- package/core/renderer/dom/DirtyValueRenderer.js +36 -0
- package/core/renderer/dom/DomRenderer.js +32 -0
- package/core/renderer/dom/ImageRenderer.js +41 -0
- package/core/renderer/dom/Vector2Renderer.js +37 -0
- package/core/renderer/generic/CollectionRenderer.js +50 -0
- package/core/renderer/generic/ConditionalNodeRenderer.js +57 -0
- package/core/renderer/generic/NullableNodeRenderer.js +43 -0
- package/core/renderer/svg/SvgRenderer.js +130 -0
- package/editor/EditorController.js +135 -0
- package/editor/EditorModel.js +38 -0
- package/editor/EditorRenderer.js +116 -0
- package/editor/form/NodeFormRenderer.js +180 -0
- package/editor/material/MaterialPreviewRenderer.js +136 -0
- package/editor/table/TableRenderer.js +123 -0
- package/editor/table/lookup/TableLookupRenderer.js +120 -0
- package/editor/table/row/TableRowRenderer.js +97 -0
- package/game/GameController.js +144 -0
- package/game/GameModel.js +73 -0
- package/game/GameRenderer.js +108 -0
- package/game/controls/ControlsController.js +104 -0
- package/game/controls/ControlsModel.js +60 -0
- package/game/menu/MenuModel.js +25 -0
- package/game/menu/MenuRenderer.js +37 -0
- package/game/menu/item/MenuItemModel.js +31 -0
- package/game/menu/item/MenuItemRenderer.js +40 -0
- package/game/resources/3d/3DModel.js +30 -0
- package/game/resources/ResourcesModel.js +26 -0
- package/game/resources/assets/AssetCache.js +193 -0
- package/game/resources/assets/loader/AssetLoader.js +56 -0
- package/game/resources/assets/loader/AudioLoader.js +15 -0
- package/game/resources/assets/loader/GlbLoader.js +16 -0
- package/game/resources/assets/loader/ImageLoader.js +15 -0
- package/game/resources/assets/loader/MaterialLoader.js +49 -0
- package/game/resources/assets/loader/Model3dLoader.js +21 -0
- package/game/resources/assets/loader/SpriteLoader.js +40 -0
- package/game/resources/image/DualImageModel.js +34 -0
- package/game/resources/image/ImageModel.js +43 -0
- package/game/resources/material/MaterialModel.js +69 -0
- package/game/save/SaveGameController.js +21 -0
- package/game/save/SaveGameModel.js +5 -0
- package/game/save/SaveGameRenderer.js +17 -0
- package/game/save/editor/SaveGameEditorRenderer.js +17 -0
- package/index.html +42 -0
- package/index.js +73 -0
- package/package.json +35 -0
- package/style/basic/editor.less +290 -0
- package/style/basic/game.less +149 -0
- package/style/basic/utilities.less +215 -0
- package/style/style.less +3 -0
- package/webpack.config.js +29 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Dictionary from "../Dictionary";
|
|
2
|
+
import ArrayHelper from "../helper/ArrayHelper";
|
|
3
|
+
import ModelBase from "./ModelBase";
|
|
4
|
+
|
|
5
|
+
export default class ObjectModel extends ModelBase {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type Dictionary<DirtyValue>
|
|
9
|
+
*/
|
|
10
|
+
properties;
|
|
11
|
+
|
|
12
|
+
constructor(persistent = true) {
|
|
13
|
+
super(persistent);
|
|
14
|
+
|
|
15
|
+
this.properties = new Dictionary();
|
|
16
|
+
this.properties.addEventListener('add', (e) => this.propertyAdded(e.key, e.value));
|
|
17
|
+
this.properties.addEventListener('remove', (e) => this.propertyRemoved(e.key, e.old));
|
|
18
|
+
this.properties.addEventListener('set', (e) => this.propertySet(e.key, e.old, e.value));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
addProperty(name, property) {
|
|
22
|
+
return this.properties.add(name, property);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
propertyAdded(name, property) {
|
|
26
|
+
this.makeDirty();
|
|
27
|
+
this.subscribeToOnDirtyEvent(property);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
propertyRemoved(name, property) {
|
|
31
|
+
this.makeDirty();
|
|
32
|
+
this.unsubscribeFromOnDirtyEvent(property);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
propertySet(name, oldProperty, newProperty) {
|
|
36
|
+
this.propertyRemoved(name, oldProperty);
|
|
37
|
+
this.propertyAdded(name, newProperty);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
clean() {
|
|
41
|
+
if (super.clean()) {
|
|
42
|
+
this.properties.forEach((name, property) => property.clean());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
restoreState(state) {
|
|
47
|
+
if (state === null || state === undefined || typeof state !== 'object') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (state.p) {
|
|
51
|
+
this.properties.forEach((name, property) => property.restoreState(state.p[name]));
|
|
52
|
+
}
|
|
53
|
+
if (state.i !== undefined) {
|
|
54
|
+
this.restoreStateInternal(state.i);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getState() {
|
|
59
|
+
if (!this.isPersistent) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const state = {};
|
|
64
|
+
|
|
65
|
+
if (this.properties.count() > 0) {
|
|
66
|
+
const properties = {};
|
|
67
|
+
this.properties.forEach((name, propertyNode) =>
|
|
68
|
+
properties[name] = propertyNode.getState()
|
|
69
|
+
);
|
|
70
|
+
state.p = properties;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const internal = this.getStateInternal();
|
|
74
|
+
if (internal !== undefined) {
|
|
75
|
+
state.i = internal;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return state;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getResourcesForPreload() {
|
|
82
|
+
const result = this.getResourcesForPreloadInternal();
|
|
83
|
+
this.properties.forEach(
|
|
84
|
+
(name, child) => {
|
|
85
|
+
if (typeof child.getResourcesForPreload === 'function') {
|
|
86
|
+
result.push(...child.getResourcesForPreload());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
return ArrayHelper.unique(result).filter((uri) => uri !== null && uri !== '');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getResourcesForPreloadInternal() {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import NullableNode from "../value/NullableNode";
|
|
2
|
+
import Collection from "../../Collection";
|
|
3
|
+
import ArrayHelper from "../../helper/ArrayHelper";
|
|
4
|
+
import ObjectModel from "../ObjectModel";
|
|
5
|
+
|
|
6
|
+
export default class ModelNodeCollection extends ObjectModel {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type Collection
|
|
10
|
+
*/
|
|
11
|
+
children;
|
|
12
|
+
|
|
13
|
+
nodeFactory;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type NullableNode
|
|
17
|
+
*/
|
|
18
|
+
selectedNode;
|
|
19
|
+
|
|
20
|
+
constructor(nodeFactory = null, persistent = true) {
|
|
21
|
+
super(persistent);
|
|
22
|
+
|
|
23
|
+
this.nodeFactory = nodeFactory;
|
|
24
|
+
this.children = new Collection();
|
|
25
|
+
const events = ['add', 'remove', 'change'];
|
|
26
|
+
events.forEach((event) => this.children.addEventListener(event, (param) => this.triggerEvent(event, param)));
|
|
27
|
+
this.children.addOnAddListener((child) => this.onChildAdded(child));
|
|
28
|
+
this.children.addOnRemoveListener((child) => this.onChildRemoved(child));
|
|
29
|
+
this.childDirtyHandler = (ch) => this.onChildDirty(ch);
|
|
30
|
+
this.childRequestedRemoveHandler = (ch) => this.remove(ch);
|
|
31
|
+
|
|
32
|
+
this.selectedNode = this.addProperty('selectedNode', new NullableNode(null, false));
|
|
33
|
+
|
|
34
|
+
this.addEventListener('drag-start', (child) => {
|
|
35
|
+
this.selectedNode.set(child);
|
|
36
|
+
});
|
|
37
|
+
this.addEventListener('drag-drop', (child) => {
|
|
38
|
+
const node = this.selectedNode.get();
|
|
39
|
+
const startIndex = this.indexOf(node);
|
|
40
|
+
const targetIndex = this.indexOf(child);
|
|
41
|
+
if (startIndex === targetIndex) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.remove(node);
|
|
45
|
+
this.insert(node, targetIndex);
|
|
46
|
+
this.selectedNode.set(node);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
asArray() {
|
|
51
|
+
return this.children.asArray();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addMultipleAsArray(children) {
|
|
55
|
+
return children.map((ch) => this.add(ch));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param {ObjectModel | []} child
|
|
61
|
+
* @returns {ObjectModel | [] | any}
|
|
62
|
+
*/
|
|
63
|
+
add(child = null) {
|
|
64
|
+
if (Array.isArray(child)) return this.addMultipleAsArray(child);
|
|
65
|
+
|
|
66
|
+
if (!child) {
|
|
67
|
+
child = this.nodeFactory();
|
|
68
|
+
}
|
|
69
|
+
return this.children.add(child);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
prepend(child) {
|
|
73
|
+
return this.children.prepend(child);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
insert(child, index) {
|
|
77
|
+
return this.children.insert(child, index);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
remove(child) {
|
|
81
|
+
return this.children.remove(child);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
contains(item) {
|
|
85
|
+
return this.children.contains(item);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
first() {
|
|
89
|
+
return this.children.first();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
last() {
|
|
93
|
+
return this.children.last();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
indexOf(node) {
|
|
97
|
+
return this.children.items.indexOf(node);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
random() {
|
|
101
|
+
return ArrayHelper.random(this.children.items);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get(i) {
|
|
105
|
+
return this.children.items[i];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
count() {
|
|
109
|
+
return this.children.count();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
isEmpty() {
|
|
113
|
+
return (this.count() === 0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
find(search) {
|
|
117
|
+
return this.children.find(search);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
exists(search) {
|
|
121
|
+
return this.children.exists(search);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
filter(search) {
|
|
125
|
+
return this.children.filter(search);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
map(transform) {
|
|
129
|
+
return this.children.map(transform);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
reduce(callback, initial) {
|
|
133
|
+
return this.children.reduce(callback, initial);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
sort(sortFunc) {
|
|
137
|
+
return this.children.sort(sortFunc);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
forEach(func) {
|
|
141
|
+
return this.children.forEach(func);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
swap(childA, childB) {
|
|
145
|
+
this.children.swap(childA, childB);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
clean() {
|
|
149
|
+
if (this.isDirty) {
|
|
150
|
+
super.clean();
|
|
151
|
+
this.children.forEach((child) => child.clean());
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
cleanAll() {
|
|
156
|
+
this.clean();
|
|
157
|
+
this.children.forEach((child) => child.cleanAll());
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
reset() {
|
|
161
|
+
this.children.reset();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
addOnAddListener(handler) {
|
|
165
|
+
this.children.addOnAddListener(handler);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
removeOnAddListener(handler) {
|
|
169
|
+
this.children.removeOnAddListener(handler);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
addOnRemoveListener(handler) {
|
|
173
|
+
this.children.addOnRemoveListener(handler);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
removeOnRemoveListener(handler) {
|
|
177
|
+
this.children.removeOnRemoveListener(handler);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
* @param {ObjectModel} child
|
|
183
|
+
*/
|
|
184
|
+
onChildAdded(child) {
|
|
185
|
+
this.makeDirty();
|
|
186
|
+
child.addOnDirtyListener(this.childDirtyHandler);
|
|
187
|
+
child.addEventListener('remove-me', this.childRequestedRemoveHandler);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
* @param {ObjectModel} child
|
|
193
|
+
*/
|
|
194
|
+
onChildRemoved(child) {
|
|
195
|
+
this.makeDirty();
|
|
196
|
+
child.removeOnDirtyListener(this.childDirtyHandler);
|
|
197
|
+
child.removeEventListener('remove-me', this.childRequestedRemoveHandler);
|
|
198
|
+
if (this.selectedNode.equalsTo(child)) {
|
|
199
|
+
this.selectedNode.set(null);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
onChildDirty(child) {
|
|
204
|
+
this.makeDirty();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getStateInternal() {
|
|
208
|
+
const state = [];
|
|
209
|
+
this.children.forEach((ch) => state.push(ch.getState()));
|
|
210
|
+
return state;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
restoreStateInternal(state) {
|
|
214
|
+
this.children.reset();
|
|
215
|
+
if (!this.nodeFactory) {
|
|
216
|
+
console.log('no factory for restoring ModelNodeCollection');
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
for (let i = 0, max = state.length; i < max; i++) {
|
|
220
|
+
const child = this.nodeFactory();
|
|
221
|
+
child.restoreState(state[i]);
|
|
222
|
+
this.children.add(child);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
getResourcesForPreload() {
|
|
227
|
+
const result = super.getResourcesForPreload();
|
|
228
|
+
this.children.forEach((ch) => result.push(...ch.getResourcesForPreload()));
|
|
229
|
+
return ArrayHelper.unique(result);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import ObjectModel from "../../ObjectModel";
|
|
2
|
+
import IntValue from "../../value/IntValue";
|
|
3
|
+
|
|
4
|
+
export default class IdentifiedModelNode extends ObjectModel {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type IntValue
|
|
8
|
+
*/
|
|
9
|
+
id;
|
|
10
|
+
|
|
11
|
+
constructor(id = 0, persistent = true) {
|
|
12
|
+
super(persistent);
|
|
13
|
+
|
|
14
|
+
this.id = this.addProperty('id', new IntValue(id));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
equalsTo(ch) {
|
|
18
|
+
if (super.equalsTo(ch)) return true;
|
|
19
|
+
if (typeof ch.id !== 'object') return false;
|
|
20
|
+
if (typeof ch.id.get !== 'function') return false;
|
|
21
|
+
return this.equalsTo(ch.id.get());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import ModelNodeCollection from "../ModelNodeCollection";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Collection of IdentifiedModelNode that allows search by ID.
|
|
5
|
+
*/
|
|
6
|
+
export default class ModelNodeTable extends ModelNodeCollection {
|
|
7
|
+
|
|
8
|
+
getById(id) {
|
|
9
|
+
if (id === null || id === undefined || id === '') {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (typeof id === 'object' && id.constructor.name === 'IntValue') {
|
|
13
|
+
return this.getById(id.get());
|
|
14
|
+
}
|
|
15
|
+
const i = Number(id);
|
|
16
|
+
if (i === Number.NaN || i <= 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return this.children.find((ch) => ch.id.equalsTo(i));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get(id) {
|
|
23
|
+
return this.getById(id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
maxId() {
|
|
27
|
+
if (this.children.count() === 0) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
return this.children.items.reduce((prev, current) => Math.max(prev, parseInt(current.id.get())), 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
nextId() {
|
|
34
|
+
return this.maxId() + 1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
add(node) {
|
|
38
|
+
const id = this.nextId();
|
|
39
|
+
if (!node) {
|
|
40
|
+
node = this.nodeFactory(id);
|
|
41
|
+
}
|
|
42
|
+
node.id.set(id);
|
|
43
|
+
super.add(node);
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
addClone(node) {
|
|
48
|
+
const clone = node.clone();
|
|
49
|
+
clone.id.set(this.nextId());
|
|
50
|
+
return this.insert(clone, this.indexOf(node) + 1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default class ChangeEvent {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type string|undefined
|
|
5
|
+
*/
|
|
6
|
+
key;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type any
|
|
10
|
+
*/
|
|
11
|
+
old;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type any
|
|
15
|
+
*/
|
|
16
|
+
value;
|
|
17
|
+
|
|
18
|
+
constructor(value, old = undefined, key = undefined) {
|
|
19
|
+
this.key = key;
|
|
20
|
+
this.old = old;
|
|
21
|
+
this.value = value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const DEBUG_EVENT_MANAGER = false;
|
|
2
|
+
|
|
3
|
+
export default class EventManager {
|
|
4
|
+
handlers;
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
this.handlers = [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
addEventListener(eventName, eventHandler) {
|
|
11
|
+
if (!this.handlers[eventName]) {
|
|
12
|
+
this.handlers[eventName] = [];
|
|
13
|
+
}
|
|
14
|
+
const index = this.handlers[eventName].indexOf(eventHandler);
|
|
15
|
+
if (index >= 0) {
|
|
16
|
+
if (DEBUG_EVENT_MANAGER) console.log('Event listener already registered.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return this.handlers[eventName].push(eventHandler);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
removeEventListener(eventName, eventHandler) {
|
|
23
|
+
if (!this.handlers[eventName]) {
|
|
24
|
+
this.handlers[eventName] = [];
|
|
25
|
+
}
|
|
26
|
+
const index = this.handlers[eventName].indexOf(eventHandler);
|
|
27
|
+
if (index >= 0) {
|
|
28
|
+
this.handlers[eventName].splice(index, 1);
|
|
29
|
+
} else {
|
|
30
|
+
if (DEBUG_EVENT_MANAGER) console.log('Event listener cannot be removed - not found.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
triggerEvent(eventName, param) {
|
|
35
|
+
if (!this.handlers[eventName]) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const handlers = this.handlers[eventName];
|
|
39
|
+
handlers.forEach((item) => {
|
|
40
|
+
item(param);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import EventManager from "./EventManager";
|
|
2
|
+
|
|
3
|
+
export default class NodeWithEvents {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type EventManager
|
|
7
|
+
*/
|
|
8
|
+
eventManager;
|
|
9
|
+
|
|
10
|
+
addEventListener(eventName, eventHandler, runImmediately = false) {
|
|
11
|
+
if (!this.eventManager) {
|
|
12
|
+
this.eventManager = new EventManager();
|
|
13
|
+
}
|
|
14
|
+
this.eventManager.addEventListener(eventName, eventHandler);
|
|
15
|
+
if (runImmediately) {
|
|
16
|
+
eventHandler();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
removeEventListener(eventName, eventHandler) {
|
|
21
|
+
if (this.eventManager) {
|
|
22
|
+
this.eventManager.removeEventListener(eventName, eventHandler);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
triggerEvent(eventName, param) {
|
|
27
|
+
if (this.eventManager) {
|
|
28
|
+
this.eventManager.triggerEvent(eventName, param);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import IdentifiedModelNode from "../collection/table/IdentifiedModelNode";
|
|
2
|
+
import IntValue from "../value/IntValue";
|
|
3
|
+
|
|
4
|
+
export default class TemplateNode extends IdentifiedModelNode {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type IntValue
|
|
8
|
+
*/
|
|
9
|
+
originalId;
|
|
10
|
+
|
|
11
|
+
constructor(id = 0) {
|
|
12
|
+
super(id);
|
|
13
|
+
|
|
14
|
+
this.originalId = this.addProperty('originalId', new IntValue());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
isCloned() {
|
|
18
|
+
return this.originalId.isSet();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getOriginalId() {
|
|
22
|
+
if (this.originalId.isSet()) return this.originalId.get();
|
|
23
|
+
return this.id.get();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
isOriginalId(id) {
|
|
27
|
+
return this.getOriginalId() === id;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
isFromSameOrigin(tn) {
|
|
31
|
+
if (typeof tn.getOriginalId !== 'function') return false;
|
|
32
|
+
return this.isOriginalId(tn.getOriginalId());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @return TemplateNode
|
|
37
|
+
*/
|
|
38
|
+
clone() {
|
|
39
|
+
throw new Error('Clone function not defined!');
|
|
40
|
+
//const ch = new CharacterModel();
|
|
41
|
+
//ch.restoreState(this.getState());
|
|
42
|
+
//ch.originalId.set(this.id.get());
|
|
43
|
+
//return ch;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import DirtyValue from "./DirtyValue";
|
|
2
|
+
|
|
3
|
+
export default class BoolValue extends DirtyValue {
|
|
4
|
+
|
|
5
|
+
set(value) {
|
|
6
|
+
if (typeof value === 'string') {
|
|
7
|
+
super.set(value !== 'false' && value !== '');
|
|
8
|
+
} else {
|
|
9
|
+
super.set(value !== undefined && value !== null && value !== false && value !== 0);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
invert() {
|
|
14
|
+
this.set(!this.get());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import FloatValue from "./FloatValue";
|
|
2
|
+
|
|
3
|
+
export default class CapacityValue extends FloatValue {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @type FloatValue
|
|
8
|
+
*/
|
|
9
|
+
min;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type FloatValue
|
|
14
|
+
*/
|
|
15
|
+
max;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @type FloatValue
|
|
20
|
+
*/
|
|
21
|
+
progress;
|
|
22
|
+
|
|
23
|
+
constructor(min = 0, max = 1, value = 0.5) {
|
|
24
|
+
super(value);
|
|
25
|
+
|
|
26
|
+
this.min = new FloatValue(min);
|
|
27
|
+
this.max = new FloatValue(max);
|
|
28
|
+
|
|
29
|
+
this.progress = new FloatValue(value, false);
|
|
30
|
+
|
|
31
|
+
this.addEventListener('change', () => this.update())
|
|
32
|
+
this.min.addEventListener('change', () => this.propUpdated())
|
|
33
|
+
this.max.addEventListener('change', () => this.propUpdated())
|
|
34
|
+
|
|
35
|
+
this.update();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
update() {
|
|
39
|
+
if (this.min.get() > this.max.get()) return this.min.set(this.max.get());
|
|
40
|
+
if (this.get() < this.min.get()) return this.set(this.min.get());
|
|
41
|
+
if (this.get() > this.max.get()) return this.set(this.max.get());
|
|
42
|
+
this.progress.set((this.get() - this.min.get()) / this.max.get());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
propUpdated() {
|
|
46
|
+
this.update();
|
|
47
|
+
this.triggerEvent('change');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import ModelBase from "../ModelBase";
|
|
2
|
+
|
|
3
|
+
export default class DirtyValue extends ModelBase {
|
|
4
|
+
/** @type object|string|null */
|
|
5
|
+
value = null;
|
|
6
|
+
|
|
7
|
+
constructor(value = null, persistent = true) {
|
|
8
|
+
super(persistent);
|
|
9
|
+
this.set(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
set(value) {
|
|
13
|
+
if (this.value !== value) {
|
|
14
|
+
const old = this.value;
|
|
15
|
+
this.value = value;
|
|
16
|
+
this.makeDirty();
|
|
17
|
+
this.triggerOnChangeEvent(old);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get() {
|
|
22
|
+
return this.value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return this.isSet() ? this.get() : '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
isEmpty() {
|
|
30
|
+
return this.value === null || this.value === undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
isSet() {
|
|
34
|
+
return !this.isEmpty();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getStateInternal() {
|
|
38
|
+
return this.get();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
equalsTo(value) {
|
|
42
|
+
if (this.value === value) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === 'object' && value !== null && value !== undefined && value.value !== undefined) {
|
|
46
|
+
return value.value === this.value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
restoreStateInternal(state) {
|
|
51
|
+
this.set(state);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addOnChangeListener(eventHandler, runImmediately = false) {
|
|
55
|
+
this.addEventListener('change', eventHandler, runImmediately);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
removeOnChangeListener(eventHandler) {
|
|
59
|
+
this.removeEventListener('change', eventHandler);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
triggerOnChangeEvent(oldValue) {
|
|
63
|
+
this.triggerEvent('change', {oldValue: oldValue, newValue: this.value});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|