wgge 1.1.4 → 2.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/bin/build.cmd +1 -0
- package/game/GameController.js +2 -95
- package/game/GameModel.js +1 -17
- package/game/{resources/assets → assets}/AssetCache.js +4 -4
- package/game/{resources/assets → assets}/loader/AssetLoader.js +1 -1
- package/package.json +2 -2
- package/game/resources/ResourcesModel.js +0 -23
- /package/game/{resources/assets → assets}/loader/AudioLoader.js +0 -0
- /package/game/{resources/assets → assets}/loader/ImageLoader.js +0 -0
package/bin/build.cmd
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm run build
|
package/game/GameController.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as localForage from "localforage";
|
|
2
1
|
import ControllerBase from "../core/controller/ControllerBase";
|
|
3
2
|
import ControlsController from "./controls/ControlsController";
|
|
4
3
|
|
|
@@ -14,9 +13,6 @@ export default class GameController extends ControllerBase {
|
|
|
14
13
|
|
|
15
14
|
this.model = model;
|
|
16
15
|
|
|
17
|
-
this.isResourcesDirty = false;
|
|
18
|
-
this.resourcesTimeOut = null;
|
|
19
|
-
|
|
20
16
|
this.addChild(new ControlsController(this.game, this.model.controls));
|
|
21
17
|
|
|
22
18
|
this.addAutoEvent(
|
|
@@ -36,99 +32,10 @@ export default class GameController extends ControllerBase {
|
|
|
36
32
|
}
|
|
37
33
|
);
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
this.model.
|
|
41
|
-
'dirty',
|
|
42
|
-
() => this.isResourcesDirty = true
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
this.addAutoEvent(
|
|
46
|
-
this.model,
|
|
47
|
-
'save-ui',
|
|
48
|
-
() => {
|
|
49
|
-
this.saveGameToStorage().then(() => {
|
|
50
|
-
console.log('savegame saved');
|
|
51
|
-
});
|
|
52
|
-
this.saveResourcesToStorage().then(() => {
|
|
53
|
-
console.log('resources saved');
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
activateInternal() {
|
|
61
|
-
super.activateInternal();
|
|
62
|
-
this.loadResourcesFromStorage();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
updateInternal(delta) {
|
|
66
|
-
|
|
67
|
-
// saving of resources during debugging
|
|
68
|
-
if (this.model.isInDebugMode.get()) {
|
|
69
|
-
this.resourcesTimeOut = (this.resourcesTimeOut === null) ? 3000 : this.resourcesTimeOut - delta;
|
|
70
|
-
if (this.isResourcesDirty && this.resourcesTimeOut <= 0) {
|
|
71
|
-
this.resourcesTimeOut = null;
|
|
72
|
-
this.isResourcesDirty = false;
|
|
73
|
-
this.saveResourcesToStorage().then(() => {
|
|
74
|
-
this.resourcesTimeOut = null;
|
|
75
|
-
console.log('resources saved');
|
|
76
|
-
});
|
|
77
|
-
}
|
|
35
|
+
hideMenu() {
|
|
36
|
+
this.model.menu.set(null);
|
|
78
37
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async loadResourcesFromStorage() {
|
|
82
|
-
try {
|
|
83
|
-
const state = await localForage.getItem('wegge-resources');
|
|
84
|
-
if (state) {
|
|
85
|
-
this.model.resources.restoreState(state);
|
|
86
|
-
} else {
|
|
87
|
-
console.log('nothing in storage');
|
|
88
|
-
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
console.error(err);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async saveResourcesToStorage() {
|
|
95
|
-
const state = this.model.resources.getState();
|
|
96
|
-
try {
|
|
97
|
-
await localForage.setItem('wegge-resources', state);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
console.error(err);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async loadGameFromStorage() {
|
|
104
|
-
try {
|
|
105
|
-
const state = await localForage.getItem('wegge-autosave');
|
|
106
|
-
if (state) {
|
|
107
|
-
const saveGame = this.saveGameFactory();
|
|
108
|
-
saveGame.restoreState(state);
|
|
109
|
-
this.model.saveGame.set(saveGame);
|
|
110
|
-
this.model.menu.set(null);
|
|
111
|
-
} else {
|
|
112
|
-
console.log('no saved game in storage');
|
|
113
|
-
}
|
|
114
|
-
} catch (err) {
|
|
115
|
-
console.error('Error when loading saved game.', err);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async saveGameToStorage() {
|
|
120
|
-
const saveGame = this.model.saveGame.get();
|
|
121
|
-
if (!saveGame) return;
|
|
122
|
-
const state = saveGame.getState();
|
|
123
|
-
try {
|
|
124
|
-
await localForage.setItem('wegge-autosave', state);
|
|
125
|
-
} catch (err) {
|
|
126
|
-
console.error(err);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
38
|
|
|
130
|
-
hideMenu() {
|
|
131
|
-
this.model.menu.set(null);
|
|
132
39
|
}
|
|
133
40
|
|
|
134
41
|
}
|
package/game/GameModel.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import ObjectModel from "../core/model/ObjectModel";
|
|
2
2
|
import Vector2 from "../core/model/vector/Vector2";
|
|
3
3
|
import ControlsModel from "./controls/ControlsModel";
|
|
4
|
-
import ResourcesModel from "./resources/ResourcesModel";
|
|
5
|
-
import NullableNode from "../core/model/value/NullableNode";
|
|
6
4
|
import BoolValue from "../core/model/value/BoolValue";
|
|
7
5
|
import GlobalAudioModel from "../core/audio/global/GlobalAudioModel";
|
|
8
|
-
import AssetCache from "./
|
|
6
|
+
import AssetCache from "./assets/AssetCache";
|
|
9
7
|
|
|
10
8
|
export default class GameModel extends ObjectModel {
|
|
11
9
|
|
|
@@ -24,16 +22,6 @@ export default class GameModel extends ObjectModel {
|
|
|
24
22
|
*/
|
|
25
23
|
viewBoxSize;
|
|
26
24
|
|
|
27
|
-
/**
|
|
28
|
-
* @type NullableNode<SaveGameModel>
|
|
29
|
-
*/
|
|
30
|
-
saveGame;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @type ResourcesModel
|
|
34
|
-
*/
|
|
35
|
-
resources;
|
|
36
|
-
|
|
37
25
|
/**
|
|
38
26
|
* @type AssetCache
|
|
39
27
|
*/
|
|
@@ -53,11 +41,7 @@ export default class GameModel extends ObjectModel {
|
|
|
53
41
|
super(false);
|
|
54
42
|
|
|
55
43
|
this.isInDebugMode = this.addProperty('isInDebugMode', new BoolValue(debugModeEnabled));
|
|
56
|
-
this.menu = this.addProperty('menu', new NullableNode());
|
|
57
|
-
|
|
58
44
|
this.viewBoxSize = this.addProperty('viewBoxSize', new Vector2());
|
|
59
|
-
this.saveGame = this.addProperty('saveGame', new NullableNode());
|
|
60
|
-
this.resources = this.addProperty('resources', new ResourcesModel());
|
|
61
45
|
this.assets = new AssetCache(this.resources);
|
|
62
46
|
this.audio = this.addProperty('audio', new GlobalAudioModel());
|
|
63
47
|
this.controls = this.addProperty('controls', new ControlsModel());
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Dictionary from "
|
|
2
|
-
import Collection from "
|
|
1
|
+
import Dictionary from "../../core/Dictionary";
|
|
2
|
+
import Collection from "../../core/Collection";
|
|
3
3
|
import ImageLoader from "./loader/ImageLoader";
|
|
4
4
|
import AudioLoader from "./loader/AudioLoader";
|
|
5
|
-
import NodeWithEvents from "
|
|
6
|
-
import StringHelper from "
|
|
5
|
+
import NodeWithEvents from "../../core/model/event/NodeWithEvents";
|
|
6
|
+
import StringHelper from "../../core/helper/StringHelper";
|
|
7
7
|
|
|
8
8
|
const ASSET_TYPE_LOADERS = {
|
|
9
9
|
'aud': AudioLoader,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wgge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Web GL Game Engine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
},
|
|
27
27
|
"author": "Karel Zavadil",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import ObjectModel from "../../core/model/ObjectModel";
|
|
2
|
-
|
|
3
|
-
export default class ResourcesModel extends ObjectModel {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @type ModelNodeTable
|
|
7
|
-
*/
|
|
8
|
-
images;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @type ModelNodeTable
|
|
12
|
-
*/
|
|
13
|
-
sounds;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
|
|
18
|
-
//this.images = this.addProperty('images', new ModelNodeTable((id) => new ImageModel(id)));
|
|
19
|
-
//this.sounds = this.addProperty('sounds', new ModelNodeTable((id) => new Model3dModel(id)));
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
File without changes
|
|
File without changes
|