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,94 @@
|
|
|
1
|
+
import DomRenderer from "../dom/DomRenderer";
|
|
2
|
+
import Vector2 from "../../model/vector/Vector2";
|
|
3
|
+
import DOMHelper from "../../helper/DOMHelper";
|
|
4
|
+
import ImageHelper from "../../helper/ImageHelper";
|
|
5
|
+
|
|
6
|
+
export default class ImageToCanvasRenderer extends DomRenderer {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type ImageModel
|
|
10
|
+
*/
|
|
11
|
+
model;
|
|
12
|
+
|
|
13
|
+
constructor(game, model, dom) {
|
|
14
|
+
super(game, model, dom);
|
|
15
|
+
|
|
16
|
+
this.model = model;
|
|
17
|
+
this.image = null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
activateInternal() {
|
|
21
|
+
this.canvas = DOMHelper.createElement(this.dom, 'canvas');
|
|
22
|
+
this.context2d = this.canvas.getContext('2d');
|
|
23
|
+
this.updateSize();
|
|
24
|
+
this.reloadImage();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deactivateInternal() {
|
|
28
|
+
this.removeElement(this.canvas);
|
|
29
|
+
this.context2d = null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
renderInternal() {
|
|
33
|
+
if (this.model.size.isDirty) {
|
|
34
|
+
this.updateSize();
|
|
35
|
+
}
|
|
36
|
+
if (this.model.uri.isDirty) {
|
|
37
|
+
this.reloadImage();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.renderImage();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
renderImage() {
|
|
44
|
+
if (!(this.image && this.context2d)) return;
|
|
45
|
+
this.context2d.clearRect(0, 0, this.model.size.x, this.model.size.y);
|
|
46
|
+
this.context2d.globalAlpha = this.model.opacity.get();
|
|
47
|
+
const imageSize = new Vector2(this.image.width, this.image.height);
|
|
48
|
+
const zoom = ImageHelper.sanitizeZoom(
|
|
49
|
+
imageSize,
|
|
50
|
+
this.model.size,
|
|
51
|
+
0,
|
|
52
|
+
this.model.zoom.get()
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
this.model.zoom.set(zoom);
|
|
56
|
+
|
|
57
|
+
const center = ImageHelper.sanitizeCenter(
|
|
58
|
+
imageSize,
|
|
59
|
+
this.model.size,
|
|
60
|
+
zoom,
|
|
61
|
+
this.model.coordinates
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
this.model.coordinates.set(center);
|
|
65
|
+
|
|
66
|
+
const viewSize = this.model.size.multiply(1 / zoom);
|
|
67
|
+
const corner = center.subtract(viewSize.multiply(0.5));
|
|
68
|
+
this.context2d.drawImage(
|
|
69
|
+
this.image,
|
|
70
|
+
corner.x,
|
|
71
|
+
corner.y,
|
|
72
|
+
viewSize.x,
|
|
73
|
+
viewSize.y,
|
|
74
|
+
0,
|
|
75
|
+
0,
|
|
76
|
+
this.model.size.x,
|
|
77
|
+
this.model.size.y
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
reloadImage() {
|
|
82
|
+
this.image = null;
|
|
83
|
+
if (this.model.uri.isEmpty()) return;
|
|
84
|
+
this.game.assets.getAsset(this.model.uri.get(), (img) => {
|
|
85
|
+
this.image = img;
|
|
86
|
+
this.renderImage();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
updateSize() {
|
|
91
|
+
this.canvas.width = this.model.size.x;
|
|
92
|
+
this.canvas.height = this.model.size.y;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import DomRenderer from "./DomRenderer";
|
|
2
|
+
import DOMHelper from "../../helper/DOMHelper";
|
|
3
|
+
|
|
4
|
+
export default class DirtyValueRenderer extends DomRenderer {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type DirtyValue
|
|
8
|
+
*/
|
|
9
|
+
model;
|
|
10
|
+
|
|
11
|
+
constructor(game, model, dom, formatter = null) {
|
|
12
|
+
super(game, model, dom);
|
|
13
|
+
|
|
14
|
+
this.model = model;
|
|
15
|
+
this.formatter = formatter;
|
|
16
|
+
this.container = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
activateInternal() {
|
|
20
|
+
this.container = DOMHelper.createElement(this.dom, 'span');
|
|
21
|
+
this.updateValue();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
deactivateInternal() {
|
|
25
|
+
this.removeElement(this.container);
|
|
26
|
+
this.container = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
renderInternal() {
|
|
30
|
+
this.updateValue();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
updateValue() {
|
|
34
|
+
this.container.innerText = this.formatter ? this.formatter(this.model.get()) : this.model.get();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import RendererBase from "../RendererBase";
|
|
2
|
+
import DOMHelper from "../../helper/DOMHelper";
|
|
3
|
+
|
|
4
|
+
export default class DomRenderer extends RendererBase {
|
|
5
|
+
dom;
|
|
6
|
+
|
|
7
|
+
constructor(game, model, dom) {
|
|
8
|
+
super(game, model);
|
|
9
|
+
this.dom = dom;
|
|
10
|
+
|
|
11
|
+
if (!this.dom) {
|
|
12
|
+
console.error('DOM renderer created without DOM!');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
addClass(css) {
|
|
17
|
+
DOMHelper.addClass(this.dom, css);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
removeClass(css) {
|
|
21
|
+
DOMHelper.removeClass(this.dom, css);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
addElement(tag, css = null) {
|
|
25
|
+
return DOMHelper.createElement(this.dom, tag, css);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
removeElement(el) {
|
|
29
|
+
DOMHelper.destroyElement(el);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import DomRenderer from "./DomRenderer";
|
|
2
|
+
|
|
3
|
+
export default class ImageRenderer extends DomRenderer {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type DirtyValue
|
|
7
|
+
*/
|
|
8
|
+
model;
|
|
9
|
+
|
|
10
|
+
constructor(game, model, dom) {
|
|
11
|
+
super(game, model, dom);
|
|
12
|
+
|
|
13
|
+
this.model = model;
|
|
14
|
+
this.container = null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
activateInternal() {
|
|
18
|
+
this.renderImage();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
deactivateInternal() {
|
|
22
|
+
this.removeElement(this.container);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
renderInternal() {
|
|
26
|
+
this.renderImage();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
renderImage() {
|
|
30
|
+
this.removeElement(this.container);
|
|
31
|
+
let uri = this.model.get();
|
|
32
|
+
if (typeof uri !== 'string' || uri.length === 0) {
|
|
33
|
+
console.error('Invalid image URI', uri);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.game.assets.getAsset(uri, (img) => {
|
|
37
|
+
this.container = img.cloneNode(true);
|
|
38
|
+
this.dom.appendChild(this.container);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import DomRenderer from "./DomRenderer";
|
|
2
|
+
import DOMHelper from "../../helper/DOMHelper";
|
|
3
|
+
import NumberHelper from "../../helper/NumberHelper";
|
|
4
|
+
|
|
5
|
+
export default class Vector2Renderer extends DomRenderer {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type Vector2
|
|
9
|
+
*/
|
|
10
|
+
model;
|
|
11
|
+
|
|
12
|
+
constructor(game, model, dom, formatter = null) {
|
|
13
|
+
super(game, model, dom);
|
|
14
|
+
|
|
15
|
+
this.model = model;
|
|
16
|
+
this.formatter = formatter;
|
|
17
|
+
this.container = null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
activateInternal() {
|
|
21
|
+
this.container = DOMHelper.createElement(this.dom, 'span');
|
|
22
|
+
this.updateValue();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
deactivateInternal() {
|
|
26
|
+
this.removeElement(this.container);
|
|
27
|
+
this.container = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
renderInternal() {
|
|
31
|
+
this.updateValue();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
updateValue() {
|
|
35
|
+
this.container.innerText = this.formatter ? this.formatter(this.model) : `[${NumberHelper.round(this.model.x, 2)}, ${NumberHelper.round(this.model.y, 2)}]`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import RendererBase from "../RendererBase";
|
|
2
|
+
|
|
3
|
+
export default class CollectionRenderer extends RendererBase {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type ModelNodeCollection
|
|
7
|
+
*/
|
|
8
|
+
model;
|
|
9
|
+
|
|
10
|
+
constructor(game, model, rendererFactory) {
|
|
11
|
+
super(game, model);
|
|
12
|
+
this.model = model;
|
|
13
|
+
|
|
14
|
+
this.rendererFactory = rendererFactory;
|
|
15
|
+
|
|
16
|
+
this.addAutoEvent(
|
|
17
|
+
this.model.children,
|
|
18
|
+
'add',
|
|
19
|
+
(model) => {
|
|
20
|
+
this.addRenderer(model);
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
this.addAutoEvent(
|
|
25
|
+
this.model.children,
|
|
26
|
+
'remove',
|
|
27
|
+
(model) => {
|
|
28
|
+
const renderer = this.children.find((ch) => ch.model === model);
|
|
29
|
+
this.removeChild(renderer);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
this.addAutoEvent(
|
|
34
|
+
this.model.children,
|
|
35
|
+
'insert',
|
|
36
|
+
() => {
|
|
37
|
+
this.resetChildren();
|
|
38
|
+
this.model.forEach((model) => {
|
|
39
|
+
this.addRenderer(model);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
true
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
addRenderer(model) {
|
|
47
|
+
return this.addChild(this.rendererFactory(model));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import RendererBase from "../RendererBase";
|
|
2
|
+
|
|
3
|
+
export default class ConditionalNodeRenderer extends RendererBase {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type DirtyValue
|
|
7
|
+
*/
|
|
8
|
+
model;
|
|
9
|
+
|
|
10
|
+
constructor(game, model, condition, rendererFactory, defaultRendererFactory = null) {
|
|
11
|
+
super(game, model);
|
|
12
|
+
this.model = model;
|
|
13
|
+
this.condition = condition;
|
|
14
|
+
this.rendererFactory = rendererFactory;
|
|
15
|
+
this.defaultRendererFactory = defaultRendererFactory;
|
|
16
|
+
this.renderer = null;
|
|
17
|
+
this.isUsingDefaultRenderer = false;
|
|
18
|
+
|
|
19
|
+
this.addAutoEvent(
|
|
20
|
+
this.model,
|
|
21
|
+
'change',
|
|
22
|
+
() => this.updateRenderer(),
|
|
23
|
+
true
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
render() {
|
|
28
|
+
if (!this.isActivated) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.renderer) {
|
|
32
|
+
this.renderer.render();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
updateRenderer() {
|
|
37
|
+
if (this.condition()) {
|
|
38
|
+
if (this.isUsingDefaultRenderer || this.renderer === null) {
|
|
39
|
+
this.resetChildren();
|
|
40
|
+
this.renderer = this.addChild(this.rendererFactory());
|
|
41
|
+
this.isUsingDefaultRenderer = false;
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (this.defaultRendererFactory) {
|
|
45
|
+
if (this.renderer === null || this.isUsingDefaultRenderer === false) {
|
|
46
|
+
this.resetChildren();
|
|
47
|
+
this.renderer = this.addChild(this.defaultRendererFactory());
|
|
48
|
+
this.isUsingDefaultRenderer = true;
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
this.resetChildren();
|
|
52
|
+
this.renderer = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import RendererBase from "../RendererBase";
|
|
2
|
+
|
|
3
|
+
export default class NullableNodeRenderer extends RendererBase {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type NodeValue
|
|
7
|
+
*/
|
|
8
|
+
model;
|
|
9
|
+
|
|
10
|
+
constructor(game, model, rendererFactory, defaultRendererFactory = null) {
|
|
11
|
+
super(game, model);
|
|
12
|
+
this.model = model;
|
|
13
|
+
|
|
14
|
+
this.rendererFactory = rendererFactory;
|
|
15
|
+
this.defaultRendererFactory = defaultRendererFactory;
|
|
16
|
+
|
|
17
|
+
this.addAutoEvent(
|
|
18
|
+
this.model,
|
|
19
|
+
'change',
|
|
20
|
+
() => this.updateRenderer(),
|
|
21
|
+
true
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
if (!this.isActivated) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (this.renderer) {
|
|
30
|
+
this.renderer.render();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
updateRenderer() {
|
|
35
|
+
this.resetChildren();
|
|
36
|
+
if (this.model.isSet()) {
|
|
37
|
+
this.renderer = this.addChild(this.rendererFactory(this.model.get()));
|
|
38
|
+
} else if (this.defaultRendererFactory) {
|
|
39
|
+
this.renderer = this.addChild(this.defaultRendererFactory());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import RendererBase from "../RendererBase";
|
|
2
|
+
import StringHelper from "../../helper/StringHelper";
|
|
3
|
+
import Vector2 from "../../model/vector/Vector2";
|
|
4
|
+
|
|
5
|
+
export default class SvgRenderer extends RendererBase {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {SVG.Container}
|
|
9
|
+
*/
|
|
10
|
+
draw;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {GameModel} game
|
|
15
|
+
* @param {ModelBase} model
|
|
16
|
+
* @param {SVG.Container} draw
|
|
17
|
+
*/
|
|
18
|
+
constructor(game, model, draw) {
|
|
19
|
+
super(game, model);
|
|
20
|
+
this.draw = draw;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getDefs() {
|
|
24
|
+
return this.draw.root().defs();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
refExists(uri) {
|
|
28
|
+
const token = StringHelper.token(uri);
|
|
29
|
+
return this.getDefs().findOne('#' + token);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getRef(uri) {
|
|
33
|
+
const token = StringHelper.token(uri);
|
|
34
|
+
const ref = this.getDefs().findOne('#' + token);
|
|
35
|
+
if (!ref) {
|
|
36
|
+
if (this.game.isInDebugMode.get()) console.warn(`Resource ${uri} (token: ${token}) not found!`)
|
|
37
|
+
}
|
|
38
|
+
return ref;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setRef(uri, ref) {
|
|
42
|
+
const token = StringHelper.token(uri);
|
|
43
|
+
const resource = this.getDefs().findOne('#' + token);
|
|
44
|
+
if (!resource) {
|
|
45
|
+
this.getDefs().add(ref);
|
|
46
|
+
ref.attr({id: token});
|
|
47
|
+
} else {
|
|
48
|
+
if (this.game.isInDebugMode.get()) console.log(`Resource ${uri} already loaded.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
loadImageRef(uri, onLoaded) {
|
|
53
|
+
if (this.refExists(uri)) {
|
|
54
|
+
onLoaded(this.getRef(uri));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.game.assets.getAsset(
|
|
58
|
+
uri,
|
|
59
|
+
(img) => {
|
|
60
|
+
if (this.refExists(uri)) {
|
|
61
|
+
onLoaded(this.getRef(uri));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const image = this.getDefs().image(img.src, () => {
|
|
65
|
+
this.setRef(uri, image);
|
|
66
|
+
onLoaded(image);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
rotate(element, rotation) {
|
|
73
|
+
let lastRotation = element.remember('rotation');
|
|
74
|
+
if (!lastRotation) {
|
|
75
|
+
lastRotation = 0;
|
|
76
|
+
}
|
|
77
|
+
element.rotate(rotation - lastRotation);
|
|
78
|
+
element.remember('rotation', rotation);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @param {SVG.Container|null|undefined} parent
|
|
84
|
+
* @param {Vector2} center
|
|
85
|
+
* @param {Vector2} size
|
|
86
|
+
* @param {SVG.StrokeData} stroke
|
|
87
|
+
* @param {string|Color|SVG.FillData} fill
|
|
88
|
+
*
|
|
89
|
+
* @returns SVG.Ellipse
|
|
90
|
+
*/
|
|
91
|
+
drawEllipse(
|
|
92
|
+
parent,
|
|
93
|
+
center,
|
|
94
|
+
size = new Vector2(5, 2),
|
|
95
|
+
stroke = {width: 1, color: 'gray'},
|
|
96
|
+
fill = 'transparent'
|
|
97
|
+
) {
|
|
98
|
+
if (!parent) parent = this.draw;
|
|
99
|
+
return parent
|
|
100
|
+
.ellipse(size.x, size.y)
|
|
101
|
+
.stroke(stroke)
|
|
102
|
+
.fill(fill)
|
|
103
|
+
.center(center.x, center.y);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @param {SVG.Container|null|undefined} parent
|
|
109
|
+
* @param {Vector2} start
|
|
110
|
+
* @param {Vector2} end
|
|
111
|
+
* @param {object|SVG.StrokeData} stroke
|
|
112
|
+
* @param {string|Color|SVG.FillData} fill
|
|
113
|
+
*
|
|
114
|
+
* @returns SVG.Line
|
|
115
|
+
*/
|
|
116
|
+
drawLine(
|
|
117
|
+
parent,
|
|
118
|
+
start,
|
|
119
|
+
end = 3,
|
|
120
|
+
stroke = {width: 1, color: 'black'},
|
|
121
|
+
fill = 'transparent'
|
|
122
|
+
) {
|
|
123
|
+
if (!parent) parent = this.draw;
|
|
124
|
+
return parent
|
|
125
|
+
.line(start.x, start.y, end.x, end.y)
|
|
126
|
+
.stroke(stroke)
|
|
127
|
+
.fill(fill);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import ControllerBase from "../core/controller/ControllerBase";
|
|
2
|
+
import HttpHelper from "../core/helper/HttpHelper";
|
|
3
|
+
|
|
4
|
+
export default class EditorController extends ControllerBase {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type DemoEditorModel
|
|
8
|
+
*/
|
|
9
|
+
model;
|
|
10
|
+
|
|
11
|
+
constructor(game, model) {
|
|
12
|
+
super(game, model);
|
|
13
|
+
|
|
14
|
+
this.model = model;
|
|
15
|
+
|
|
16
|
+
this.addAutoEvent(
|
|
17
|
+
this.model,
|
|
18
|
+
'table-selected',
|
|
19
|
+
(table) => this.runOnUpdate(() => this.model.activeTable.set(table))
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
this.addAutoEvent(
|
|
23
|
+
this.model,
|
|
24
|
+
'table-closed',
|
|
25
|
+
() => this.runOnUpdate(() => this.model.activeTable.set(null))
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
this.addAutoEvent(
|
|
29
|
+
this.model,
|
|
30
|
+
'node-saved',
|
|
31
|
+
(param) => this.runOnUpdate(() => this.saveNode(param))
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
this.addAutoEvent(
|
|
35
|
+
this.model,
|
|
36
|
+
'form-closed',
|
|
37
|
+
() => this.runOnUpdate(() => this.model.activeForm.set(null))
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
this.addAutoEvent(
|
|
41
|
+
this.model,
|
|
42
|
+
'node-delete',
|
|
43
|
+
(param) => this.runOnUpdate(() => this.deleteNode(param))
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
this.addAutoEvent(
|
|
47
|
+
this.model,
|
|
48
|
+
'node-clone',
|
|
49
|
+
(param) => this.runOnUpdate(() => this.cloneNode(param))
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
this.addAutoEvent(
|
|
53
|
+
this.model,
|
|
54
|
+
'download-resources',
|
|
55
|
+
(param) => this.runOnUpdate(() => this.downloadResources(param))
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
this.addAutoEvent(
|
|
59
|
+
this.model,
|
|
60
|
+
'save-resources',
|
|
61
|
+
() => this.saveResources()
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
this.addAutoEvent(
|
|
65
|
+
this.model,
|
|
66
|
+
'switch-options',
|
|
67
|
+
() => this.runOnUpdate(() => this.model.isVisible.invert())
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
activateInternal() {
|
|
73
|
+
this.game.audio.paused.set(true);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
deactivateInternal() {
|
|
77
|
+
this.game.audio.paused.set(false);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* * @param {Object} param
|
|
83
|
+
* * @param {ObjectModel} param.node
|
|
84
|
+
* * @param {FormData} param.data
|
|
85
|
+
*/
|
|
86
|
+
saveNode(param) {
|
|
87
|
+
const node = param.node;
|
|
88
|
+
const data = param.data;
|
|
89
|
+
|
|
90
|
+
node.properties.forEach((name, value) => {
|
|
91
|
+
if (data.has(name)) {
|
|
92
|
+
if (value && value.value !== undefined && typeof value.set === 'function') {
|
|
93
|
+
value.set(data.get(name));
|
|
94
|
+
} else {
|
|
95
|
+
console.log(data.get(name), name);
|
|
96
|
+
}
|
|
97
|
+
} else if (data.has(`${name}[]`)) {
|
|
98
|
+
if (typeof value === 'object' && typeof value.setFromArray === 'function') {
|
|
99
|
+
const arr = data.getAll(`${name}[]`);
|
|
100
|
+
value.setFromArray(arr);
|
|
101
|
+
}
|
|
102
|
+
} else if (value && typeof value.value === 'boolean' && typeof value.set === 'function') {
|
|
103
|
+
value.set(false);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
deleteNode(param) {
|
|
109
|
+
const node = param.node;
|
|
110
|
+
const table = param.table;
|
|
111
|
+
const result = table.remove(node);
|
|
112
|
+
if (table.selectedNode.equalsTo(node)) {
|
|
113
|
+
table.selectedNode.set(null);
|
|
114
|
+
}
|
|
115
|
+
console.log('removed node', result);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
cloneNode(param) {
|
|
119
|
+
const node = param.node;
|
|
120
|
+
const table = param.table;
|
|
121
|
+
const result = table.addClone(node);
|
|
122
|
+
table.selectedNode.set(result);
|
|
123
|
+
console.log('cloned node', result);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
downloadResources() {
|
|
127
|
+
const data = JSON.stringify(this.game.resources.getState());
|
|
128
|
+
HttpHelper.fakeDownload('resources.json', data);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async saveResources() {
|
|
132
|
+
const str = JSON.stringify(this.game.resources.getState());
|
|
133
|
+
await HttpHelper.post('http://localhost:88/save-resources', str);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ObjectModel from "../core/model/ObjectModel";
|
|
2
|
+
import NullableNode from "../core/model/value/NullableNode";
|
|
3
|
+
import BoolValue from "../core/model/value/BoolValue";
|
|
4
|
+
|
|
5
|
+
export default class EditorModel extends ObjectModel {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type BoolValue
|
|
9
|
+
*/
|
|
10
|
+
isVisible;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type NullableNode
|
|
14
|
+
*/
|
|
15
|
+
activeTable;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type NullableNode
|
|
19
|
+
*/
|
|
20
|
+
activeForm;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @type NullableNode<MaterialModel>
|
|
24
|
+
*/
|
|
25
|
+
activeMaterial;
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
|
|
30
|
+
this.activeTable = this.addProperty('activeTable', new NullableNode());
|
|
31
|
+
this.activeForm = this.addProperty('activeForm', new NullableNode());
|
|
32
|
+
this.activeMaterial = this.addProperty('activeMaterial', new NullableNode());
|
|
33
|
+
|
|
34
|
+
this.isVisible = this.addProperty('isVisible', new BoolValue(true));
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|