@remvst/game-navigation-core 1.6.0 → 1.7.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.
package/lib/game/game.js CHANGED
@@ -21,14 +21,16 @@ class Game {
21
21
  return this.pluginMap.get(keyProvider.key);
22
22
  }
23
23
  setup() {
24
+ this.inputs = new inputs_1.GameInputs(this);
25
+ this.inputs.setup();
26
+ this.screenStack = new screen_stack_1.ScreenStack(this);
24
27
  for (const plugin of this.plugins) {
25
28
  plugin.bind(this);
26
- plugin.setup();
27
29
  this.pluginMap.set(plugin.key, plugin);
28
30
  }
29
- this.inputs = new inputs_1.GameInputs(this);
30
- this.inputs.setup();
31
- this.screenStack = new screen_stack_1.ScreenStack(this);
31
+ for (const plugin of this.plugins) {
32
+ plugin.setup();
33
+ }
32
34
  this.lastFrame = window.performance.now();
33
35
  this.scheduleFrame();
34
36
  }
@@ -16,6 +16,7 @@ export declare class ScreenStack {
16
16
  current(): Screen;
17
17
  popTo(screen: Screen, inclusive?: boolean): void;
18
18
  push(screen: Screen): void;
19
+ replaceExisting(screen: Screen): void;
19
20
  pop(): void;
20
21
  reset(screen: Screen): void;
21
22
  resolvableScreen<T>(screen: Screen & ResolverHolder<T>, navigationType?: NavigationType, dismissWhenResolved?: boolean): Promise<T>;
@@ -45,6 +45,12 @@ class ScreenStack {
45
45
  this.game.onCurrentScreenChanged();
46
46
  });
47
47
  }
48
+ replaceExisting(screen) {
49
+ const existing = this.findByType(screen.constructor);
50
+ if (existing)
51
+ this.popTo(existing, true);
52
+ this.push(screen);
53
+ }
48
54
  pop() {
49
55
  this.queue.execute(() => {
50
56
  const screen = this.screens.pop();
@@ -80,10 +86,7 @@ class ScreenStack {
80
86
  this.reset(screen);
81
87
  break;
82
88
  case NavigationType.REPLACE_EXISTING:
83
- const existing = this.findByType(screen.constructor);
84
- if (existing)
85
- this.popTo(existing, true);
86
- this.push(screen);
89
+ this.replaceExisting(screen);
87
90
  break;
88
91
  }
89
92
  });
@@ -5,7 +5,7 @@ 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;
8
+ readonly labelElement: HTMLDivElement;
9
9
  readonly styleElement: HTMLStyleElement;
10
10
  constructor(container: HTMLElement, label: string, extraStyle?: string);
11
11
  setup(): void;
@@ -13,7 +13,7 @@ class VersionLabelGamePlugin extends game_plugin_1.GamePlugin {
13
13
  const label = document.createElement("div");
14
14
  label.className = "version-label";
15
15
  label.innerText = this.label;
16
- return this.labelElement;
16
+ return label;
17
17
  })();
18
18
  this.styleElement = (() => {
19
19
  const styleElt = document.createElement("style");
@@ -10,7 +10,7 @@ export declare abstract class Screen {
10
10
  frameCount: number;
11
11
  interpolationPool: InterpolationPool;
12
12
  delegate: ScreenDelegate | null;
13
- private readonly subscreens;
13
+ protected readonly subscreens: Screen[];
14
14
  constructor();
15
15
  addSubscreen(screen: Screen): void;
16
16
  bind(game: Game): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/game-navigation-core",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
package/src/game/game.ts CHANGED
@@ -41,16 +41,19 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
41
41
  }
42
42
 
43
43
  setup() {
44
+ this.inputs = new GameInputs(this);
45
+ this.inputs.setup();
46
+
47
+ this.screenStack = new ScreenStack(this);
48
+
44
49
  for (const plugin of this.plugins) {
45
50
  plugin.bind(this);
46
- plugin.setup();
47
51
  this.pluginMap.set(plugin.key, plugin);
48
52
  }
49
53
 
50
- this.inputs = new GameInputs(this);
51
- this.inputs.setup();
52
-
53
- this.screenStack = new ScreenStack(this);
54
+ for (const plugin of this.plugins) {
55
+ plugin.setup();
56
+ }
54
57
 
55
58
  this.lastFrame = window.performance.now();
56
59
  this.scheduleFrame();
@@ -60,6 +60,14 @@ export class ScreenStack {
60
60
  });
61
61
  }
62
62
 
63
+ replaceExisting(screen: Screen) {
64
+ const existing = this.findByType(
65
+ screen.constructor as new (...params: any) => Screen,
66
+ ) as Screen;
67
+ if (existing) this.popTo(existing, true);
68
+ this.push(screen);
69
+ }
70
+
63
71
  pop() {
64
72
  this.queue.execute(() => {
65
73
  const screen = this.screens.pop();
@@ -103,11 +111,7 @@ export class ScreenStack {
103
111
  this.reset(screen);
104
112
  break;
105
113
  case NavigationType.REPLACE_EXISTING:
106
- const existing = this.findByType(
107
- screen.constructor as new (...params: any) => Screen,
108
- ) as Screen;
109
- if (existing) this.popTo(existing, true);
110
- this.push(screen);
114
+ this.replaceExisting(screen);
111
115
  break;
112
116
  }
113
117
  });
@@ -8,7 +8,7 @@ export class VersionLabelGamePlugin extends GamePlugin {
8
8
  const label = document.createElement("div");
9
9
  label.className = "version-label";
10
10
  label.innerText = this.label;
11
- return this.labelElement;
11
+ return label;
12
12
  })();
13
13
 
14
14
  readonly styleElement = (() => {
package/src/ui/screen.ts CHANGED
@@ -13,7 +13,7 @@ export abstract class Screen {
13
13
  interpolationPool: InterpolationPool;
14
14
  delegate: ScreenDelegate | null = null;
15
15
 
16
- private readonly subscreens: Screen[] = [];
16
+ protected readonly subscreens: Screen[] = [];
17
17
 
18
18
  constructor() {
19
19
  this.game = null;