@remvst/game-navigation-core 1.5.0 → 1.6.0
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/game/game-params.js +0 -1
- package/lib/game/game-plugin.d.ts +1 -1
- package/lib/game/game-plugin.js +4 -8
- package/lib/game/game.d.ts +5 -5
- package/lib/game/game.js +8 -9
- package/lib/index.d.ts +25 -19
- package/lib/index.js +9 -3
- package/lib/interaction/inputs.d.ts +6 -6
- package/lib/interaction/inputs.js +3 -4
- package/lib/navigation/resolver.d.ts +1 -1
- package/lib/navigation/screen-stack.d.ts +4 -4
- package/lib/navigation/screen-stack.js +1 -2
- package/lib/plugins/automation-game-plugin.js +7 -6
- package/lib/plugins/blur-pausing-game-plugin.js +3 -3
- package/lib/plugins/fullscreen-button-game-plugin.js +6 -6
- package/lib/plugins/metrics-game-plugin.d.ts +13 -0
- package/lib/plugins/metrics-game-plugin.js +47 -0
- package/lib/plugins/storage-game-plugin.js +1 -1
- package/lib/plugins/time-keys-game-plugin.js +1 -1
- package/lib/plugins/version-label-game-plugin.d.ts +2 -0
- package/lib/plugins/version-label-game-plugin.js +28 -17
- package/lib/storage/get-client-storage.js +3 -3
- package/lib/storage/in-memory-storage.js +1 -1
- package/lib/storage/local-json-store.js +0 -1
- package/lib/tracking/framerate-counts.d.ts +10 -0
- package/lib/tracking/framerate-counts.js +47 -0
- package/lib/tracking/properties-provider.d.ts +4 -0
- package/lib/tracking/properties-provider.js +2 -0
- package/lib/tracking/tracker.d.ts +7 -0
- package/lib/tracking/tracker.js +2 -0
- package/lib/tracking/tracking-screen-delegate.d.ts +14 -0
- package/lib/tracking/tracking-screen-delegate.js +38 -0
- package/lib/ui/screen.d.ts +4 -4
- package/lib/ui/screen.js +3 -3
- package/lib/util/math.js +0 -1
- package/lib/util/navigation-flow.d.ts +1 -0
- package/lib/util/navigation-flow.js +12 -0
- package/package.json +1 -1
- package/src/game/game-params.ts +1 -1
- package/src/game/game-plugin.ts +5 -14
- package/src/game/game.ts +23 -17
- package/src/index.ts +26 -19
- package/src/interaction/inputs.ts +43 -23
- package/src/interaction/screen-mouse-inputs.ts +7 -3
- package/src/navigation/resolver.ts +3 -6
- package/src/navigation/screen-stack.ts +15 -12
- package/src/plugins/automation-game-plugin.ts +8 -8
- package/src/plugins/blur-pausing-game-plugin.ts +3 -4
- package/src/plugins/fullscreen-button-game-plugin.ts +11 -7
- package/src/plugins/metrics-game-plugin.ts +65 -0
- package/src/plugins/storage-game-plugin.ts +1 -1
- package/src/plugins/time-keys-game-plugin.ts +7 -6
- package/src/plugins/version-label-game-plugin.ts +30 -18
- package/src/storage/get-client-storage.ts +4 -4
- package/src/storage/in-memory-storage.ts +1 -3
- package/src/storage/local-json-store.ts +10 -12
- package/src/tracking/framerate-counts.ts +50 -0
- package/src/tracking/properties-provider.ts +5 -0
- package/src/tracking/tracker.ts +6 -0
- package/src/tracking/tracking-screen-delegate.ts +48 -0
- package/src/ui/screen-delegate.ts +1 -1
- package/src/ui/screen.ts +29 -14
- package/src/util/math.ts +1 -1
- package/src/util/navigation-flow.ts +8 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrackingScreenDelegate = void 0;
|
|
4
|
+
class TrackingScreenDelegate {
|
|
5
|
+
constructor(screen, tracker) {
|
|
6
|
+
this.screen = screen;
|
|
7
|
+
this.tracker = tracker;
|
|
8
|
+
}
|
|
9
|
+
properties(extraProperties) {
|
|
10
|
+
const merged = {
|
|
11
|
+
"screen.id": this.screen.id,
|
|
12
|
+
"screen.age": this.screen.age,
|
|
13
|
+
};
|
|
14
|
+
Object.assign(merged, extraProperties);
|
|
15
|
+
const screenProperties = this.screen
|
|
16
|
+
.properties;
|
|
17
|
+
if (screenProperties) {
|
|
18
|
+
Object.assign(merged, screenProperties);
|
|
19
|
+
}
|
|
20
|
+
return merged;
|
|
21
|
+
}
|
|
22
|
+
track(eventName, extraProperties = {}) {
|
|
23
|
+
this.tracker.track(eventName, this.properties(extraProperties));
|
|
24
|
+
}
|
|
25
|
+
onSetup() {
|
|
26
|
+
this.track("screenSetup");
|
|
27
|
+
}
|
|
28
|
+
onForeground() {
|
|
29
|
+
this.track("screenForeground");
|
|
30
|
+
}
|
|
31
|
+
onBackground() {
|
|
32
|
+
this.track("screenBackground");
|
|
33
|
+
}
|
|
34
|
+
onDestroy() {
|
|
35
|
+
this.track("screenDestroy");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.TrackingScreenDelegate = TrackingScreenDelegate;
|
package/lib/ui/screen.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InterpolationPool } from
|
|
2
|
-
import { Game } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { InterpolationPool } from "@remvst/animate.js";
|
|
2
|
+
import { Game } from "../game/game";
|
|
3
|
+
import { ScreenInputs } from "../interaction/inputs";
|
|
4
|
+
import { ScreenDelegate } from "./screen-delegate";
|
|
5
5
|
export declare abstract class Screen {
|
|
6
6
|
game: Game;
|
|
7
7
|
cursorType: string;
|
package/lib/ui/screen.js
CHANGED
|
@@ -5,7 +5,7 @@ const animate_js_1 = require("@remvst/animate.js");
|
|
|
5
5
|
const inputs_1 = require("../interaction/inputs");
|
|
6
6
|
class Screen {
|
|
7
7
|
constructor() {
|
|
8
|
-
this.cursorType =
|
|
8
|
+
this.cursorType = "default";
|
|
9
9
|
this.age = 0;
|
|
10
10
|
this.frameCount = 0;
|
|
11
11
|
this.delegate = null;
|
|
@@ -111,8 +111,8 @@ class Screen {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
addDebugValues(values) {
|
|
114
|
-
values[
|
|
115
|
-
values[
|
|
114
|
+
values["screen.id"] = this.id;
|
|
115
|
+
values["screen.interpolations"] = this.interpolationPool.size;
|
|
116
116
|
}
|
|
117
117
|
get isForeground() {
|
|
118
118
|
return this.game && this.game.screenStack.current() === this;
|
package/lib/util/math.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function navigationFlow<T>(flow: Promise<T>): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.navigationFlow = void 0;
|
|
4
|
+
const resolver_1 = require("../navigation/resolver");
|
|
5
|
+
function navigationFlow(flow) {
|
|
6
|
+
flow.catch((err) => {
|
|
7
|
+
if (err instanceof resolver_1.UserCancelledError)
|
|
8
|
+
return;
|
|
9
|
+
console.error(err);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
exports.navigationFlow = navigationFlow;
|
package/package.json
CHANGED
package/src/game/game-params.ts
CHANGED
package/src/game/game-plugin.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { Screen } from "../ui/screen";
|
|
1
2
|
import { Game } from "./game";
|
|
2
|
-
import { Screen } from '../ui/screen';
|
|
3
3
|
|
|
4
4
|
export abstract class GamePlugin {
|
|
5
|
-
|
|
6
5
|
abstract get key(): string;
|
|
7
6
|
|
|
8
7
|
protected game: Game;
|
|
@@ -15,19 +14,11 @@ export abstract class GamePlugin {
|
|
|
15
14
|
this.game = game;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
setup(): void {
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
setup(): void {}
|
|
21
18
|
|
|
22
|
-
setupScreen(screen: Screen): void {
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
setupScreen(screen: Screen): void {}
|
|
25
20
|
|
|
26
|
-
cycle(elapsed: number) {
|
|
21
|
+
cycle(elapsed: number) {}
|
|
27
22
|
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
render() {
|
|
31
|
-
|
|
32
|
-
}
|
|
23
|
+
render() {}
|
|
33
24
|
}
|
package/src/game/game.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { PerformanceRecorder } from "@remvst/client-performance";
|
|
2
|
+
import { GameInputs } from "../interaction/inputs";
|
|
3
|
+
import { ScreenStack } from "../navigation/screen-stack";
|
|
4
|
+
import { GameParams } from "./game-params";
|
|
5
|
+
import { GamePlugin } from "./game-plugin";
|
|
6
6
|
|
|
7
7
|
export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
8
|
-
|
|
9
8
|
private readonly pluginMap = new Map<string, GamePlugin>();
|
|
10
9
|
|
|
11
10
|
// Inputs
|
|
@@ -24,7 +23,7 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
24
23
|
|
|
25
24
|
// Performance
|
|
26
25
|
readonly performanceRecorder = new PerformanceRecorder({
|
|
27
|
-
|
|
26
|
+
recordCount: Math.floor(window.innerWidth / 3),
|
|
28
27
|
});
|
|
29
28
|
|
|
30
29
|
constructor(readonly params: ParamsType) {
|
|
@@ -35,7 +34,9 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
35
34
|
|
|
36
35
|
abstract get container(): HTMLElement;
|
|
37
36
|
|
|
38
|
-
plugin<T extends GamePlugin>(
|
|
37
|
+
plugin<T extends GamePlugin>(
|
|
38
|
+
keyProvider: (new (...params: any) => T) & { key: string },
|
|
39
|
+
): T {
|
|
39
40
|
return this.pluginMap.get(keyProvider.key) as T;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -82,23 +83,26 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
82
83
|
|
|
83
84
|
frame() {
|
|
84
85
|
this.performanceRecorder.roll();
|
|
85
|
-
this.performanceRecorder.onStart(
|
|
86
|
+
this.performanceRecorder.onStart("FRAME");
|
|
86
87
|
|
|
87
88
|
const now = window.performance.now();
|
|
88
89
|
const elapsedMs = now - this.lastFrame;
|
|
89
|
-
const elapsed = Math.min(
|
|
90
|
+
const elapsed = Math.min(
|
|
91
|
+
this.params.maxFrameInterval || 1,
|
|
92
|
+
elapsedMs / 1000,
|
|
93
|
+
);
|
|
90
94
|
|
|
91
95
|
this.lastFrame = now;
|
|
92
96
|
|
|
93
97
|
this.cycle(elapsed);
|
|
94
98
|
|
|
95
|
-
this.performanceRecorder.onStart(
|
|
99
|
+
this.performanceRecorder.onStart("RENDER");
|
|
96
100
|
for (const plugin of this.plugins) {
|
|
97
101
|
plugin.render();
|
|
98
102
|
}
|
|
99
|
-
this.performanceRecorder.onEnd(
|
|
103
|
+
this.performanceRecorder.onEnd("RENDER");
|
|
100
104
|
|
|
101
|
-
this.performanceRecorder.onEnd(
|
|
105
|
+
this.performanceRecorder.onEnd("FRAME");
|
|
102
106
|
|
|
103
107
|
if (this.runningLoop) {
|
|
104
108
|
this.scheduleFrame();
|
|
@@ -136,15 +140,17 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
getDebugValues(out: {[key: string]: any}) {
|
|
143
|
+
getDebugValues(out: { [key: string]: any }) {
|
|
140
144
|
this.screenStack.current()?.addDebugValues(out);
|
|
141
145
|
}
|
|
142
146
|
|
|
143
147
|
private parseURL() {
|
|
144
|
-
const params = new URLSearchParams(
|
|
148
|
+
const params = new URLSearchParams(
|
|
149
|
+
(document.location.search || "?").substr(1),
|
|
150
|
+
);
|
|
145
151
|
for (const [param, originalValue] of params.entries()) {
|
|
146
152
|
let value = originalValue as any;
|
|
147
|
-
if (value ===
|
|
153
|
+
if (value === "true" || value === "false") {
|
|
148
154
|
value = JSON.parse(value);
|
|
149
155
|
} else if (!Number.isNaN(value)) {
|
|
150
156
|
value = parseFloat(value) || value;
|
|
@@ -158,4 +164,4 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
158
164
|
(window as any).S = this.screenStack.current();
|
|
159
165
|
this.container.style.cursor = this.screenStack.current()?.cursorType;
|
|
160
166
|
}
|
|
161
|
-
}
|
|
167
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./game/game";
|
|
2
|
+
export * from "./game/game-params";
|
|
3
|
+
export * from "./game/game-plugin";
|
|
4
4
|
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
5
|
+
export * from "./interaction/inputs";
|
|
6
|
+
export * from "./interaction/screen-mouse-inputs";
|
|
7
7
|
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
8
|
+
export * from "./navigation/resolver";
|
|
9
|
+
export * from "./navigation/screen-stack";
|
|
10
10
|
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
11
|
+
export * from "./ui/screen";
|
|
12
|
+
export * from "./ui/screen-delegate";
|
|
13
13
|
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
14
|
+
export * from "./plugins/automation-game-plugin";
|
|
15
|
+
export * from "./plugins/blur-pausing-game-plugin";
|
|
16
|
+
export * from "./plugins/fullscreen-button-game-plugin";
|
|
17
|
+
export * from "./plugins/metrics-game-plugin";
|
|
18
|
+
export * from "./plugins/storage-game-plugin";
|
|
19
|
+
export * from "./plugins/time-keys-game-plugin";
|
|
20
|
+
export * from "./plugins/version-label-game-plugin";
|
|
20
21
|
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
22
|
+
export * from "./storage/get-client-storage";
|
|
23
|
+
export * from "./storage/in-memory-storage";
|
|
24
|
+
export * from "./storage/local-json-store";
|
|
24
25
|
|
|
25
|
-
export * from
|
|
26
|
+
export * from "./tracking/framerate-counts";
|
|
27
|
+
export * from "./tracking/properties-provider";
|
|
28
|
+
export * from "./tracking/tracker";
|
|
29
|
+
export * from "./tracking/tracking-screen-delegate";
|
|
30
|
+
|
|
31
|
+
export * from "./util/math";
|
|
32
|
+
export * from "./util/navigation-flow";
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
DOMGamepadInputs,
|
|
3
|
+
DOMKeyboardInputs,
|
|
4
|
+
DOMMouseInputs,
|
|
5
|
+
Inputs,
|
|
6
|
+
} from "@remvst/client-inputs";
|
|
7
|
+
import GamepadInputs from "@remvst/client-inputs/lib/gamepad/gamepad-inputs";
|
|
8
|
+
import KeyboardInputs from "@remvst/client-inputs/lib/keyboard/keyboard-inputs";
|
|
9
|
+
import { Game } from "../game/game";
|
|
10
|
+
import { Screen } from "../ui/screen";
|
|
11
|
+
import { between } from "../util/math";
|
|
12
|
+
import { ScreenMouseInputs } from "./screen-mouse-inputs";
|
|
8
13
|
|
|
9
14
|
export class ScreenInputs implements Inputs {
|
|
10
15
|
readonly keyboard = new KeyboardInputs();
|
|
11
16
|
readonly mouse = new ScreenMouseInputs(this.screen.game.params);
|
|
12
17
|
readonly gamepad = new GamepadInputs();
|
|
13
18
|
|
|
14
|
-
constructor(readonly screen: Screen) {
|
|
15
|
-
|
|
16
|
-
}
|
|
19
|
+
constructor(readonly screen: Screen) {}
|
|
17
20
|
|
|
18
21
|
setup() {
|
|
19
22
|
this.keyboard.setup();
|
|
@@ -42,20 +45,28 @@ export class GameInputs implements Inputs {
|
|
|
42
45
|
constructor(private readonly game: Game) {
|
|
43
46
|
this.keyboard.onKeyDown = (keyCode: number) => {
|
|
44
47
|
this.makeGamepadInactive();
|
|
45
|
-
this.loopScreens((inputs) =>
|
|
48
|
+
this.loopScreens((inputs) =>
|
|
49
|
+
inputs.keyboard.setDown(keyCode, true),
|
|
50
|
+
);
|
|
46
51
|
};
|
|
47
52
|
this.keyboard.onKeyUp = (keyCode: number) => {
|
|
48
53
|
this.makeGamepadInactive();
|
|
49
|
-
this.loopScreens((inputs) =>
|
|
54
|
+
this.loopScreens((inputs) =>
|
|
55
|
+
inputs.keyboard.setDown(keyCode, false),
|
|
56
|
+
);
|
|
50
57
|
};
|
|
51
58
|
|
|
52
59
|
this.mouse.onMouseDown = (button) => {
|
|
53
60
|
this.makeGamepadInactive();
|
|
54
|
-
this.loopScreens((inputs) =>
|
|
61
|
+
this.loopScreens((inputs) =>
|
|
62
|
+
inputs.mouse.setButtonDown(button, true),
|
|
63
|
+
);
|
|
55
64
|
};
|
|
56
65
|
this.mouse.onMouseUp = (button) => {
|
|
57
66
|
this.makeGamepadInactive();
|
|
58
|
-
this.loopScreens((inputs) =>
|
|
67
|
+
this.loopScreens((inputs) =>
|
|
68
|
+
inputs.mouse.setButtonDown(button, false),
|
|
69
|
+
);
|
|
59
70
|
};
|
|
60
71
|
this.mouse.onWheel = (x, y, z) => {
|
|
61
72
|
this.makeGamepadInactive();
|
|
@@ -66,14 +77,23 @@ export class GameInputs implements Inputs {
|
|
|
66
77
|
this.makeGamepadInactive();
|
|
67
78
|
|
|
68
79
|
const x = between(0, this.mouse.position.x, this.game.params.width);
|
|
69
|
-
const y = between(
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
const y = between(
|
|
81
|
+
0,
|
|
82
|
+
this.mouse.position.y,
|
|
83
|
+
this.game.params.height,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
this.loopScreens((inputs) =>
|
|
87
|
+
inputs.mouse.setMousePosition(x, y, movementX, movementY),
|
|
88
|
+
);
|
|
72
89
|
};
|
|
73
90
|
|
|
74
|
-
this.gamepad.onButtonDown = (button) =>
|
|
75
|
-
|
|
76
|
-
this.gamepad.
|
|
91
|
+
this.gamepad.onButtonDown = (button) =>
|
|
92
|
+
this.loopScreens((inputs) => inputs.gamepad.setDown(button, true));
|
|
93
|
+
this.gamepad.onButtonUp = (button) =>
|
|
94
|
+
this.loopScreens((inputs) => inputs.gamepad.setDown(button, false));
|
|
95
|
+
this.gamepad.onAxisUpdated = (axis, value) =>
|
|
96
|
+
this.loopScreens((inputs) => inputs.gamepad.setAxis(axis, value));
|
|
77
97
|
}
|
|
78
98
|
|
|
79
99
|
setup() {
|
|
@@ -81,7 +101,7 @@ export class GameInputs implements Inputs {
|
|
|
81
101
|
this.mouse.setup();
|
|
82
102
|
this.gamepad.setup();
|
|
83
103
|
|
|
84
|
-
window.addEventListener(
|
|
104
|
+
window.addEventListener("blur", () => this.reset(), false);
|
|
85
105
|
}
|
|
86
106
|
|
|
87
107
|
reset() {
|
|
@@ -102,7 +122,7 @@ export class GameInputs implements Inputs {
|
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
private loopScreens(func: (inputs: Inputs) => void) {
|
|
105
|
-
for (let i = this.game.screenStack.screens.length - 1
|
|
125
|
+
for (let i = this.game.screenStack.screens.length - 1; i >= 0; i--) {
|
|
106
126
|
const screen = this.game.screenStack.screens[i];
|
|
107
127
|
func(screen.inputs);
|
|
108
128
|
|
|
@@ -115,4 +135,4 @@ export class GameInputs implements Inputs {
|
|
|
115
135
|
preventDefault() {
|
|
116
136
|
this.keyboard.preventDefault();
|
|
117
137
|
}
|
|
118
|
-
}
|
|
138
|
+
}
|
|
@@ -2,12 +2,16 @@ import MouseInputs from "@remvst/client-inputs/lib/mouse/mouse-inputs";
|
|
|
2
2
|
import { between } from "../util/math";
|
|
3
3
|
|
|
4
4
|
export class ScreenMouseInputs extends MouseInputs {
|
|
5
|
-
|
|
6
|
-
constructor(private readonly size: {width: number, height: number}) {
|
|
5
|
+
constructor(private readonly size: { width: number; height: number }) {
|
|
7
6
|
super();
|
|
8
7
|
}
|
|
9
8
|
|
|
10
|
-
setMousePosition(
|
|
9
|
+
setMousePosition(
|
|
10
|
+
x: number,
|
|
11
|
+
y: number,
|
|
12
|
+
movementX: number,
|
|
13
|
+
movementY: number,
|
|
14
|
+
): void {
|
|
11
15
|
if (document.pointerLockElement) {
|
|
12
16
|
super.setMousePosition(
|
|
13
17
|
between(0, this.position.x + movementX, this.size.width),
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { Screen } from
|
|
1
|
+
import { Screen } from "../ui/screen";
|
|
2
2
|
|
|
3
|
-
export class UserCancelledError extends Error {
|
|
4
|
-
|
|
5
|
-
}
|
|
3
|
+
export class UserCancelledError extends Error {}
|
|
6
4
|
|
|
7
5
|
export class Resolver<T> {
|
|
8
|
-
|
|
9
6
|
private readonly screen: Screen;
|
|
10
7
|
readonly resolve: (value: T) => void;
|
|
11
8
|
readonly reject: (error: Error) => void;
|
|
@@ -16,7 +13,7 @@ export class Resolver<T> {
|
|
|
16
13
|
constructor(
|
|
17
14
|
screen: Screen,
|
|
18
15
|
resolve: (value: T) => void,
|
|
19
|
-
reject: (error: Error) => void
|
|
16
|
+
reject: (error: Error) => void,
|
|
20
17
|
) {
|
|
21
18
|
this.screen = screen;
|
|
22
19
|
this.resolve = (value) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { OperationQueue } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { OperationQueue } from "@remvst/optimization";
|
|
2
|
+
import { Game } from "../game/game";
|
|
3
|
+
import { Screen } from "../ui/screen";
|
|
4
|
+
import { Resolver, ResolverHolder } from "./resolver";
|
|
5
5
|
|
|
6
6
|
export enum NavigationType {
|
|
7
7
|
RESET,
|
|
@@ -10,17 +10,18 @@ export enum NavigationType {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class ScreenStack {
|
|
13
|
-
|
|
14
13
|
readonly screens: Screen[] = [];
|
|
15
14
|
private readonly queue = new OperationQueue();
|
|
16
15
|
prepareScreen: (screen: Screen) => void = () => {};
|
|
17
16
|
|
|
18
|
-
constructor(private readonly game: Game) {
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
constructor(private readonly game: Game) {}
|
|
21
18
|
|
|
22
|
-
findByType<T extends Screen>(
|
|
23
|
-
|
|
19
|
+
findByType<T extends Screen>(
|
|
20
|
+
screenType: new (...params: any) => T,
|
|
21
|
+
): T | null {
|
|
22
|
+
return (
|
|
23
|
+
(this.screens.find((scr) => scr instanceof screenType) as T) || null
|
|
24
|
+
);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
current() {
|
|
@@ -102,11 +103,13 @@ export class ScreenStack {
|
|
|
102
103
|
this.reset(screen);
|
|
103
104
|
break;
|
|
104
105
|
case NavigationType.REPLACE_EXISTING:
|
|
105
|
-
const existing = this.findByType(
|
|
106
|
+
const existing = this.findByType(
|
|
107
|
+
screen.constructor as new (...params: any) => Screen,
|
|
108
|
+
) as Screen;
|
|
106
109
|
if (existing) this.popTo(existing, true);
|
|
107
110
|
this.push(screen);
|
|
108
111
|
break;
|
|
109
112
|
}
|
|
110
113
|
});
|
|
111
114
|
}
|
|
112
|
-
}
|
|
115
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { GamePlugin } from "../game/game-plugin";
|
|
2
2
|
|
|
3
3
|
export class AutomationGamePlugin extends GamePlugin {
|
|
4
|
-
|
|
5
|
-
static readonly key = 'automation';
|
|
4
|
+
static readonly key = "automation";
|
|
6
5
|
readonly key = AutomationGamePlugin.key;
|
|
7
6
|
|
|
8
7
|
// Debug
|
|
@@ -19,8 +18,8 @@ export class AutomationGamePlugin extends GamePlugin {
|
|
|
19
18
|
setup(): void {
|
|
20
19
|
super.setup();
|
|
21
20
|
|
|
22
|
-
this.automationLabel = document.createElement(
|
|
23
|
-
this.automationLabel.id =
|
|
21
|
+
this.automationLabel = document.createElement("div");
|
|
22
|
+
this.automationLabel.id = "automation-label";
|
|
24
23
|
document.body.appendChild(this.automationLabel);
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -32,13 +31,14 @@ export class AutomationGamePlugin extends GamePlugin {
|
|
|
32
31
|
this.automationLabel.innerText = JSON.stringify(automation);
|
|
33
32
|
|
|
34
33
|
// Disable all CSS animations for automation
|
|
35
|
-
const styleElement = document.createElement(
|
|
36
|
-
styleElement.setAttribute(
|
|
37
|
-
styleElement.innerHTML =
|
|
34
|
+
const styleElement = document.createElement("style");
|
|
35
|
+
styleElement.setAttribute("id", "style-tag");
|
|
36
|
+
styleElement.innerHTML =
|
|
37
|
+
"*,:after,:before,.animate-in{transition:none!important;animation:none!important;}";
|
|
38
38
|
document.head.appendChild(styleElement);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
getAutomationValues(out: {[key: string]: any}) {
|
|
41
|
+
getAutomationValues(out: { [key: string]: any }) {
|
|
42
42
|
this.game.getDebugValues(out);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { GamePlugin } from "../game/game-plugin";
|
|
2
2
|
|
|
3
3
|
export class BlurPausingGamePlugin extends GamePlugin {
|
|
4
|
-
|
|
5
|
-
static readonly key = 'blur-pausing-game';
|
|
4
|
+
static readonly key = "blur-pausing-game";
|
|
6
5
|
readonly key = BlurPausingGamePlugin.key;
|
|
7
6
|
|
|
8
7
|
private _enabled = true;
|
|
@@ -19,8 +18,8 @@ export class BlurPausingGamePlugin extends GamePlugin {
|
|
|
19
18
|
setup(): void {
|
|
20
19
|
super.setup();
|
|
21
20
|
|
|
22
|
-
window.addEventListener(
|
|
23
|
-
window.addEventListener(
|
|
21
|
+
window.addEventListener("blur", () => this.updateLoop(), false);
|
|
22
|
+
window.addEventListener("focus", () => this.updateLoop(), false);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
private updateLoop() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { GamePlugin } from "../game/game-plugin";
|
|
2
2
|
|
|
3
|
-
const ICON_DATA =
|
|
3
|
+
const ICON_DATA =
|
|
4
|
+
"iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9bpSIVQYuIOASsulgQFXHUKhShQqgVWnUwufQLmjQkKS6OgmvBwY/FqoOLs64OroIg+AHi6OSk6CIl/i8ptIjx4Lgf7+497t4B/lqJqWbbOKBqlpGMx4R0ZlUIviKEHvRhFEMSM/U5UUzAc3zdw8fXuyjP8j735+hSsiYDfALxLNMNi3iDeHrT0jnvE4dZQVKIz4nHDLog8SPXZZffOOcd9vPMsJFKzhOHiYV8C8stzAqGSjxFHFFUjfL9aZcVzluc1VKFNe7JXxjKaivLXKc5iDgWsQQRAmRUUEQJFqK0aqSYSNJ+zMM/4PhFcsnkKoKRYwFlqJAcP/gf/O7WzE1OuEmhGND+Ytsfw0BwF6hXbfv72LbrJ0DgGbjSmv5yDZj5JL3a1CJHQPc2cHHd1OQ94HIH6H/SJUNypABNfy4HvJ/RN2WA3lugc83trbGP0wcgRV0lboCDQ2AkT9nrHu/uaO3t3zON/n4AqiVyvXIak4gAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfnAgQQGhZq6KlXAAAAK0lEQVQY02P8////fwYoYGRkZGRAAshyqBwc4P////+ZGIYToLqvGYkNcAAblh/vxNHP4AAAAABJRU5ErkJggg==";
|
|
4
5
|
|
|
5
6
|
export class FullscreenButtonGamePlugin extends GamePlugin {
|
|
6
|
-
|
|
7
|
-
static readonly key = 'fullscreen-button';
|
|
7
|
+
static readonly key = "fullscreen-button";
|
|
8
8
|
readonly key = FullscreenButtonGamePlugin.key;
|
|
9
9
|
|
|
10
10
|
constructor(private readonly container: HTMLElement) {
|
|
@@ -14,7 +14,7 @@ export class FullscreenButtonGamePlugin extends GamePlugin {
|
|
|
14
14
|
setup(): void {
|
|
15
15
|
super.setup();
|
|
16
16
|
|
|
17
|
-
const styleElt = document.createElement(
|
|
17
|
+
const styleElt = document.createElement("style");
|
|
18
18
|
styleElt.innerHTML = `
|
|
19
19
|
.fullscreen-button {
|
|
20
20
|
position: absolute;
|
|
@@ -38,9 +38,13 @@ export class FullscreenButtonGamePlugin extends GamePlugin {
|
|
|
38
38
|
`;
|
|
39
39
|
document.head.appendChild(styleElt);
|
|
40
40
|
|
|
41
|
-
const button = document.createElement(
|
|
42
|
-
button.className =
|
|
43
|
-
button.addEventListener(
|
|
41
|
+
const button = document.createElement("div");
|
|
42
|
+
button.className = "fullscreen-button";
|
|
43
|
+
button.addEventListener(
|
|
44
|
+
"click",
|
|
45
|
+
() => document.body.requestFullscreen(),
|
|
46
|
+
false,
|
|
47
|
+
);
|
|
44
48
|
this.container.appendChild(button);
|
|
45
49
|
}
|
|
46
50
|
}
|