@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/game-navigation-core",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -3,4 +3,4 @@ export interface GameParams {
3
3
  height: number;
4
4
  maxFrameInterval?: number;
5
5
  fps?: number;
6
- };
6
+ }
@@ -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 { GameInputs } from '../interaction/inputs';
2
- import { GameParams } from './game-params';
3
- import { GamePlugin } from './game-plugin';
4
- import { ScreenStack } from '../navigation/screen-stack';
5
- import { PerformanceRecorder } from '@remvst/client-performance';
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
- 'recordCount': Math.floor(window.innerWidth / 3),
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>(keyProvider: (new (...params: any) => T) & {key: string}): T {
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('FRAME');
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(this.params.maxFrameInterval || 1, elapsedMs / 1000);
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('RENDER');
99
+ this.performanceRecorder.onStart("RENDER");
96
100
  for (const plugin of this.plugins) {
97
101
  plugin.render();
98
102
  }
99
- this.performanceRecorder.onEnd('RENDER');
103
+ this.performanceRecorder.onEnd("RENDER");
100
104
 
101
- this.performanceRecorder.onEnd('FRAME');
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((document.location.search || '?').substr(1));
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 === 'true' || value === 'false') {
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,20 +1,26 @@
1
- export * from './game/game-params';
2
- export * from './game/game-plugin';
3
- export * from './game/game';
1
+ export * from "./game/game";
2
+ export * from "./game/game-params";
3
+ export * from "./game/game-plugin";
4
4
 
5
- export * from './interaction/inputs';
6
- export * from './interaction/screen-mouse-inputs';
5
+ export * from "./interaction/inputs";
6
+ export * from "./interaction/screen-mouse-inputs";
7
7
 
8
- export * from './navigation/resolver';
9
- export * from './navigation/screen-stack';
8
+ export * from "./navigation/resolver";
9
+ export * from "./navigation/screen-stack";
10
10
 
11
- export * from './ui/screen-delegate';
12
- export * from './ui/screen';
11
+ export * from "./ui/screen";
12
+ export * from "./ui/screen-delegate";
13
13
 
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/time-keys-game-plugin';
18
- export * from './plugins/version-label-game-plugin';
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/storage-game-plugin";
18
+ export * from "./plugins/time-keys-game-plugin";
19
+ export * from "./plugins/version-label-game-plugin";
19
20
 
20
- export * from './util/math';
21
+ export * from "./storage/get-client-storage";
22
+ export * from "./storage/in-memory-storage";
23
+ export * from "./storage/local-json-store";
24
+
25
+ export * from "./util/math";
26
+ export * from "./util/navigation-flow";
@@ -1,19 +1,22 @@
1
- import { between } from '../util/math';
2
- import { ScreenMouseInputs } from './screen-mouse-inputs';
3
- import { DOMGamepadInputs, DOMKeyboardInputs, DOMMouseInputs, Inputs } from '@remvst/client-inputs';
4
- import GamepadInputs from '@remvst/client-inputs/lib/gamepad/gamepad-inputs';
5
- import KeyboardInputs from '@remvst/client-inputs/lib/keyboard/keyboard-inputs';
6
- import { Screen } from '../ui/screen';
7
- import { Game } from '../game/game';
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) => inputs.keyboard.setDown(keyCode, true));
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) => inputs.keyboard.setDown(keyCode, false));
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) => inputs.mouse.setButtonDown(button, true));
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) => inputs.mouse.setButtonDown(button, false));
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(0, this.mouse.position.y, this.game.params.height);
70
-
71
- this.loopScreens((inputs) => inputs.mouse.setMousePosition(x, y, movementX, movementY));
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) => this.loopScreens((inputs) => inputs.gamepad.setDown(button, true));
75
- this.gamepad.onButtonUp = (button) => this.loopScreens((inputs) => inputs.gamepad.setDown(button, false));
76
- this.gamepad.onAxisUpdated = (axis, value) => this.loopScreens((inputs) => inputs.gamepad.setAxis(axis, value));
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('blur', () => this.reset(), false);
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 ; i >= 0 ; i--) {
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(x: number, y: number, movementX: number, movementY: number): void {
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 '../ui/screen';
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 '@remvst/optimization';
2
- import { ResolverHolder, Resolver } from './resolver';
3
- import { Game } from '../game/game';
4
- import { Screen } from '../ui/screen';
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>(screenType: (new (...params: any) => T)): T | null {
23
- return (this.screens.find((scr) => scr instanceof screenType) as T) || null;
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(screen.constructor as new (...params: any) => Screen) as Screen;
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('div');
23
- this.automationLabel.id = 'automation-label';
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('style');
36
- styleElement.setAttribute('id','style-tag');
37
- styleElement.innerHTML = '*,:after,:before,.animate-in{transition:none!important;animation:none!important;}';
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('blur', () => this.updateLoop(), false);
23
- window.addEventListener('focus', () => this.updateLoop(), false);
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 = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9bpSIVQYuIOASsulgQFXHUKhShQqgVWnUwufQLmjQkKS6OgmvBwY/FqoOLs64OroIg+AHi6OSk6CIl/i8ptIjx4Lgf7+497t4B/lqJqWbbOKBqlpGMx4R0ZlUIviKEHvRhFEMSM/U5UUzAc3zdw8fXuyjP8j735+hSsiYDfALxLNMNi3iDeHrT0jnvE4dZQVKIz4nHDLog8SPXZZffOOcd9vPMsJFKzhOHiYV8C8stzAqGSjxFHFFUjfL9aZcVzluc1VKFNe7JXxjKaivLXKc5iDgWsQQRAmRUUEQJFqK0aqSYSNJ+zMM/4PhFcsnkKoKRYwFlqJAcP/gf/O7WzE1OuEmhGND+Ytsfw0BwF6hXbfv72LbrJ0DgGbjSmv5yDZj5JL3a1CJHQPc2cHHd1OQ94HIH6H/SJUNypABNfy4HvJ/RN2WA3lugc83trbGP0wcgRV0lboCDQ2AkT9nrHu/uaO3t3zON/n4AqiVyvXIak4gAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfnAgQQGhZq6KlXAAAAK0lEQVQY02P8////fwYoYGRkZGRAAshyqBwc4P////+ZGIYToLqvGYkNcAAblh/vxNHP4AAAAABJRU5ErkJggg==';
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('style');
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('div');
42
- button.className = 'fullscreen-button';
43
- button.addEventListener('click', () => document.body.requestFullscreen(), false);
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
  }
@@ -0,0 +1,9 @@
1
+ import { GamePlugin } from "../game/game-plugin";
2
+ import { getClientStorage } from "../storage/get-client-storage";
3
+ import { LocalJsonStore } from "../storage/local-json-store";
4
+
5
+ export class StorageGamePlugin extends GamePlugin {
6
+ static readonly key = "storage";
7
+ readonly key = StorageGamePlugin.key;
8
+ readonly localJsonStore = new LocalJsonStore(getClientStorage());
9
+ }
@@ -2,17 +2,18 @@ import { Keyboard } from "@remvst/client-inputs";
2
2
  import { GamePlugin } from "../game/game-plugin";
3
3
 
4
4
  export class TimeKeysGamePlugin extends GamePlugin {
5
-
6
- static readonly key = 'time-keys';
5
+ static readonly key = "time-keys";
7
6
  readonly key = TimeKeysGamePlugin.key;
8
7
 
9
8
  speedUpFactor: number;
10
9
  slowDownFactor: number;
11
10
 
12
- constructor(options: {
13
- speedUpFactor?: number,
14
- slowDownFactor?: number,
15
- } = {}) {
11
+ constructor(
12
+ options: {
13
+ speedUpFactor?: number;
14
+ slowDownFactor?: number;
15
+ } = {},
16
+ ) {
16
17
  super();
17
18
 
18
19
  this.speedUpFactor = options.speedUpFactor || 10;
@@ -1,14 +1,40 @@
1
1
  import { GamePlugin } from "../game/game-plugin";
2
2
 
3
3
  export class VersionLabelGamePlugin extends GamePlugin {
4
-
5
4
  static readonly key = "version-label";
6
5
  readonly key = VersionLabelGamePlugin.key;
7
6
 
7
+ readonly labelElement = (() => {
8
+ const label = document.createElement("div");
9
+ label.className = "version-label";
10
+ label.innerText = this.label;
11
+ return this.labelElement;
12
+ })();
13
+
14
+ readonly styleElement = (() => {
15
+ const styleElt = document.createElement("style");
16
+ styleElt.innerHTML = `
17
+ .version-label {
18
+ position: absolute;
19
+ z-index: 2;
20
+ margin: 10px;
21
+ color: #fff;
22
+ bottom: 0;
23
+ right: 0;
24
+ text-transform: uppercase;
25
+ text-shadow: 0px 2px 0px #000;
26
+ font-family: Courier;
27
+ font-size: 10px;
28
+ ${this.extraStyle}
29
+ }
30
+ `;
31
+ return styleElt;
32
+ })();
33
+
8
34
  constructor(
9
35
  private readonly container: HTMLElement,
10
36
  private readonly label: string,
11
- private readonly extraStyle: string = '',
37
+ private readonly extraStyle: string = "",
12
38
  ) {
13
39
  super();
14
40
  }
@@ -16,21 +42,7 @@ export class VersionLabelGamePlugin extends GamePlugin {
16
42
  setup(): void {
17
43
  super.setup();
18
44
 
19
- const button = document.createElement('div');
20
- button.innerText = this.label;
21
- button.style.cssText = `
22
- position: absolute;
23
- z-index: 2;
24
- margin: 10px;
25
- color: #fff;
26
- bottom: 0;
27
- right: 0;
28
- text-transform: uppercase;
29
- text-shadow: 0px 2px 0px #000;
30
- font-family: Courier;
31
- font-size: 10px;
32
- ${this.extraStyle}
33
- `;
34
- this.container.appendChild(button);
45
+ document.head.appendChild(this.styleElement);
46
+ this.container.appendChild(this.labelElement);
35
47
  }
36
48
  }
@@ -0,0 +1,17 @@
1
+ import { InMemoryStorage } from "./in-memory-storage";
2
+
3
+ export function getClientStorage(): Storage {
4
+ const options: [string, () => Storage][] = [
5
+ ["localStorage", () => window.localStorage],
6
+ ["sessionStorage", () => window.sessionStorage],
7
+ ["InMemoryStorage", () => new InMemoryStorage()],
8
+ ];
9
+
10
+ for (const [label, getter] of options) {
11
+ try {
12
+ return getter();
13
+ } catch (err) {
14
+ console.error(`Failed to get ${label}, falling back`);
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,27 @@
1
+ export class InMemoryStorage implements Storage {
2
+ private readonly items = new Map<string, string>();
3
+
4
+ get length(): number {
5
+ return this.items.size;
6
+ }
7
+
8
+ clear(): void {
9
+ this.items.clear();
10
+ }
11
+
12
+ getItem(key: string): string {
13
+ return this.items.get(key);
14
+ }
15
+
16
+ key(index: number): string {
17
+ throw new Error("Method not implemented.");
18
+ }
19
+
20
+ removeItem(key: string): void {
21
+ this.items.delete(key);
22
+ }
23
+
24
+ setItem(key: string, value: string): void {
25
+ this.items.set(key, value);
26
+ }
27
+ }