@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
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
@@ -1,5 +1,5 @@
1
+ import { Screen } from "../ui/screen";
1
2
  import { Game } from "./game";
2
- import { Screen } from '../ui/screen';
3
3
  export declare abstract class GamePlugin {
4
4
  abstract get key(): string;
5
5
  protected game: Game;
@@ -8,13 +8,9 @@ class GamePlugin {
8
8
  bind(game) {
9
9
  this.game = game;
10
10
  }
11
- setup() {
12
- }
13
- setupScreen(screen) {
14
- }
15
- cycle(elapsed) {
16
- }
17
- render() {
18
- }
11
+ setup() { }
12
+ setupScreen(screen) { }
13
+ cycle(elapsed) { }
14
+ render() { }
19
15
  }
20
16
  exports.GamePlugin = GamePlugin;
@@ -1,8 +1,8 @@
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
  export declare abstract class Game<ParamsType extends GameParams = GameParams> {
7
7
  readonly params: ParamsType;
8
8
  private readonly pluginMap;
package/lib/game/game.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Game = void 0;
4
+ const client_performance_1 = require("@remvst/client-performance");
4
5
  const inputs_1 = require("../interaction/inputs");
5
6
  const screen_stack_1 = require("../navigation/screen-stack");
6
- const client_performance_1 = require("@remvst/client-performance");
7
7
  class Game {
8
8
  constructor(params) {
9
9
  this.params = params;
@@ -13,7 +13,7 @@ class Game {
13
13
  this.runningLoop = false;
14
14
  // Performance
15
15
  this.performanceRecorder = new client_performance_1.PerformanceRecorder({
16
- 'recordCount': Math.floor(window.innerWidth / 3),
16
+ recordCount: Math.floor(window.innerWidth / 3),
17
17
  });
18
18
  this.parseURL();
19
19
  }
@@ -55,18 +55,18 @@ class Game {
55
55
  }
56
56
  frame() {
57
57
  this.performanceRecorder.roll();
58
- this.performanceRecorder.onStart('FRAME');
58
+ this.performanceRecorder.onStart("FRAME");
59
59
  const now = window.performance.now();
60
60
  const elapsedMs = now - this.lastFrame;
61
61
  const elapsed = Math.min(this.params.maxFrameInterval || 1, elapsedMs / 1000);
62
62
  this.lastFrame = now;
63
63
  this.cycle(elapsed);
64
- this.performanceRecorder.onStart('RENDER');
64
+ this.performanceRecorder.onStart("RENDER");
65
65
  for (const plugin of this.plugins) {
66
66
  plugin.render();
67
67
  }
68
- this.performanceRecorder.onEnd('RENDER');
69
- this.performanceRecorder.onEnd('FRAME');
68
+ this.performanceRecorder.onEnd("RENDER");
69
+ this.performanceRecorder.onEnd("FRAME");
70
70
  if (this.runningLoop) {
71
71
  this.scheduleFrame();
72
72
  }
@@ -99,10 +99,10 @@ class Game {
99
99
  this.screenStack.current()?.addDebugValues(out);
100
100
  }
101
101
  parseURL() {
102
- const params = new URLSearchParams((document.location.search || '?').substr(1));
102
+ const params = new URLSearchParams((document.location.search || "?").substr(1));
103
103
  for (const [param, originalValue] of params.entries()) {
104
104
  let value = originalValue;
105
- if (value === 'true' || value === 'false') {
105
+ if (value === "true" || value === "false") {
106
106
  value = JSON.parse(value);
107
107
  }
108
108
  else if (!Number.isNaN(value)) {
@@ -117,4 +117,3 @@ class Game {
117
117
  }
118
118
  }
119
119
  exports.Game = Game;
120
- ;
package/lib/index.d.ts CHANGED
@@ -1,15 +1,20 @@
1
- export * from './game/game-params';
2
- export * from './game/game-plugin';
3
- export * from './game/game';
4
- export * from './interaction/inputs';
5
- export * from './interaction/screen-mouse-inputs';
6
- export * from './navigation/resolver';
7
- export * from './navigation/screen-stack';
8
- export * from './ui/screen-delegate';
9
- export * from './ui/screen';
10
- export * from './plugins/automation-game-plugin';
11
- export * from './plugins/blur-pausing-game-plugin';
12
- export * from './plugins/fullscreen-button-game-plugin';
13
- export * from './plugins/time-keys-game-plugin';
14
- export * from './plugins/version-label-game-plugin';
15
- export * from './util/math';
1
+ export * from "./game/game";
2
+ export * from "./game/game-params";
3
+ export * from "./game/game-plugin";
4
+ export * from "./interaction/inputs";
5
+ export * from "./interaction/screen-mouse-inputs";
6
+ export * from "./navigation/resolver";
7
+ export * from "./navigation/screen-stack";
8
+ export * from "./ui/screen";
9
+ export * from "./ui/screen-delegate";
10
+ export * from "./plugins/automation-game-plugin";
11
+ export * from "./plugins/blur-pausing-game-plugin";
12
+ export * from "./plugins/fullscreen-button-game-plugin";
13
+ export * from "./plugins/storage-game-plugin";
14
+ export * from "./plugins/time-keys-game-plugin";
15
+ export * from "./plugins/version-label-game-plugin";
16
+ export * from "./storage/get-client-storage";
17
+ export * from "./storage/in-memory-storage";
18
+ export * from "./storage/local-json-store";
19
+ export * from "./util/math";
20
+ export * from "./util/navigation-flow";
package/lib/index.js CHANGED
@@ -14,18 +14,23 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./game/game"), exports);
17
18
  __exportStar(require("./game/game-params"), exports);
18
19
  __exportStar(require("./game/game-plugin"), exports);
19
- __exportStar(require("./game/game"), exports);
20
20
  __exportStar(require("./interaction/inputs"), exports);
21
21
  __exportStar(require("./interaction/screen-mouse-inputs"), exports);
22
22
  __exportStar(require("./navigation/resolver"), exports);
23
23
  __exportStar(require("./navigation/screen-stack"), exports);
24
- __exportStar(require("./ui/screen-delegate"), exports);
25
24
  __exportStar(require("./ui/screen"), exports);
25
+ __exportStar(require("./ui/screen-delegate"), exports);
26
26
  __exportStar(require("./plugins/automation-game-plugin"), exports);
27
27
  __exportStar(require("./plugins/blur-pausing-game-plugin"), exports);
28
28
  __exportStar(require("./plugins/fullscreen-button-game-plugin"), exports);
29
+ __exportStar(require("./plugins/storage-game-plugin"), exports);
29
30
  __exportStar(require("./plugins/time-keys-game-plugin"), exports);
30
31
  __exportStar(require("./plugins/version-label-game-plugin"), exports);
32
+ __exportStar(require("./storage/get-client-storage"), exports);
33
+ __exportStar(require("./storage/in-memory-storage"), exports);
34
+ __exportStar(require("./storage/local-json-store"), exports);
31
35
  __exportStar(require("./util/math"), exports);
36
+ __exportStar(require("./util/navigation-flow"), exports);
@@ -1,9 +1,9 @@
1
- import { ScreenMouseInputs } from './screen-mouse-inputs';
2
- import { DOMGamepadInputs, DOMKeyboardInputs, DOMMouseInputs, Inputs } from '@remvst/client-inputs';
3
- import GamepadInputs from '@remvst/client-inputs/lib/gamepad/gamepad-inputs';
4
- import KeyboardInputs from '@remvst/client-inputs/lib/keyboard/keyboard-inputs';
5
- import { Screen } from '../ui/screen';
6
- import { Game } from '../game/game';
1
+ import { DOMGamepadInputs, DOMKeyboardInputs, DOMMouseInputs, Inputs } from "@remvst/client-inputs";
2
+ import GamepadInputs from "@remvst/client-inputs/lib/gamepad/gamepad-inputs";
3
+ import KeyboardInputs from "@remvst/client-inputs/lib/keyboard/keyboard-inputs";
4
+ import { Game } from "../game/game";
5
+ import { Screen } from "../ui/screen";
6
+ import { ScreenMouseInputs } from "./screen-mouse-inputs";
7
7
  export declare class ScreenInputs implements Inputs {
8
8
  readonly screen: Screen;
9
9
  readonly keyboard: KeyboardInputs;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GameInputs = exports.ScreenInputs = void 0;
4
- const math_1 = require("../util/math");
5
- const screen_mouse_inputs_1 = require("./screen-mouse-inputs");
6
4
  const client_inputs_1 = require("@remvst/client-inputs");
7
5
  const gamepad_inputs_1 = require("@remvst/client-inputs/lib/gamepad/gamepad-inputs");
8
6
  const keyboard_inputs_1 = require("@remvst/client-inputs/lib/keyboard/keyboard-inputs");
7
+ const math_1 = require("../util/math");
8
+ const screen_mouse_inputs_1 = require("./screen-mouse-inputs");
9
9
  class ScreenInputs {
10
10
  constructor(screen) {
11
11
  this.screen = screen;
@@ -70,7 +70,7 @@ class GameInputs {
70
70
  this.keyboard.setup();
71
71
  this.mouse.setup();
72
72
  this.gamepad.setup();
73
- window.addEventListener('blur', () => this.reset(), false);
73
+ window.addEventListener("blur", () => this.reset(), false);
74
74
  }
75
75
  reset() {
76
76
  this.keyboard.reset();
@@ -100,4 +100,3 @@ class GameInputs {
100
100
  }
101
101
  }
102
102
  exports.GameInputs = GameInputs;
103
- ;
@@ -1,4 +1,4 @@
1
- import { Screen } from '../ui/screen';
1
+ import { Screen } from "../ui/screen";
2
2
  export declare class UserCancelledError extends Error {
3
3
  }
4
4
  export declare class Resolver<T> {
@@ -1,6 +1,6 @@
1
- import { ResolverHolder } from './resolver';
2
- import { Game } from '../game/game';
3
- import { Screen } from '../ui/screen';
1
+ import { Game } from "../game/game";
2
+ import { Screen } from "../ui/screen";
3
+ import { ResolverHolder } from "./resolver";
4
4
  export declare enum NavigationType {
5
5
  RESET = 0,
6
6
  PUSH = 1,
@@ -12,7 +12,7 @@ export declare class ScreenStack {
12
12
  private readonly queue;
13
13
  prepareScreen: (screen: Screen) => void;
14
14
  constructor(game: Game);
15
- findByType<T extends Screen>(screenType: (new (...params: any) => T)): T | null;
15
+ findByType<T extends Screen>(screenType: new (...params: any) => T): T | null;
16
16
  current(): Screen;
17
17
  popTo(screen: Screen, inclusive?: boolean): void;
18
18
  push(screen: Screen): void;
@@ -17,7 +17,7 @@ class ScreenStack {
17
17
  this.prepareScreen = () => { };
18
18
  }
19
19
  findByType(screenType) {
20
- return this.screens.find((scr) => scr instanceof screenType) || null;
20
+ return (this.screens.find((scr) => scr instanceof screenType) || null);
21
21
  }
22
22
  current() {
23
23
  return this.screens[this.screens.length - 1] || null;
@@ -90,4 +90,3 @@ class ScreenStack {
90
90
  }
91
91
  }
92
92
  exports.ScreenStack = ScreenStack;
93
- ;
@@ -13,8 +13,8 @@ class AutomationGamePlugin extends game_plugin_1.GamePlugin {
13
13
  }
14
14
  setup() {
15
15
  super.setup();
16
- this.automationLabel = document.createElement('div');
17
- this.automationLabel.id = 'automation-label';
16
+ this.automationLabel = document.createElement("div");
17
+ this.automationLabel.id = "automation-label";
18
18
  document.body.appendChild(this.automationLabel);
19
19
  }
20
20
  render() {
@@ -23,9 +23,10 @@ class AutomationGamePlugin extends game_plugin_1.GamePlugin {
23
23
  this.getAutomationValues(automation);
24
24
  this.automationLabel.innerText = JSON.stringify(automation);
25
25
  // Disable all CSS animations for automation
26
- const styleElement = document.createElement('style');
27
- styleElement.setAttribute('id', 'style-tag');
28
- styleElement.innerHTML = '*,:after,:before,.animate-in{transition:none!important;animation:none!important;}';
26
+ const styleElement = document.createElement("style");
27
+ styleElement.setAttribute("id", "style-tag");
28
+ styleElement.innerHTML =
29
+ "*,:after,:before,.animate-in{transition:none!important;animation:none!important;}";
29
30
  document.head.appendChild(styleElement);
30
31
  }
31
32
  getAutomationValues(out) {
@@ -33,4 +34,4 @@ class AutomationGamePlugin extends game_plugin_1.GamePlugin {
33
34
  }
34
35
  }
35
36
  exports.AutomationGamePlugin = AutomationGamePlugin;
36
- AutomationGamePlugin.key = 'automation';
37
+ AutomationGamePlugin.key = "automation";
@@ -17,8 +17,8 @@ class BlurPausingGamePlugin extends game_plugin_1.GamePlugin {
17
17
  }
18
18
  setup() {
19
19
  super.setup();
20
- window.addEventListener('blur', () => this.updateLoop(), false);
21
- window.addEventListener('focus', () => this.updateLoop(), false);
20
+ window.addEventListener("blur", () => this.updateLoop(), false);
21
+ window.addEventListener("focus", () => this.updateLoop(), false);
22
22
  }
23
23
  updateLoop() {
24
24
  if (document.hasFocus() || !this._enabled) {
@@ -30,4 +30,4 @@ class BlurPausingGamePlugin extends game_plugin_1.GamePlugin {
30
30
  }
31
31
  }
32
32
  exports.BlurPausingGamePlugin = BlurPausingGamePlugin;
33
- BlurPausingGamePlugin.key = 'blur-pausing-game';
33
+ BlurPausingGamePlugin.key = "blur-pausing-game";
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FullscreenButtonGamePlugin = void 0;
4
4
  const game_plugin_1 = require("../game/game-plugin");
5
- 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==';
5
+ 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==";
6
6
  class FullscreenButtonGamePlugin extends game_plugin_1.GamePlugin {
7
7
  constructor(container) {
8
8
  super();
@@ -11,7 +11,7 @@ class FullscreenButtonGamePlugin extends game_plugin_1.GamePlugin {
11
11
  }
12
12
  setup() {
13
13
  super.setup();
14
- const styleElt = document.createElement('style');
14
+ const styleElt = document.createElement("style");
15
15
  styleElt.innerHTML = `
16
16
  .fullscreen-button {
17
17
  position: absolute;
@@ -34,11 +34,11 @@ class FullscreenButtonGamePlugin extends game_plugin_1.GamePlugin {
34
34
  }
35
35
  `;
36
36
  document.head.appendChild(styleElt);
37
- const button = document.createElement('div');
38
- button.className = 'fullscreen-button';
39
- button.addEventListener('click', () => document.body.requestFullscreen(), false);
37
+ const button = document.createElement("div");
38
+ button.className = "fullscreen-button";
39
+ button.addEventListener("click", () => document.body.requestFullscreen(), false);
40
40
  this.container.appendChild(button);
41
41
  }
42
42
  }
43
43
  exports.FullscreenButtonGamePlugin = FullscreenButtonGamePlugin;
44
- FullscreenButtonGamePlugin.key = 'fullscreen-button';
44
+ FullscreenButtonGamePlugin.key = "fullscreen-button";
@@ -0,0 +1,7 @@
1
+ import { GamePlugin } from "../game/game-plugin";
2
+ import { LocalJsonStore } from "../storage/local-json-store";
3
+ export declare class StorageGamePlugin extends GamePlugin {
4
+ static readonly key = "storage";
5
+ readonly key = "storage";
6
+ readonly localJsonStore: LocalJsonStore;
7
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageGamePlugin = void 0;
4
+ const game_plugin_1 = require("../game/game-plugin");
5
+ const get_client_storage_1 = require("../storage/get-client-storage");
6
+ const local_json_store_1 = require("../storage/local-json-store");
7
+ class StorageGamePlugin extends game_plugin_1.GamePlugin {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.key = StorageGamePlugin.key;
11
+ this.localJsonStore = new local_json_store_1.LocalJsonStore((0, get_client_storage_1.getClientStorage)());
12
+ }
13
+ }
14
+ exports.StorageGamePlugin = StorageGamePlugin;
15
+ StorageGamePlugin.key = "storage";
@@ -21,4 +21,4 @@ class TimeKeysGamePlugin extends game_plugin_1.GamePlugin {
21
21
  }
22
22
  }
23
23
  exports.TimeKeysGamePlugin = TimeKeysGamePlugin;
24
- TimeKeysGamePlugin.key = 'time-keys';
24
+ TimeKeysGamePlugin.key = "time-keys";
@@ -5,6 +5,8 @@ export declare class VersionLabelGamePlugin extends GamePlugin {
5
5
  private readonly extraStyle;
6
6
  static readonly key = "version-label";
7
7
  readonly key = "version-label";
8
+ readonly labelElement: any;
9
+ readonly styleElement: HTMLStyleElement;
8
10
  constructor(container: HTMLElement, label: string, extraStyle?: string);
9
11
  setup(): void;
10
12
  }
@@ -3,31 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VersionLabelGamePlugin = void 0;
4
4
  const game_plugin_1 = require("../game/game-plugin");
5
5
  class VersionLabelGamePlugin extends game_plugin_1.GamePlugin {
6
- constructor(container, label, extraStyle = '') {
6
+ constructor(container, label, extraStyle = "") {
7
7
  super();
8
8
  this.container = container;
9
9
  this.label = label;
10
10
  this.extraStyle = extraStyle;
11
11
  this.key = VersionLabelGamePlugin.key;
12
+ this.labelElement = (() => {
13
+ const label = document.createElement("div");
14
+ label.className = "version-label";
15
+ label.innerText = this.label;
16
+ return this.labelElement;
17
+ })();
18
+ this.styleElement = (() => {
19
+ const styleElt = document.createElement("style");
20
+ styleElt.innerHTML = `
21
+ .version-label {
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
+ `;
35
+ return styleElt;
36
+ })();
12
37
  }
13
38
  setup() {
14
39
  super.setup();
15
- const button = document.createElement('div');
16
- button.innerText = this.label;
17
- button.style.cssText = `
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
- this.container.appendChild(button);
40
+ document.head.appendChild(this.styleElement);
41
+ this.container.appendChild(this.labelElement);
31
42
  }
32
43
  }
33
44
  exports.VersionLabelGamePlugin = VersionLabelGamePlugin;
@@ -0,0 +1 @@
1
+ export declare function getClientStorage(): Storage;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getClientStorage = void 0;
4
+ const in_memory_storage_1 = require("./in-memory-storage");
5
+ function getClientStorage() {
6
+ const options = [
7
+ ["localStorage", () => window.localStorage],
8
+ ["sessionStorage", () => window.sessionStorage],
9
+ ["InMemoryStorage", () => new in_memory_storage_1.InMemoryStorage()],
10
+ ];
11
+ for (const [label, getter] of options) {
12
+ try {
13
+ return getter();
14
+ }
15
+ catch (err) {
16
+ console.error(`Failed to get ${label}, falling back`);
17
+ }
18
+ }
19
+ }
20
+ exports.getClientStorage = getClientStorage;
@@ -0,0 +1,9 @@
1
+ export declare class InMemoryStorage implements Storage {
2
+ private readonly items;
3
+ get length(): number;
4
+ clear(): void;
5
+ getItem(key: string): string;
6
+ key(index: number): string;
7
+ removeItem(key: string): void;
8
+ setItem(key: string, value: string): void;
9
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryStorage = void 0;
4
+ class InMemoryStorage {
5
+ constructor() {
6
+ this.items = new Map();
7
+ }
8
+ get length() {
9
+ return this.items.size;
10
+ }
11
+ clear() {
12
+ this.items.clear();
13
+ }
14
+ getItem(key) {
15
+ return this.items.get(key);
16
+ }
17
+ key(index) {
18
+ throw new Error("Method not implemented.");
19
+ }
20
+ removeItem(key) {
21
+ this.items.delete(key);
22
+ }
23
+ setItem(key, value) {
24
+ this.items.set(key, value);
25
+ }
26
+ }
27
+ exports.InMemoryStorage = InMemoryStorage;
@@ -0,0 +1,16 @@
1
+ export declare class StoredItem<T> {
2
+ private readonly localJsonStore;
3
+ readonly key: string;
4
+ constructor(localJsonStore: LocalJsonStore, key: string);
5
+ get(): Promise<T | null>;
6
+ set(value: T): Promise<void>;
7
+ delete(): Promise<void>;
8
+ }
9
+ export declare class LocalJsonStore {
10
+ private readonly localStorage;
11
+ constructor(localStorage: Storage);
12
+ item<T>(key: string): StoredItem<T>;
13
+ setItem(key: string, value: any): Promise<void>;
14
+ deleteItem(key: string): Promise<void>;
15
+ getItem(key: string): Promise<any>;
16
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalJsonStore = exports.StoredItem = void 0;
4
+ class StoredItem {
5
+ constructor(localJsonStore, key) {
6
+ this.localJsonStore = localJsonStore;
7
+ this.key = key;
8
+ }
9
+ get() {
10
+ return this.localJsonStore.getItem(this.key);
11
+ }
12
+ set(value) {
13
+ return this.localJsonStore.setItem(this.key, value);
14
+ }
15
+ delete() {
16
+ return this.localJsonStore.deleteItem(this.key);
17
+ }
18
+ }
19
+ exports.StoredItem = StoredItem;
20
+ class LocalJsonStore {
21
+ constructor(localStorage) {
22
+ this.localStorage = localStorage;
23
+ }
24
+ item(key) {
25
+ return new StoredItem(this, key);
26
+ }
27
+ async setItem(key, value) {
28
+ try {
29
+ this.localStorage.setItem(key, JSON.stringify(value));
30
+ }
31
+ catch (err) {
32
+ console.error(`setItem error: ${err.message}`, err);
33
+ throw err;
34
+ }
35
+ }
36
+ async deleteItem(key) {
37
+ try {
38
+ this.localStorage.removeItem(key);
39
+ }
40
+ catch (err) {
41
+ console.error(`deleteItem error: ${err.message}`, err);
42
+ throw err;
43
+ }
44
+ }
45
+ async getItem(key) {
46
+ try {
47
+ const stored = this.localStorage.getItem(key);
48
+ if (!stored)
49
+ return null;
50
+ return JSON.parse(stored);
51
+ }
52
+ catch (err) {
53
+ console.error(`getItem error: ${err.message}. Falling back to null`, err);
54
+ return null;
55
+ }
56
+ }
57
+ }
58
+ exports.LocalJsonStore = LocalJsonStore;
@@ -1,7 +1,7 @@
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
  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 = 'default';
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['screen.id'] = this.id;
115
- values['screen.interpolations'] = this.interpolationPool.size;
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
@@ -9,4 +9,3 @@ function between(a, b, c) {
9
9
  return b;
10
10
  }
11
11
  exports.between = between;
12
- ;
@@ -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;