wgge 2.0.33 → 2.0.37
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/ActivatedTreeNode.js +37 -25
- package/core/controller/TimeoutController.js +1 -1
- package/core/helper/DOMHelper.js +2 -1
- package/core/model/event/EventManager.js +19 -16
- package/core/model/event/NodeWithEvents.js +2 -2
- package/core/model/value/BoolValue.js +4 -0
- package/package.json +1 -1
- package/core/controller/ControllerWithSaveGame.js +0 -27
|
@@ -20,11 +20,11 @@ export default class ActivatedTreeNode {
|
|
|
20
20
|
/**
|
|
21
21
|
* @type boolean
|
|
22
22
|
*/
|
|
23
|
-
isRemoved= false;
|
|
23
|
+
isRemoved = false;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
27
|
-
* @type array
|
|
27
|
+
* @type array|null
|
|
28
28
|
* @type param.node {ModelNode}
|
|
29
29
|
* @type param.event {string}
|
|
30
30
|
* @type param.handler {(ep) => any}
|
|
@@ -107,23 +107,29 @@ export default class ActivatedTreeNode {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
activate() {
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
if (this.isActivated) return;
|
|
111
|
+
|
|
112
|
+
this.activateInternal();
|
|
113
|
+
|
|
114
|
+
if (this.autoRegisterEvents) {
|
|
115
|
+
const events = this.autoRegisterEvents;
|
|
116
|
+
for (let i = 0, max = events.length; i < max; i++) {
|
|
117
|
+
const event = events[i];
|
|
118
|
+
event.node.addEventListener(event.name, event.handler);
|
|
119
|
+
if (event.runOnActivate) {
|
|
120
|
+
event.handler();
|
|
121
|
+
}
|
|
120
122
|
}
|
|
123
|
+
}
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.afterActivatedInternal();
|
|
125
|
+
const children = this.children;
|
|
126
|
+
for (let i = 0, max = children.length; i < max; i++) {
|
|
127
|
+
children[i].activate();
|
|
126
128
|
}
|
|
129
|
+
|
|
130
|
+
this.isActivated = true;
|
|
131
|
+
this.afterActivatedInternal();
|
|
132
|
+
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
activateInternal() {
|
|
@@ -135,17 +141,23 @@ export default class ActivatedTreeNode {
|
|
|
135
141
|
}
|
|
136
142
|
|
|
137
143
|
deactivate() {
|
|
138
|
-
if (this.isActivated)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
if (!this.isActivated) return;
|
|
145
|
+
|
|
146
|
+
if (this.autoRegisterEvents) {
|
|
147
|
+
const events = this.autoRegisterEvents;
|
|
148
|
+
for (let i = 0, max = events.length; i < max; i++) {
|
|
149
|
+
const event = events[i];
|
|
150
|
+
event.node.removeEventListener(event.name, event.handler);
|
|
143
151
|
}
|
|
152
|
+
}
|
|
144
153
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
const children = this.children;
|
|
155
|
+
for (let i = 0, max = children.length; i < max; i++) {
|
|
156
|
+
children[i].deactivate();
|
|
148
157
|
}
|
|
158
|
+
|
|
159
|
+
this.deactivateInternal();
|
|
160
|
+
this.isActivated = false;
|
|
149
161
|
}
|
|
150
162
|
|
|
151
163
|
deactivateInternal() {
|
|
@@ -170,7 +182,7 @@ export default class ActivatedTreeNode {
|
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
addAutoEvents(node, events, handler, runOnActivate = false) {
|
|
173
|
-
events.forEach((event) => this.addAutoEvent(node, event, handler, runOnActivate));
|
|
185
|
+
events.forEach((event, i) => this.addAutoEvent(node, event, handler, i === 0 && runOnActivate));
|
|
174
186
|
}
|
|
175
187
|
|
|
176
188
|
addAutoEventMultiple(nodes, event, handler, runOnActivate = false) {
|
package/core/helper/DOMHelper.js
CHANGED
|
@@ -74,7 +74,8 @@ export default class DOMHelper {
|
|
|
74
74
|
return (document.fullscreenElement !== null) || (window.innerWidth === screen.width && window.innerHeight === screen.height);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
static openFullscreen(elem) {
|
|
77
|
+
static openFullscreen(elem = null) {
|
|
78
|
+
if (!elem) elem = document.body;
|
|
78
79
|
if (elem.requestFullscreen) {
|
|
79
80
|
elem.requestFullscreen();
|
|
80
81
|
} else if (elem.webkitRequestFullscreen) { /* Safari */
|
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
const DEBUG_EVENT_MANAGER = false;
|
|
2
2
|
|
|
3
3
|
export default class EventManager {
|
|
4
|
-
handlers;
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
this.handlers = [];
|
|
8
|
-
}
|
|
5
|
+
handlers = new Map();
|
|
9
6
|
|
|
10
7
|
addEventListener(eventName, eventHandler) {
|
|
11
|
-
if (!this.handlers
|
|
12
|
-
this.handlers
|
|
8
|
+
if (!this.handlers.has(eventName)) {
|
|
9
|
+
this.handlers.add(eventName, [eventHandler]);
|
|
10
|
+
return;
|
|
13
11
|
}
|
|
12
|
+
/*
|
|
14
13
|
const index = this.handlers[eventName].indexOf(eventHandler);
|
|
15
14
|
if (index >= 0) {
|
|
16
15
|
if (DEBUG_EVENT_MANAGER) console.log('Event listener already registered.');
|
|
17
16
|
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
}*/
|
|
18
|
+
const handlers = this.handlers.get(eventName);
|
|
19
|
+
handlers.push(eventHandler);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
removeEventListener(eventName, eventHandler) {
|
|
23
|
-
if (!this.handlers
|
|
24
|
-
|
|
23
|
+
if (!this.handlers.has(eventName)) {
|
|
24
|
+
return;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const handlers = this.handlers.get(eventName);
|
|
27
|
+
const index = handlers.indexOf(eventHandler);
|
|
27
28
|
if (index >= 0) {
|
|
28
|
-
|
|
29
|
+
handlers.splice(index, 1);
|
|
29
30
|
} else {
|
|
30
31
|
if (DEBUG_EVENT_MANAGER) console.log('Event listener cannot be removed - not found.');
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
triggerEvent(eventName, param) {
|
|
35
|
-
if (!this.handlers
|
|
36
|
+
if (!this.handlers.has(eventName)) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
|
-
const handlers = [...this.handlers
|
|
39
|
-
handlers.
|
|
39
|
+
const handlers = [...this.handlers.get(eventName)];
|
|
40
|
+
for (let i = 0, max = handlers.length; i < max; i++) {
|
|
41
|
+
handlers[i](param);
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
reset() {
|
|
43
|
-
this.handlers
|
|
46
|
+
this.handlers.clear();
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
}
|
|
@@ -28,10 +28,10 @@ export default class NodeWithEvents {
|
|
|
28
28
|
this.eventManager.triggerEvent(eventName, param);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
/*
|
|
32
32
|
static isNodeWithEvents(node) {
|
|
33
33
|
if (!node) return false;
|
|
34
34
|
return (typeof node === 'object' && typeof node.addEventListener === 'function');
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
*/
|
|
37
37
|
}
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import ControllerWithTimeout from "./ControllerWithTimeout";
|
|
2
|
-
|
|
3
|
-
export default class ControllerWithSaveGame extends ControllerWithTimeout {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @type DemoSaveGameModel
|
|
7
|
-
*/
|
|
8
|
-
saveGame;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {DemoGameModel} game
|
|
12
|
-
* @param {ObjectModel} model
|
|
13
|
-
* @param {DemoSaveGameModel} saveGame
|
|
14
|
-
*/
|
|
15
|
-
constructor(game, model, saveGame = null) {
|
|
16
|
-
super(game, model);
|
|
17
|
-
if (!saveGame) {
|
|
18
|
-
saveGame = this.game.saveGame.get();
|
|
19
|
-
}
|
|
20
|
-
this.saveGame = saveGame;
|
|
21
|
-
|
|
22
|
-
if (!this.saveGame) {
|
|
23
|
-
console.error('no SaveGameModel provided for controller!');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|