wgge 2.0.6 → 2.0.8

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.
@@ -63,8 +63,9 @@ export default class Collection extends NodeWithEvents {
63
63
  return this.count() <= 0;
64
64
  }
65
65
 
66
- count() {
67
- return this.items.length;
66
+ count(filter = null) {
67
+ if (!filter) return this.items.length;
68
+ return this.items.reduce((prev, current) => filter(current) ? prev + 1 : prev, 0);
68
69
  }
69
70
 
70
71
  contains(item) {
@@ -36,7 +36,7 @@ export default class GameRenderer extends DomRenderer {
36
36
  this.addAutoEventMultiple(
37
37
  [
38
38
  this.model.assets.totalLoaders,
39
- this.model.assets.blockingLoaders,
39
+ this.model.assets.preloadingLoaders,
40
40
  this.model.assets.sessionTotalLoaders,
41
41
  this.model.assets.sessionFinishedLoaders
42
42
  ],
@@ -75,7 +75,7 @@ export default class GameRenderer extends DomRenderer {
75
75
  }
76
76
 
77
77
  updateLoading() {
78
- const isLoading = this.model.assets.blockingLoaders.get() > 0;
78
+ const isLoading = this.model.assets.totalLoaders.get() > 0;
79
79
  if (this.loading && !isLoading) {
80
80
  this.removeElement(this.loading);
81
81
  this.loading = null;
@@ -36,7 +36,7 @@ export default class AssetCache extends ObjectModel {
36
36
  /**
37
37
  * @type IntValue
38
38
  */
39
- blockingLoaders;
39
+ preloadingLoaders;
40
40
 
41
41
  /**
42
42
  * @type IntValue
@@ -62,7 +62,7 @@ export default class AssetCache extends ObjectModel {
62
62
  this.loaders = new Collection();
63
63
 
64
64
  this.totalLoaders = this.addProperty('totalLoaders', new IntValue(0));
65
- this.blockingLoaders = this.addProperty('blockingLoaders', new IntValue(0));
65
+ this.preloadingLoaders = this.addProperty('preloadingLoaders', new IntValue(0));
66
66
  this.sessionTotalLoaders = this.addProperty('sessionTotalLoaders', new IntValue(0));
67
67
  this.sessionFinishedLoaders = this.addProperty('sessionFinishedLoaders', new IntValue(0));
68
68
 
@@ -75,34 +75,28 @@ export default class AssetCache extends ObjectModel {
75
75
  this.loaderClasses.set(id, cls);
76
76
  }
77
77
 
78
+ updateLoadingState() {
79
+ this.totalLoaders.set(this.loaders.count());
80
+ this.preloadingLoaders.set(this.loaders.count((l) => l.isPreloading));
81
+ }
82
+
78
83
  loaderAdded(loader) {
79
- this.updateLoadingState();
80
- if (!loader.isPreloading) {
81
- this.sessionTotalLoaders.increase();
84
+ if (this.totalLoaders.equalsTo(0)) {
85
+ this.sessionFinishedLoaders.set(0);
86
+ this.sessionTotalLoaders.set(0);
82
87
  }
83
-
88
+ this.updateLoadingState();
89
+ this.sessionTotalLoaders.increase();
84
90
  }
85
91
 
86
92
  loaderRemoved(loader) {
87
93
  this.updateLoadingState();
88
- if (!loader.isPreloading) {
89
- this.sessionFinishedLoaders.increase();
90
- if (this.blockingLoaders.equalsTo(0)) {
91
- this.sessionFinishedLoaders.set(0);
92
- this.sessionTotalLoaders.set(0);
93
- }
94
- }
95
- }
96
-
97
- updateLoadingState() {
98
- this.totalLoaders.set(this.loaders.count());
99
- const blocking = this.loaders.filter((l) => l.isPreloading === false).length;
100
- this.blockingLoaders.set(blocking);
94
+ this.sessionFinishedLoaders.increase();
101
95
  }
102
96
 
103
- resetCache(name = null) {
104
- if (name) {
105
- this.cache.remove(name);
97
+ resetCache(uri = null) {
98
+ if (uri) {
99
+ this.cache.remove(uri);
106
100
  } else {
107
101
  this.cache.reset();
108
102
  }
@@ -114,14 +108,14 @@ export default class AssetCache extends ObjectModel {
114
108
  this.loaders.remove(loader);
115
109
  }
116
110
 
117
- loaderSucceeded(loader, resource, onLoaded) {
111
+ loaderSucceeded(loader, asset, onLoaded) {
118
112
  if (this.cache.exists(loader.uri)) {
119
- this.cache.set(loader.uri, resource);
120
- console.warn(`Resource ${loader.uri} was already present then loaded and replaced.`);
113
+ this.cache.set(loader.uri, asset);
114
+ console.warn(`Asset ${loader.uri} was already present then loaded and replaced.`);
121
115
  } else {
122
- this.cache.add(loader.uri, resource);
116
+ this.cache.add(loader.uri, asset);
123
117
  }
124
- if (onLoaded) onLoaded(resource);
118
+ if (onLoaded) onLoaded(asset);
125
119
  this.loaders.remove(loader);
126
120
  }
127
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgge",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "Web GL Game Engine",
5
5
  "main": "index.js",
6
6
  "devDependencies": {