@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.
Files changed (64) 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 +25 -19
  7. package/lib/index.js +9 -3
  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/metrics-game-plugin.d.ts +13 -0
  17. package/lib/plugins/metrics-game-plugin.js +47 -0
  18. package/lib/plugins/storage-game-plugin.js +1 -1
  19. package/lib/plugins/time-keys-game-plugin.js +1 -1
  20. package/lib/plugins/version-label-game-plugin.d.ts +2 -0
  21. package/lib/plugins/version-label-game-plugin.js +28 -17
  22. package/lib/storage/get-client-storage.js +3 -3
  23. package/lib/storage/in-memory-storage.js +1 -1
  24. package/lib/storage/local-json-store.js +0 -1
  25. package/lib/tracking/framerate-counts.d.ts +10 -0
  26. package/lib/tracking/framerate-counts.js +47 -0
  27. package/lib/tracking/properties-provider.d.ts +4 -0
  28. package/lib/tracking/properties-provider.js +2 -0
  29. package/lib/tracking/tracker.d.ts +7 -0
  30. package/lib/tracking/tracker.js +2 -0
  31. package/lib/tracking/tracking-screen-delegate.d.ts +14 -0
  32. package/lib/tracking/tracking-screen-delegate.js +38 -0
  33. package/lib/ui/screen.d.ts +4 -4
  34. package/lib/ui/screen.js +3 -3
  35. package/lib/util/math.js +0 -1
  36. package/lib/util/navigation-flow.d.ts +1 -0
  37. package/lib/util/navigation-flow.js +12 -0
  38. package/package.json +1 -1
  39. package/src/game/game-params.ts +1 -1
  40. package/src/game/game-plugin.ts +5 -14
  41. package/src/game/game.ts +23 -17
  42. package/src/index.ts +26 -19
  43. package/src/interaction/inputs.ts +43 -23
  44. package/src/interaction/screen-mouse-inputs.ts +7 -3
  45. package/src/navigation/resolver.ts +3 -6
  46. package/src/navigation/screen-stack.ts +15 -12
  47. package/src/plugins/automation-game-plugin.ts +8 -8
  48. package/src/plugins/blur-pausing-game-plugin.ts +3 -4
  49. package/src/plugins/fullscreen-button-game-plugin.ts +11 -7
  50. package/src/plugins/metrics-game-plugin.ts +65 -0
  51. package/src/plugins/storage-game-plugin.ts +1 -1
  52. package/src/plugins/time-keys-game-plugin.ts +7 -6
  53. package/src/plugins/version-label-game-plugin.ts +30 -18
  54. package/src/storage/get-client-storage.ts +4 -4
  55. package/src/storage/in-memory-storage.ts +1 -3
  56. package/src/storage/local-json-store.ts +10 -12
  57. package/src/tracking/framerate-counts.ts +50 -0
  58. package/src/tracking/properties-provider.ts +5 -0
  59. package/src/tracking/tracker.ts +6 -0
  60. package/src/tracking/tracking-screen-delegate.ts +48 -0
  61. package/src/ui/screen-delegate.ts +1 -1
  62. package/src/ui/screen.ts +29 -14
  63. package/src/util/math.ts +1 -1
  64. 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,19 +1,25 @@
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 './plugins/storage-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';
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/metrics-game-plugin";
14
+ export * from "./plugins/storage-game-plugin";
15
+ export * from "./plugins/time-keys-game-plugin";
16
+ export * from "./plugins/version-label-game-plugin";
17
+ export * from "./storage/get-client-storage";
18
+ export * from "./storage/in-memory-storage";
19
+ export * from "./storage/local-json-store";
20
+ export * from "./tracking/framerate-counts";
21
+ export * from "./tracking/properties-provider";
22
+ export * from "./tracking/tracker";
23
+ export * from "./tracking/tracking-screen-delegate";
24
+ export * from "./util/math";
25
+ export * from "./util/navigation-flow";
package/lib/index.js CHANGED
@@ -14,22 +14,28 @@ 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/metrics-game-plugin"), exports);
30
+ __exportStar(require("./plugins/storage-game-plugin"), exports);
29
31
  __exportStar(require("./plugins/time-keys-game-plugin"), exports);
