@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.
Files changed (53) hide show
  1. package/lib/game/game-params.js +0 -1
  2. package/lib/game/game-plugin.d.ts +1 -1
  3. package/lib/game/game-plugin.js +4 -8
  4. package/lib/game/game.d.ts +5 -5
  5. package/lib/game/game.js +8 -9
  6. package/lib/index.d.ts +20 -15
  7. package/lib/index.js +7 -2
  8. package/lib/interaction/inputs.d.ts +6 -6
  9. package/lib/interaction/inputs.js +3 -4
  10. package/lib/navigation/resolver.d.ts +1 -1
  11. package/lib/navigation/screen-stack.d.ts +4 -4
  12. package/lib/navigation/screen-stack.js +1 -2
  13. package/lib/plugins/automation-game-plugin.js +7 -6
  14. package/lib/plugins/blur-pausing-game-plugin.js +3 -3
  15. package/lib/plugins/fullscreen-button-game-plugin.js +6 -6
  16. package/lib/plugins/storage-game-plugin.d.ts +7 -0
  17. package/lib/plugins/storage-game-plugin.js +15 -0
  18. package/lib/plugins/time-keys-game-plugin.js +1 -1
  19. package/lib/plugins/version-label-game-plugin.d.ts +2 -0
  20. package/lib/plugins/version-label-game-plugin.js +28 -17
  21. package/lib/storage/get-client-storage.d.ts +1 -0
  22. package/lib/storage/get-client-storage.js +20 -0
  23. package/lib/storage/in-memory-storage.d.ts +9 -0
  24. package/lib/storage/in-memory-storage.js +27 -0
  25. package/lib/storage/local-json-store.d.ts +16 -0
  26. package/lib/storage/local-json-store.js +58 -0
  27. package/lib/ui/screen.d.ts +4 -4
  28. package/lib/ui/screen.js +3 -3
  29. package/lib/util/math.js +0 -1
  30. package/lib/util/navigation-flow.d.ts +1 -0
  31. package/lib/util/navigation-flow.js +12 -0
  32. package/package.json +1 -1
  33. package/src/game/game-params.ts +1 -1
  34. package/src/game/game-plugin.ts +5 -14
  35. package/src/game/game.ts +23 -17
  36. package/src/index.ts +21 -15
  37. package/src/interaction/inputs.ts +43 -23
  38. package/src/interaction/screen-mouse-inputs.ts +7 -3
  39. package/src/navigation/resolver.ts +3 -6
  40. package/src/navigation/screen-stack.ts +15 -12
  41. package/src/plugins/automation-game-plugin.ts +8 -8
  42. package/src/plugins/blur-pausing-game-plugin.ts +3 -4
  43. package/src/plugins/fullscreen-button-game-plugin.ts +11 -7
  44. package/src/plugins/storage-game-plugin.ts +9 -0
  45. package/src/plugins/time-keys-game-plugin.ts +7 -6
  46. package/src/plugins/version-label-game-plugin.ts +30 -18
  47. package/src/storage/get-client-storage.ts +17 -0
  48. package/src/storage/in-memory-storage.ts +27 -0
  49. package/src/storage/local-json-store.ts +58 -0
  50. package/src/ui/screen-delegate.ts +1 -1
  51. package/src/ui/screen.ts +29 -14
  52. package/src/util/math.ts +1 -1
  53. 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
+ }
@@ -3,4 +3,4 @@ export interface ScreenDelegate {
3
3
  onForeground(): void;
4
4
  onBackground(): void;
5
5
  onDestroy(): void;
6
- }
6
+ }
package/src/ui/screen.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { InterpolationPool } from '@remvst/animate.js';
2
- import { Game } from '../game/game';
3
- import { ScreenDelegate } from './screen-delegate';
4
- import { ScreenInputs } from '../interaction/inputs';
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 = 'default';
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) => this.mouseDown(button, this.inputs.mouse.position.x, this.inputs.mouse.position.y);
46
- this.inputs.mouse.onMouseUp = (button) => this.mouseUp(button, this.inputs.mouse.position.x, this.inputs.mouse.position.y);
47
- this.inputs.mouse.onMouseMove = (movementX, movementY) => this.mouseMove(this.inputs.mouse.position.x, this.inputs.mouse.position.y, movementX, movementY);
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['screen.id'] = this.id;
149
- values['screen.interpolations'] = this.interpolationPool.size;
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 ; i >= 0 ; i--) {
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 ; i >= 0 ; i--) {
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
@@ -2,4 +2,4 @@ export function between(a: number, b: number, c: number) {
2
2
  if (b < a) return a;
3
3
  if (b > c) return c;
4
4
  return b;
5
- };
5
+ }
@@ -0,0 +1,8 @@
1
+ import { UserCancelledError } from "../navigation/resolver";
2
+
3
+ export function navigationFlow<T>(flow: Promise<T>) {
4
+ flow.catch((err) => {
5
+ if (err instanceof UserCancelledError) return;
6
+ console.error(err);
7
+ });
8
+ }