wgge 2.0.38 → 2.0.39
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/Dictionary.js +30 -31
- package/core/model/event/NodeWithEvents.js +1 -6
- package/game/assets/AssetCache.js +22 -25
- package/package.json +1 -1
package/core/Dictionary.js
CHANGED
|
@@ -7,61 +7,54 @@ import ChangeEvent from "./model/event/ChangeEvent";
|
|
|
7
7
|
export default class Dictionary extends NodeWithEvents {
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @type
|
|
10
|
+
* @type Map
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
constructor(init = {}) {
|
|
15
|
-
super();
|
|
16
|
-
this.keyValues = init;
|
|
17
|
-
}
|
|
12
|
+
map= new Map();
|
|
18
13
|
|
|
19
14
|
get(key) {
|
|
20
|
-
return this.
|
|
15
|
+
return this.map.get(key);
|
|
21
16
|
}
|
|
22
17
|
|
|
23
18
|
exists(key) {
|
|
24
|
-
return
|
|
19
|
+
return this.map.has(key);
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
remove(key) {
|
|
23
|
+
if (!this.exists(key)) return;
|
|
24
|
+
const element = this.get(key);
|
|
25
|
+
this.map.delete(key);
|
|
26
|
+
this.triggerEvent('remove', new ChangeEvent(undefined, element, key));
|
|
27
|
+
return element;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
set(key, value =
|
|
30
|
+
set(key, value = undefined) {
|
|
32
31
|
const old = this.get(key);
|
|
33
32
|
const existed = old !== undefined;
|
|
34
|
-
this.keyValues[key] = value;
|
|
35
33
|
|
|
36
34
|
if (existed) {
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
return this.remove(key);
|
|
37
|
+
}
|
|
38
|
+
this.map.set(key, value);
|
|
37
39
|
this.triggerEvent('set', new ChangeEvent(value, old, key));
|
|
38
40
|
} else {
|
|
41
|
+
this.map.set(key, value);
|
|
39
42
|
this.triggerEvent('add', new ChangeEvent(value, undefined, key));
|
|
40
43
|
}
|
|
44
|
+
|
|
41
45
|
return value;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const element = this.get(key);
|
|
48
|
-
delete this.keyValues[key];
|
|
49
|
-
this.triggerEvent('remove', new ChangeEvent(undefined, element, key));
|
|
50
|
-
return element;
|
|
48
|
+
add(key, value = undefined) {
|
|
49
|
+
return this.set(key, value);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
rename(key, newKey) {
|
|
54
53
|
this.add(newKey, this.remove(key));
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
reset() {
|
|
58
|
-
const keys = this.keys();
|
|
59
|
-
keys.forEach((key) => this.remove(key));
|
|
60
|
-
this.keyValues = {};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
56
|
count() {
|
|
64
|
-
return this.
|
|
57
|
+
return this.map.size;
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
isEmpty() {
|
|
@@ -69,13 +62,19 @@ export default class Dictionary extends NodeWithEvents {
|
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
keys() {
|
|
72
|
-
return
|
|
65
|
+
return Array.from(this.map.keys());
|
|
73
66
|
}
|
|
74
67
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
reset() {
|
|
69
|
+
const keys = this.keys();
|
|
70
|
+
for (let i = 0, max = keys.length; i < max; i++) {
|
|
71
|
+
this.remove(keys[i]);
|
|
78
72
|
}
|
|
73
|
+
this.map = new Map();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
forEach(func) {
|
|
77
|
+
this.map.forEach((value, key) => func(key, value));
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
}
|
|
@@ -28,10 +28,5 @@ export default class NodeWithEvents {
|
|
|
28
28
|
this.eventManager.triggerEvent(eventName, param);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
static isNodeWithEvents(node) {
|
|
33
|
-
if (!node) return false;
|
|
34
|
-
return (typeof node === 'object' && typeof node.addEventListener === 'function');
|
|
35
|
-
}
|
|
36
|
-
*/
|
|
31
|
+
|
|
37
32
|
}
|
|
@@ -21,12 +21,17 @@ export default class AssetCache extends ObjectModel {
|
|
|
21
21
|
/**
|
|
22
22
|
* @type Dictionary
|
|
23
23
|
*/
|
|
24
|
-
cache;
|
|
24
|
+
cache = new Dictionary();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @type Dictionary
|
|
28
|
+
*/
|
|
29
|
+
loaderClasses = new Dictionary();
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
32
|
* @type Collection
|
|
28
33
|
*/
|
|
29
|
-
loaders;
|
|
34
|
+
loaders = new Collection();
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
37
|
* @type IntValue
|
|
@@ -51,15 +56,7 @@ export default class AssetCache extends ObjectModel {
|
|
|
51
56
|
constructor(resources) {
|
|
52
57
|
super(false);
|
|
53
58
|
|
|
54
|
-
this.loaderClasses = new Dictionary(
|
|
55
|
-
{
|
|
56
|
-
'aud': AudioLoader,
|
|
57
|
-
'img': ImageLoader
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
59
|
this.resources = resources;
|
|
61
|
-
this.cache = new Dictionary();
|
|
62
|
-
this.loaders = new Collection();
|
|
63
60
|
|
|
64
61
|
this.totalLoaders = this.addProperty('totalLoaders', new IntValue(0));
|
|
65
62
|
this.preloadingLoaders = this.addProperty('preloadingLoaders', new IntValue(0));
|
|
@@ -79,6 +76,9 @@ export default class AssetCache extends ObjectModel {
|
|
|
79
76
|
}
|
|
80
77
|
);
|
|
81
78
|
|
|
79
|
+
this.registerLoaderClass('aud', AudioLoader);
|
|
80
|
+
this.registerLoaderClass('img', ImageLoader);
|
|
81
|
+
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
registerLoaderClass(id, cls) {
|
|
@@ -100,8 +100,8 @@ export default class AssetCache extends ObjectModel {
|
|
|
100
100
|
this.sessionFinishedLoaders.increase();
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
resetCache(uri =
|
|
104
|
-
if (uri) {
|
|
103
|
+
resetCache(uri = undefined) {
|
|
104
|
+
if (uri !== undefined) {
|
|
105
105
|
this.cache.remove(uri);
|
|
106
106
|
} else {
|
|
107
107
|
this.cache.reset();
|
|
@@ -158,25 +158,22 @@ export default class AssetCache extends ObjectModel {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
loadImage(
|
|
162
|
-
this.loadAsset(
|
|
161
|
+
loadImage(path, onLoaded) {
|
|
162
|
+
this.loadAsset(`img/${path}`, onLoaded);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
loadAudio(
|
|
166
|
-
this.loadAsset(`
|
|
165
|
+
loadAudio(path, onLoaded) {
|
|
166
|
+
this.loadAsset(`aud/${path}`, onLoaded);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
preload(uris) {
|
|
170
|
+
console.log('Preloading:', uris);
|
|
171
|
+
uris.forEach((uri) => this.loadAsset(uri));
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
|
|
174
|
-
console.log('
|
|
175
|
-
|
|
174
|
+
load(uris) {
|
|
175
|
+
console.log('Loading:', uris);
|
|
176
|
+
uris.forEach((uri) => this.loadAsset(uri, () => undefined));
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
load(resources) {
|
|
179
|
-
console.log('Loading:', resources);
|
|
180
|
-
resources.forEach((r) => this.loadAsset(r, () => undefined));
|
|
181
|
-
}
|
|
182
179
|
}
|