30
32
  __exportStar(require("./plugins/version-label-game-plugin"), exports);
31
- __exportStar(require("./plugins/storage-game-plugin"), exports);
32
33
  __exportStar(require("./storage/get-client-storage"), exports);
33
34
  __exportStar(require("./storage/in-memory-storage"), exports);
34
35
  __exportStar(require("./storage/local-json-store"), exports);
36
+ __exportStar(require("./tracking/framerate-counts"), exports);
37
+ __exportStar(require("./tracking/properties-provider"), exports);
38
+ __exportStar(require("./tracking/tracker"), exports);
39
+ __exportStar(require("./tracking/tracking-screen-delegate"), exports);
35
40
  __exportStar(require("./util/math"), exports);
41
+ __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,13 @@
1
+ import { GamePlugin } from "../game/game-plugin";
2
+ import { Tracker } from "../tracking/tracker";
3
+ import { Screen } from "../ui/screen";
4
+ export declare class MetricsGamePlugin extends GamePlugin {
5
+ readonly tracker: Tracker;
6
+ static readonly key = "metrics";
7
+ readonly key = "metrics";
8
+ private framerateCounts;
9
+ constructor(tracker: Tracker);
10
+ setup(): void;
11
+ cycle(elapsed: number): void;
12
+ setupScreen(screen: Screen): void;
13
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetricsGamePlugin = void 0;
4
+ const game_plugin_1 = require("../game/game-plugin");
5
+ const resolver_1 = require("../navigation/resolver");
6
+ const framerate_counts_1 = require("../tracking/framerate-counts");
7
+ const tracking_screen_delegate_1 = require("../tracking/tracking-screen-delegate");
8
+ class MetricsGamePlugin extends game_plugin_1.GamePlugin {
9
+ constructor(tracker) {
10
+ super();
11
+ this.tracker = tracker;
12
+ this.key = MetricsGamePlugin.key;
13
+ }
14
+ setup() {
15
+ super.setup();
16
+ this.framerateCounts = new framerate_counts_1.FrameRateCounts(this.game.performanceRecorder);
17
+ window.addEventListener("error", (event) => {
18
+ this.tracker.track("errorOccurred", {
19
+ errorType: "error",
20
+ message: event.message,
21
+ lineno: event.lineno,
22
+ });
23
+ return false;
24
+ }, false);
25
+ window.addEventListener("unhandledrejection", (err) => {
26
+ if (err.reason instanceof resolver_1.UserCancelledError) {
27
+ return;
28
+ }
29
+ this.tracker.track("errorOccurred", {
30
+ errorType: "unhandledrejection",
31
+ message: err.reason.message,
32
+ });
33
+ return false;
34
+ }, false);
35
+ this.tracker.track("gameSetup", {});
36
+ }
37
+ cycle(elapsed) {
38
+ super.cycle(elapsed);
39
+ this.framerateCounts.cycle(elapsed);
40
+ }
41
+ setupScreen(screen) {
42
+ super.setupScreen(screen);
43
+ screen.delegate = new tracking_screen_delegate_1.TrackingScreenDelegate(screen, this.tracker);
44
+ }
45
+ }
46
+ exports.MetricsGamePlugin = MetricsGamePlugin;
47
+ MetricsGamePlugin.key = "metrics";
@@ -12,4 +12,4 @@ class StorageGamePlugin extends game_plugin_1.GamePlugin {
12
12
  }
13
13
  }
14
14
  exports.StorageGamePlugin = StorageGamePlugin;
15
- StorageGamePlugin.key = 'storage';
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;
@@ -4,9 +4,9 @@ exports.getClientStorage = void 0;
4
4
  const in_memory_storage_1 = require("./in-memory-storage");
