@remvst/game-navigation-core 1.4.0 → 1.5.1
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 +20 -15
- package/lib/index.js +7 -2
- 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/storage-game-plugin.d.ts +7 -0
- package/lib/plugins/storage-game-plugin.js +15 -0
- 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.d.ts +1 -0
- package/lib/storage/get-client-storage.js +20 -0
- package/lib/storage/in-memory-storage.d.ts +9 -0
- package/lib/storage/in-memory-storage.js +27 -0
- package/lib/storage/local-json-store.d.ts +16 -0
- package/lib/storage/local-json-store.js +58 -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 +21 -15
- 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/storage-game-plugin.ts +9 -0
- 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 +17 -0
- package/src/storage/in-memory-storage.ts +27 -0
- package/src/storage/local-json-store.ts +58 -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,58 @@
|
|
|
1
|
+
export class StoredItem<T> {
|
|
2
|
+
constructor(
|
|
3
|
+
private readonly localJsonStore: LocalJsonStore,
|
|
4
|
+
readonly key: string,
|
|
5
|
+
) {}
|
|
6
|
+
|
|
7
|
+
get(): Promise<T | null> {
|
|
8
|
+
return this.localJsonStore.getItem(this.key);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
set(value: T): Promise<void> {
|
|
12
|
+
return this.localJsonStore.setItem(this.key, value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
delete(): Promise<void> {
|
|
16
|
+
return this.localJsonStore.deleteItem(this.key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class LocalJsonStore {
|
|
21
|
+
constructor(private readonly localStorage: Storage) {}
|
|
22
|
+
|
|
23
|
+
item<T>(key: string): StoredItem<T> {
|
|
24
|
+
return new StoredItem(this, key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async setItem(key: string, value: any): Promise<void> {
|
|
28
|
+
try {
|
|
29
|
+
this.localStorage.setItem(key, JSON.stringify(value));
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(`setItem error: ${err.message}`, err);
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async deleteItem(key: string): Promise<void> {
|
|
37
|
+
try {
|
|
38
|
+
this.localStorage.removeItem(key);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error(`deleteItem error: ${err.message}`, err);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getItem(key: string): Promise<any> {
|
|
46
|
+
try {
|
|
47
|
+
const stored = this.localStorage.getItem(key);
|
|
48
|
+
if (!stored) return null;
|
|
49
|
+
return JSON.parse(stored);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error(
|
|
52
|
+
`getItem error: ${err.message}. Falling back to null`,
|
|
53
|
+
err,
|
|
54
|
+
);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/ui/screen.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
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
|
|
|
6
6
|
export abstract class Screen {
|
|
7
|
-
|
|
8
7
|
game: Game;
|
|
9
|
-
cursorType: string =
|
|
8
|
+
cursorType: string = "default";
|
|
10
9
|
|
|
11
10
|
inputs: ScreenInputs;
|
|
12
11
|
age: number = 0;
|
|
@@ -42,9 +41,25 @@ export abstract class Screen {
|
|
|
42
41
|
this.inputs = new ScreenInputs(this);
|
|
43
42
|
this.inputs.keyboard.onKeyDown = (keyCode) => this.keyDown(keyCode);
|
|
44
43
|
this.inputs.keyboard.onKeyUp = (keyCode) => this.keyUp(keyCode);
|
|
45
|
-
this.inputs.mouse.onMouseDown = (button) =>
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
this.inputs.mouse.onMouseDown = (button) =>
|
|
45
|
+
this.mouseDown(
|
|
46
|
+
button,
|
|
47
|
+
this.inputs.mouse.position.x,
|
|
48
|
+
this.inputs.mouse.position.y,
|
|
49
|
+
);
|
|
50
|
+
this.inputs.mouse.onMouseUp = (button) =>
|
|
51
|
+
this.mouseUp(
|
|
52
|
+
button,
|
|
53
|
+
this.inputs.mouse.position.x,
|
|
54
|
+
this.inputs.mouse.position.y,
|
|
55
|
+
);
|
|
56
|
+
this.inputs.mouse.onMouseMove = (movementX, movementY) =>
|
|
57
|
+
this.mouseMove(
|
|
58
|
+
this.inputs.mouse.position.x,
|
|
59
|
+
this.inputs.mouse.position.y,
|
|
60
|
+
movementX,
|
|
61
|
+
movementY,
|
|
62
|
+
);
|
|
48
63
|
this.inputs.mouse.onWheel = (x, y, z) => this.wheel(x, y, z);
|
|
49
64
|
this.inputs.setup();
|
|
50
65
|
|
|
@@ -144,9 +159,9 @@ export abstract class Screen {
|
|
|
144
159
|
}
|
|
145
160
|
}
|
|
146
161
|
|
|
147
|
-
addDebugValues(values: {[key: string]: any}) {
|
|
148
|
-
values[
|
|
149
|
-
values[
|
|
162
|
+
addDebugValues(values: { [key: string]: any }) {
|
|
163
|
+
values["screen.id"] = this.id;
|
|
164
|
+
values["screen.interpolations"] = this.interpolationPool.size;
|
|
150
165
|
}
|
|
151
166
|
|
|
152
167
|
get isForeground() {
|
|
@@ -166,7 +181,7 @@ export abstract class Screen {
|
|
|
166
181
|
}
|
|
167
182
|
|
|
168
183
|
get isCycling() {
|
|
169
|
-
for (let i = this.game.screenStack.screens.length - 1
|
|
184
|
+
for (let i = this.game.screenStack.screens.length - 1; i >= 0; i--) {
|
|
170
185
|
const screen = this.game.screenStack.screens[i];
|
|
171
186
|
if (screen === this) return true;
|
|
172
187
|
if (screen.absorbCycle) return false;
|
|
@@ -175,7 +190,7 @@ export abstract class Screen {
|
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
get isTakingInputs() {
|
|
178
|
-
for (let i = this.game.screenStack.screens.length - 1
|
|
193
|
+
for (let i = this.game.screenStack.screens.length - 1; i >= 0; i--) {
|
|
179
194
|
const screen = this.game.screenStack.screens[i];
|
|
180
195
|
if (screen === this) return true;
|
|
181
196
|
if (screen.absorbInputs) return false;
|
package/src/util/math.ts
CHANGED