wgge 2.0.4 → 2.0.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.
- package/core/controller/AnimationRotationController.js +1 -1
- package/core/model/value/IntValue.js +1 -1
- package/game/GameModel.js +14 -1
- package/game/GameRenderer.js +11 -6
- package/game/assets/AssetCache.js +40 -35
- package/game/resources/ResourcesModel.js +20 -0
- package/game/resources/image/ImageModel.js +2 -7
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ export default class AnimationRotationVector2Controller extends AnimationControl
|
|
|
26
26
|
constructor(game, model, target, duration, easing = EASING_FLAT, elapsed = 0) {
|
|
27
27
|
super(game, model);
|
|
28
28
|
this.model = model;
|
|
29
|
-
this.animated = new AnimatedRotation(model.
|
|
29
|
+
this.animated = new AnimatedRotation(model.get(), target.get(), duration, easing, elapsed);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
updateInternal(delta) {
|
package/game/GameModel.js
CHANGED
|
@@ -5,6 +5,7 @@ import BoolValue from "../core/model/value/BoolValue";
|
|
|
5
5
|
import GlobalAudioModel from "../core/audio/global/GlobalAudioModel";
|
|
6
6
|
import AssetCache from "./assets/AssetCache";
|
|
7
7
|
import NullableNode from "../core/model/value/NullableNode";
|
|
8
|
+
import ResourcesModel from "./resources/ResourcesModel";
|
|
8
9
|
|
|
9
10
|
export default class GameModel extends ObjectModel {
|
|
10
11
|
|
|
@@ -23,6 +24,16 @@ export default class GameModel extends ObjectModel {
|
|
|
23
24
|
*/
|
|
24
25
|
viewBoxSize;
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @type NullableNode<SaveGameModel>
|
|
29
|
+
*/
|
|
30
|
+
saveGame;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @type ResourcesModel
|
|
34
|
+
*/
|
|
35
|
+
resources;
|
|
36
|
+
|
|
26
37
|
/**
|
|
27
38
|
* @type AssetCache
|
|
28
39
|
*/
|
|
@@ -44,7 +55,9 @@ export default class GameModel extends ObjectModel {
|
|
|
44
55
|
this.isInDebugMode = this.addProperty('isInDebugMode', new BoolValue(debugModeEnabled));
|
|
45
56
|
this.menu = this.addProperty('menu', new NullableNode());
|
|
46
57
|
this.viewBoxSize = this.addProperty('viewBoxSize', new Vector2());
|
|
47
|
-
this.
|
|
58
|
+
this.saveGame = this.addProperty('saveGame', new NullableNode());
|
|
59
|
+
this.resources = this.addProperty('resources', new ResourcesModel());
|
|
60
|
+
this.assets = this.addProperty('assets', new AssetCache(this.resources));
|
|
48
61
|
this.audio = this.addProperty('audio', new GlobalAudioModel());
|
|
49
62
|
this.controls = this.addProperty('controls', new ControlsModel());
|
|
50
63
|
}
|
package/game/GameRenderer.js
CHANGED
|
@@ -33,9 +33,14 @@ export default class GameRenderer extends DomRenderer {
|
|
|
33
33
|
)
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
this.addAutoEventMultiple(
|
|
37
|
+
[
|
|
38
|
+
this.model.assets.totalLoaders,
|
|
39
|
+
this.model.assets.blockingLoaders,
|
|
40
|
+
this.model.assets.sessionTotalLoaders,
|
|
41
|
+
this.model.assets.sessionFinishedLoaders
|
|
42
|
+
],
|
|
43
|
+
'changed',
|
|
39
44
|
() => this.updateLoading(),
|
|
40
45
|
true
|
|
41
46
|
);
|
|
@@ -70,7 +75,7 @@ export default class GameRenderer extends DomRenderer {
|
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
updateLoading() {
|
|
73
|
-
const isLoading = this.model.assets.blockingLoaders > 0;
|
|
78
|
+
const isLoading = this.model.assets.blockingLoaders.get() > 0;
|
|
74
79
|
if (this.loading && !isLoading) {
|
|
75
80
|
this.removeElement(this.loading);
|
|
76
81
|
this.loading = null;
|
|
@@ -86,9 +91,9 @@ export default class GameRenderer extends DomRenderer {
|
|
|
86
91
|
const progressWrapper = DOMHelper.createElement(content, 'div', 'progress-wrapper mt-2');
|
|
87
92
|
this.loadingProgress = DOMHelper.createElement(progressWrapper, 'div', 'stretch');
|
|
88
93
|
}
|
|
89
|
-
const portion = this.game.assets.sessionFinishedLoaders / this.game.assets.sessionTotalLoaders;
|
|
94
|
+
const portion = this.game.assets.sessionFinishedLoaders.get() / this.game.assets.sessionTotalLoaders.get();
|
|
90
95
|
this.loadingProgress.style.width = `${Math.round(portion * 100)}%`;
|
|
91
|
-
this.label2.innerText = `${this.game.assets.sessionFinishedLoaders}/${this.game.assets.sessionTotalLoaders}`;
|
|
96
|
+
this.label2.innerText = `${this.game.assets.sessionFinishedLoaders.get()}/${this.game.assets.sessionTotalLoaders.get()}`;
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
@@ -4,16 +4,14 @@ import ImageLoader from "./loader/ImageLoader";
|
|
|
4
4
|
import AudioLoader from "./loader/AudioLoader";
|
|
5
5
|
import NodeWithEvents from "../../core/model/event/NodeWithEvents";
|
|
6
6
|
import StringHelper from "../../core/helper/StringHelper";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'img': ImageLoader
|
|
11
|
-
}
|
|
7
|
+
import ObjectModel from "../../core/model/ObjectModel";
|
|
8
|
+
import ResourcesModel from "../resources/ResourcesModel";
|
|
9
|
+
import IntValue from "../../core/model/value/IntValue";
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Keeps cached raw resources like images, sounds and 3D models
|
|
15
13
|
*/
|
|
16
|
-
export default class AssetCache extends
|
|
14
|
+
export default class AssetCache extends ObjectModel {
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
17
|
* @type ResourcesModel
|
|
@@ -31,40 +29,56 @@ export default class AssetCache extends NodeWithEvents {
|
|
|
31
29
|
loaders;
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
|
-
* @type
|
|
32
|
+
* @type IntValue
|
|
35
33
|
*/
|
|
36
|
-
totalLoaders
|
|
34
|
+
totalLoaders;
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
|
-
* @type
|
|
37
|
+
* @type IntValue
|
|
40
38
|
*/
|
|
41
|
-
blockingLoaders
|
|
39
|
+
blockingLoaders;
|
|
42
40
|
|
|
43
41
|
/**
|
|
44
|
-
* @type
|
|
42
|
+
* @type IntValue
|
|
45
43
|
*/
|
|
46
|
-
sessionTotalLoaders
|
|
44
|
+
sessionTotalLoaders;
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
|
-
* @type
|
|
47
|
+
* @type IntValue
|
|
50
48
|
*/
|
|
51
|
-
sessionFinishedLoaders
|
|
49
|
+
sessionFinishedLoaders;
|
|
52
50
|
|
|
53
51
|
constructor(resources) {
|
|
54
|
-
super();
|
|
52
|
+
super(false);
|
|
53
|
+
|
|
54
|
+
this.loaderClasses = new Dictionary(
|
|
55
|
+
{
|
|
56
|
+
'aud': AudioLoader,
|
|
57
|
+
'img': ImageLoader
|
|
58
|
+
}
|
|
59
|
+
);
|
|
55
60
|
this.resources = resources;
|
|
56
61
|
this.cache = new Dictionary();
|
|
57
62
|
this.loaders = new Collection();
|
|
63
|
+
|
|
64
|
+
this.totalLoaders = this.addProperty('totalLoaders', new IntValue(0));
|
|
65
|
+
this.blockingLoaders = this.addProperty('blockingLoaders', new IntValue(0));
|
|
66
|
+
this.sessionTotalLoaders = this.addProperty('sessionTotalLoaders', new IntValue(0));
|
|
67
|
+
this.sessionFinishedLoaders = this.addProperty('sessionFinishedLoaders', new IntValue(0));
|
|
68
|
+
|
|
58
69
|
this.loaders.addOnAddListener((loader) => this.loaderAdded(loader));
|
|
59
70
|
this.loaders.addOnRemoveListener((loader) => this.loaderRemoved(loader));
|
|
60
71
|
|
|
61
72
|
}
|
|
62
73
|
|
|
74
|
+
registerLoaderClass(id, cls) {
|
|
75
|
+
this.loaderClasses.set(id, cls);
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
loaderAdded(loader) {
|
|
64
79
|
this.updateLoadingState();
|
|
65
80
|
if (!loader.isPreloading) {
|
|
66
|
-
this.sessionTotalLoaders
|
|
67
|
-
this.triggerEvent('session-total-loaders-changed', this.sessionTotalLoaders);
|
|
81
|
+
this.sessionTotalLoaders.increase();
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
}
|
|
@@ -72,26 +86,18 @@ export default class AssetCache extends NodeWithEvents {
|
|
|
72
86
|
loaderRemoved(loader) {
|
|
73
87
|
this.updateLoadingState();
|
|
74
88
|
if (!loader.isPreloading) {
|
|
75
|
-
this.sessionFinishedLoaders
|
|
76
|
-
if (this.blockingLoaders
|
|
77
|
-
this.sessionFinishedLoaders
|
|
78
|
-
this.sessionTotalLoaders
|
|
89
|
+
this.sessionFinishedLoaders.increase();
|
|
90
|
+
if (this.blockingLoaders.equalsTo(0)) {
|
|
91
|
+
this.sessionFinishedLoaders.set(0);
|
|
92
|
+
this.sessionTotalLoaders.set(0);
|
|
79
93
|
}
|
|
80
|
-
this.triggerEvent('session-finished-loaders-changed', this.sessionFinishedLoaders);
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
|
|
84
97
|
updateLoadingState() {
|
|
85
|
-
|
|
86
|
-
if (this.totalLoaders !== total) {
|
|
87
|
-
this.totalLoaders = total;
|
|
88
|
-
this.triggerEvent('total-loaders-changed', total);
|
|
89
|
-
}
|
|
98
|
+
this.totalLoaders.set(this.loaders.count());
|
|
90
99
|
const blocking = this.loaders.filter((l) => l.isPreloading === false).length;
|
|
91
|
-
|
|
92
|
-
this.blockingLoaders = blocking;
|
|
93
|
-
this.triggerEvent('blocking-loaders-changed', blocking);
|
|
94
|
-
}
|
|
100
|
+
this.blockingLoaders.set(blocking);
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
resetCache(name = null) {
|
|
@@ -139,12 +145,11 @@ export default class AssetCache extends NodeWithEvents {
|
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
const assetType = StringHelper.extractId(uri, 0);
|
|
142
|
-
|
|
148
|
+
const loaderClass = this.loaderClasses.get(assetType);
|
|
149
|
+
if (!loaderClass) {
|
|
143
150
|
console.error(`Valid resource type could not be inferred from URI '${uri}'!`);
|
|
144
151
|
}
|
|
145
|
-
|
|
146
|
-
const loaderType = ASSET_TYPE_LOADERS[assetType];
|
|
147
|
-
const loader = new loaderType(this, uri, onLoaded === null);
|
|
152
|
+
const loader = new loaderClass(this, uri, onLoaded === null);
|
|
148
153
|
this.loaders.add(loader);
|
|
149
154
|
loader.load(
|
|
150
155
|
(resource) => this.loaderSucceeded(loader, resource, onLoaded),
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ObjectModel from "../../core/model/ObjectModel";
|
|
2
|
+
import ModelNodeTable from "../../core/model/collection/table/ModelNodeTable";
|
|
3
|
+
import ImageModel from "./image/ImageModel";
|
|
4
|
+
|
|
5
|
+
export default class ResourcesModel extends ObjectModel {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type ModelNodeTable
|
|
9
|
+
*/
|
|
10
|
+
images;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
this.images = this.addProperty('images', new ModelNodeTable((id) => new ImageModel(id)));
|
|
16
|
+
//this.sounds = this.addProperty('sounds', new ModelNodeTable((id) => new Model3dModel(id)));
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import ObjectModel from "../../../core/model/ObjectModel";
|
|
2
2
|
import StringValue from "../../../core/model/value/StringValue";
|
|
3
3
|
import Vector2 from "../../../core/model/vector/Vector2";
|
|
4
|
+
import IdentifiedModelNode from "../../../core/model/collection/table/IdentifiedModelNode";
|
|
4
5
|
|
|
5
|
-
export default class ImageModel extends
|
|
6
|
+
export default class ImageModel extends IdentifiedModelNode {
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @type StringValue
|
|
9
10
|
*/
|
|
10
11
|
uri;
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
-
* @type Vector2
|
|
14
|
-
*/
|
|
15
|
-
size;
|
|
16
|
-
|
|
17
13
|
constructor(persistent = true) {
|
|
18
14
|
super(persistent);
|
|
19
15
|
|
|
20
16
|
this.uri = this.addProperty('uri', new StringValue());
|
|
21
|
-
this.size = this.addProperty('size', new Vector2(0, 0, false));
|
|
22
17
|
}
|
|
23
18
|
|
|
24
19
|
}
|