5
5
  function getClientStorage() {
6
6
  const options = [
7
- ['localStorage', () => window.localStorage],
8
- ['sessionStorage', () => window.sessionStorage],
9
- ['InMemoryStorage', () => new in_memory_storage_1.InMemoryStorage()],
7
+ ["localStorage", () => window.localStorage],
8
+ ["sessionStorage", () => window.sessionStorage],
9
+ ["InMemoryStorage", () => new in_memory_storage_1.InMemoryStorage()],
10
10
  ];
11
11
  for (const [label, getter] of options) {
12
12
  try {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryStorage = void 0;
4
4
  class InMemoryStorage {
5
5
  constructor() {
6
- this.items = new Map;
6
+ this.items = new Map();
7
7
  }
8
8
  get length() {
9
9
  return this.items.size;
@@ -56,4 +56,3 @@ class LocalJsonStore {
56
56
  }
57
57
  }
58
58
  exports.LocalJsonStore = LocalJsonStore;
59
- ;
@@ -0,0 +1,10 @@
1
+ import { PerformanceRecorder } from "@remvst/client-performance";
2
+ import { Properties } from "./tracker";
3
+ export declare class FrameRateCounts {
4
+ private readonly performanceRecorder;
5
+ private readonly counts;
6
+ private age;
7
+ constructor(performanceRecorder: PerformanceRecorder);
8
+ cycle(elapsed: number): void;
9
+ toJson(): Properties;
10
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FrameRateCounts = void 0;
4
+ class FrameRateCounts {
5
+ constructor(performanceRecorder) {
6
+ this.performanceRecorder = performanceRecorder;
7
+ this.counts = {
8
+ above60: 0,
9
+ above45: 0,
10
+ above30: 0,
11
+ above15: 0,
12
+ above0: 0,
13
+ };
14
+ this.age = 0;
15
+ }
16
+ cycle(elapsed) {
17
+ this.age += elapsed;
18
+ if (this.age > 0.5) {
19
+ const previousFrame = this.performanceRecorder.frame(this.performanceRecorder.frameCount - 1);
20
+ const currentFrame = this.performanceRecorder.frame(this.performanceRecorder.frameCount);
21
+ const framerate = 1000 /
22
+ (currentFrame.onStartTimes.get("FRAME") -
23
+ previousFrame.onStartTimes.get("FRAME"));
24
+ let key;
25
+ if (framerate > 60) {
26
+ key = "above60";
27
+ }
28
+ else if (framerate > 45) {
29
+ key = "above45";
30
+ }
31
+ else if (framerate > 30) {
32
+ key = "above30";
33
+ }
34
+ else if (framerate > 15) {
35
+ key = "above15";
36
+ }
37
+ else {
38
+ key = "above0";
39
+ }
40
+ this.counts[key]++;
41
+ }
42
+ }
43
+ toJson() {
44
+ return this.counts;
45
+ }
46
+ }
47
+ exports.FrameRateCounts = FrameRateCounts;
@@ -0,0 +1,4 @@
1
+ import { Properties } from "./tracker";
2
+ export interface PropertiesProvider {
3
+ readonly properties: Properties;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export type PropertyValue = string | number | boolean;
2
+ export type Properties = {
3
+ [key: string]: PropertyValue | PropertyValue[];
4
+ };
5
+ export interface Tracker {
6
+ track(eventName: string, properties: Properties): void;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { Screen } from "../ui/screen";
2
+ import { ScreenDelegate } from "../ui/screen-delegate";
3
+ import { Tracker } from "./tracker";
4
+ export declare class TrackingScreenDelegate implements ScreenDelegate {
5
+ private readonly screen;
6
+ private readonly tracker;
7
+ constructor(screen: Screen, tracker: Tracker);
8
+ private properties;
9
+ private track;
10
+ onSetup(): void;
11
+ onForeground(): void;
12
+ onBackground(): void;
13
+ onDestroy(): void;
14
+ }