wgge 2.0.38 → 2.0.40

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.
@@ -7,61 +7,54 @@ import ChangeEvent from "./model/event/ChangeEvent";
7
7
  export default class Dictionary extends NodeWithEvents {
8
8
 
9
9
  /**
10
- * @type object
10
+ * @type Map
11
11
  */
12
- keyValues;
13
-
14
- constructor(init = {}) {
15
- super();
16
- this.keyValues = init;
17
- }
12
+ map= new Map();
18
13
 
19
14
  get(key) {
20
- return this.keyValues[key];
15
+ return this.map.get(key);
21
16
  }
22
17
 
23
18
  exists(key) {
24
- return (this.keyValues[key] !== undefined);
19
+ return this.map.has(key);
25
20
  }
26
21
 
27
- add(key, value = null) {
28
- return this.set(key, value);
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 = null) {
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
- remove(key) {
45
- if (!this.exists(key)) return;
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.keys().length;
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 Object.keys(this.keyValues);
65
+ return Array.from(this.map.keys());
73
66
  }
74
67
 
75
- forEach(func) {
76
- for (let key in this.keyValues) {
77
- func(key, this.keyValues[key]);
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 = null) {
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(url, onLoaded) {
162
- this.loadAsset(url, onLoaded);
161
+ loadImage(path, onLoaded) {
162
+ this.loadAsset(`img/${path}`, onLoaded);
163
163
  }
164
164
 
165
- loadAudio(materialId, onLoaded) {
166
- this.loadAsset(`mat/${materialId}`, onLoaded);
165
+ loadAudio(path, onLoaded) {
166
+ this.loadAsset(`aud/${path}`, onLoaded);
167
167
  }
168
168
 
169
- resetMaterial(materialId) {
170
- this.resetCache(`mat/${materialId}`);
169
+ preload(uris) {
170
+ console.log('Preloading:', uris);
171
+ uris.forEach((uri) => this.loadAsset(uri));
171
172
  }
172
173
 
173
- preload(resources) {
174
- console.log('Preloading:', resources);
175
- resources.forEach((r) => this.loadAsset(r));
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
  }
@@ -1,6 +1,7 @@
1
1
  import ControllerBase from "../../core/controller/ControllerBase";
2
2
 
3
3
  export default class ControlsController extends ControllerBase {
4
+
4
5
  dom;
5
6
 
6
7
  /**
@@ -29,7 +30,7 @@ export default class ControlsController extends ControllerBase {
29
30
 
30
31
  onKeyDown(event) {
31
32
  const key = event.keyCode ? event.keyCode : event.charCode;
32
- if (this.game.isInDebugMode.get()) console.log(key);
33
+ if (this.model.logPressedKeys.get()) console.log(key);
33
34
  this.model.triggerEvent(`key-down-${key}`);
34
35
  this.model.triggerEvent(`key-down`, key);
35
36
  }
@@ -47,7 +48,6 @@ export default class ControlsController extends ControllerBase {
47
48
  this.model.triggerEvent(`key-up-${key}`);
48
49
  this.model.triggerEvent(`key-up`, key);
49
50
  }
50
-
51
51
  }
52
52
 
53
53
  onMouseMove(e) {
@@ -10,6 +10,11 @@ export const EVENT_RIGHT_CLICK = 'right-click';
10
10
 
11
11
  export default class ControlsModel extends ObjectModel {
12
12
 
13
+ /**
14
+ * @type BoolValue
15
+ */
16
+ logPressedKeys;
17
+
13
18
  /**
14
19
  * @type BoolValue
15
20
  */
@@ -20,14 +25,24 @@ export default class ControlsModel extends ObjectModel {
20
25
  */
21
26
  mouseCoordinates;
22
27
 
28
+ /**
29
+ * @type BoolValue
30
+ */
23
31
  mouseDownLeft;
32
+
33
+ /**
34
+ * @type BoolValue
35
+ */
24
36
  mouseDownRight;
37
+
25
38
  leftClickTime;
39
+
26
40
  rightClickTime;
27
41
 
28
42
  constructor() {
29
43
  super();
30
44
 
45
+ this.logPressedKeys = this.addProperty('logPressedKeys', new BoolValue(false));
31
46
  this.isMouseOver = this.addProperty('isMouseOver', new BoolValue(false));
32
47
  this.mouseCoordinates = this.addProperty('mouseCoordinates', new Vector2());
33
48
  this.mouseDownLeft = this.addProperty('mouseDownLeft', new BoolValue(false));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgge",
3
- "version": "2.0.38",
3
+ "version": "2.0.40",
4
4
  "description": "Web GL Game Engine",
5
5
  "main": "index.js",
6
6
  "devDependencies": {