@inappstory/game-center-api 1.3.6 → 1.3.7
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/lib/gameResources.d.ts +3 -6
- package/lib/gameResources.js +18 -25
- package/package.json +1 -1
package/lib/gameResources.d.ts
CHANGED
|
@@ -16,14 +16,11 @@ export declare class Resource implements ResourceInterface {
|
|
|
16
16
|
}
|
|
17
17
|
export declare abstract class ResourceList implements Iterable<ResourceInterface> {
|
|
18
18
|
protected orderOfFetch: number;
|
|
19
|
+
protected _hashMap: Record<string, Resource> | null;
|
|
20
|
+
protected get hashMap(): Readonly<Record<string, Resource>>;
|
|
19
21
|
constructor();
|
|
20
|
-
|
|
21
|
-
[k: string]: string;
|
|
22
|
-
};
|
|
23
|
-
getAssetByKey(key: string, defaultValue: any): any;
|
|
24
|
-
protected _assets: Array<Resource> | undefined;
|
|
22
|
+
getAssetByKey<T>(key: string, defaultValue: T): string | T;
|
|
25
23
|
protected rawMapGetter(): Record<string, string>;
|
|
26
|
-
protected get __assets(): Resource[];
|
|
27
24
|
protected prepareSrc(src: string, key: string): string;
|
|
28
25
|
protected onCacheDone(): void;
|
|
29
26
|
[Symbol.iterator](): {
|
package/lib/gameResources.js
CHANGED
|
@@ -43,47 +43,40 @@ class Resource {
|
|
|
43
43
|
exports.Resource = Resource;
|
|
44
44
|
class ResourceList {
|
|
45
45
|
orderOfFetch = 0;
|
|
46
|
-
|
|
47
|
-
get
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
_hashMap = null;
|
|
47
|
+
get hashMap() {
|
|
48
|
+
if (this._hashMap === null) {
|
|
49
|
+
const map = this.rawMapGetter();
|
|
50
|
+
this._hashMap = {};
|
|
51
|
+
let src;
|
|
52
|
+
for (let key in map) {
|
|
53
|
+
src = map[key];
|
|
54
|
+
this._hashMap[key] = new Resource(key, this.prepareSrc(src, key), src, this.orderOfFetch);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
return
|
|
57
|
+
return this._hashMap;
|
|
58
|
+
}
|
|
59
|
+
constructor() { }
|
|
60
|
+
getAssetByKey(key, defaultValue) {
|
|
61
|
+
const resource = this.hashMap[key] ?? null;
|
|
62
|
+
return resource === null ? defaultValue : resource.getCacheUri();
|
|
58
63
|
}
|
|
59
|
-
_assets = undefined;
|
|
60
64
|
rawMapGetter() {
|
|
61
65
|
return {};
|
|
62
66
|
}
|
|
63
|
-
get __assets() {
|
|
64
|
-
if (this._assets == null) {
|
|
65
|
-
const map = this.rawMapGetter();
|
|
66
|
-
this._assets = new Array();
|
|
67
|
-
for (let key in map) {
|
|
68
|
-
let src = map[key];
|
|
69
|
-
this._assets.push(new Resource(key, this.prepareSrc(src, key), src, this.orderOfFetch));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return this._assets;
|
|
73
|
-
}
|
|
74
67
|
prepareSrc(src, key) {
|
|
75
68
|
return src;
|
|
76
69
|
}
|
|
77
70
|
onCacheDone() { }
|
|
78
71
|
[Symbol.iterator]() {
|
|
79
72
|
let pointer = 0;
|
|
80
|
-
const
|
|
73
|
+
const resources = Object.values(this.hashMap);
|
|
81
74
|
return {
|
|
82
75
|
next() {
|
|
83
|
-
if (pointer <
|
|
76
|
+
if (pointer < resources.length) {
|
|
84
77
|
return {
|
|
85
78
|
done: false,
|
|
86
|
-
value:
|
|
79
|
+
value: resources[pointer++],
|
|
87
80
|
};
|
|
88
81
|
}
|
|
89
82
|
else {
|