@remvst/game-navigation-core 1.10.0 → 1.10.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.
package/lib/index.d.ts CHANGED
@@ -9,10 +9,10 @@ export * from "./navigation/screen-stack";
9
9
  export * from "./ui/screen";
10
10
  export * from "./ui/screen-delegate";
11
11
  export * from "./plugins/automation-game-plugin";
12
+ export * from "./plugins/back-navigation-plugin";
12
13
  export * from "./plugins/blur-pausing-game-plugin";
13
14
  export * from "./plugins/fullscreen-button-game-plugin";
14
15
  export * from "./plugins/metrics-game-plugin";
15
- export * from "./plugins/back-navigation-plugin";
16
16
  export * from "./plugins/storage-game-plugin";
17
17
  export * from "./plugins/time-keys-game-plugin";
18
18
  export * from "./plugins/version-label-game-plugin";
package/lib/index.js CHANGED
@@ -25,10 +25,10 @@ __exportStar(require("./navigation/screen-stack"), exports);
25
25
  __exportStar(require("./ui/screen"), exports);
26
26
  __exportStar(require("./ui/screen-delegate"), exports);
27
27
  __exportStar(require("./plugins/automation-game-plugin"), exports);
28
+ __exportStar(require("./plugins/back-navigation-plugin"), exports);
28
29
  __exportStar(require("./plugins/blur-pausing-game-plugin"), exports);
29
30
  __exportStar(require("./plugins/fullscreen-button-game-plugin"), exports);
30
31
  __exportStar(require("./plugins/metrics-game-plugin"), exports);
31
- __exportStar(require("./plugins/back-navigation-plugin"), exports);
32
32
  __exportStar(require("./plugins/storage-game-plugin"), exports);
33
33
  __exportStar(require("./plugins/time-keys-game-plugin"), exports);
34
34
  __exportStar(require("./plugins/version-label-game-plugin"), exports);
@@ -32,7 +32,7 @@ class Resolver {
32
32
  };
33
33
  }
34
34
  dismiss() {
35
- this.screen.game.screenStack.pop();
35
+ this.screen.game.screenStack.popTo(this.screen, true);
36
36
  }
37
37
  }
38
38
  exports.Resolver = Resolver;
@@ -24,6 +24,9 @@ class ScreenStack {
24
24
  return this.screens[this.screens.length - 1] || null;
25
25
  }
26
26
  popTo(screen, inclusive = false) {
27
+ if (!this.screens.includes(screen)) {
28
+ return;
29
+ }
27
30
  while (this.current() && this.current() !== screen) {
28
31
  this.pop();
29
32
  }
@@ -5,7 +5,7 @@ const game_plugin_1 = require("../game/game-plugin");
5
5
  class BackNavigationPlugin extends game_plugin_1.GamePlugin {
6
6
  constructor() {
7
7
  super(...arguments);
8
- this.key = 'back-navigation';
8
+ this.key = "back-navigation";
9
9
  this.pushedState = false;
10
10
  }
11
11
  setup() {
@@ -13,13 +13,13 @@ class BackNavigationPlugin extends game_plugin_1.GamePlugin {
13
13
  const { length } = history;
14
14
  if (length > 0)
15
15
  history.go(-length);
16
- window.addEventListener('popstate', () => this.onPopState());
16
+ window.addEventListener("popstate", () => this.onPopState());
17
17
  }
18
18
  pushState() {
19
19
  if (this.pushedState)
20
20
  return;
21
21
  this.pushedState = true;
22
- window.history.pushState({}, '', '');
22
+ window.history.pushState({}, "", "");
23
23
  }
24
24
  popState() {
25
25
  if (!this.pushedState)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/game-navigation-core",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -13,10 +13,10 @@ export * from "./ui/screen";
13
13
  export * from "./ui/screen-delegate";
14
14
 
15
15
  export * from "./plugins/automation-game-plugin";
16
+ export * from "./plugins/back-navigation-plugin";
16
17
  export * from "./plugins/blur-pausing-game-plugin";
17
18
  export * from "./plugins/fullscreen-button-game-plugin";
18
19
  export * from "./plugins/metrics-game-plugin";
19
- export * from "./plugins/back-navigation-plugin";
20
20
  export * from "./plugins/storage-game-plugin";
21
21
  export * from "./plugins/time-keys-game-plugin";
22
22
  export * from "./plugins/version-label-game-plugin";
@@ -1,3 +1,3 @@
1
- export interface BackNavigationListener {
2
- onBackNavigation(): void;
3
- }
1
+ export interface BackNavigationListener {
2
+ onBackNavigation(): void;
3
+ }
@@ -43,7 +43,7 @@ export class Resolver<T> {
43
43
  }
44
44
 
45
45
  private dismiss() {
46
- this.screen.game.screenStack.pop();
46
+ this.screen.game.screenStack.popTo(this.screen, true);
47
47
  }
48
48
  }
49
49
 
@@ -31,6 +31,10 @@ export class ScreenStack {
31
31
  }
32
32
 
33
33
  popTo(screen: Screen, inclusive: boolean = false) {
34
+ if (!this.screens.includes(screen)) {
35
+ return;
36
+ }
37
+
34
38
  while (this.current() && this.current() !== screen) {
35
39
  this.pop();
36
40
  }
@@ -1,53 +1,56 @@
1
- import { GamePlugin } from "../game/game-plugin";
2
- import { BackNavigationListener } from "../navigation/back-navigation-listener";
3
- import { Screen } from "../ui/screen";
4
-
5
- export class BackNavigationPlugin extends GamePlugin {
6
- readonly key = 'back-navigation';
7
-
8
- private pushedState = false;
9
-
10
- setup(): void {
11
- super.setup();
12
-
13
- const { length} = history;
14
- if (length > 0) history.go(-length);
15
-
16
- window.addEventListener('popstate', () => this.onPopState());
17
- }
18
-
19
- pushState() {
20
- if (this.pushedState) return;
21
- this.pushedState = true;
22
- window.history.pushState({}, '', '');
23
- }
24
-
25
- popState() {
26
- if (!this.pushedState) return;
27
- this.pushedState = false;
28
- window.history.back();
29
- }
30
-
31
- private onPopState() {
32
- this.pushedState = false;
33
-
34
- const currentScreen = this.game.screenStack.current() as unknown as BackNavigationListener | null;
35
- if (!currentScreen?.onBackNavigation) return;
36
-
37
- this.pushState();
38
- currentScreen.onBackNavigation();
39
- }
40
-
41
- setupScreen(screen: Screen) {
42
- super.setupScreen(screen);
43
- }
44
-
45
- onCurrentScreenChanged(screen: Screen | null): void {
46
- const handlesBackNavigation = (screen as unknown as BackNavigationListener)?.onBackNavigation;
47
- if (handlesBackNavigation) {
48
- this.pushState();
49
- } else {
50
- this.popState();
51
- }
52
- }
53
- }
1
+ import { GamePlugin } from "../game/game-plugin";
2
+ import { BackNavigationListener } from "../navigation/back-navigation-listener";
3
+ import { Screen } from "../ui/screen";
4
+
5
+ export class BackNavigationPlugin extends GamePlugin {
6
+ readonly key = "back-navigation";
7
+
8
+ private pushedState = false;
9
+
10
+ setup(): void {
11
+ super.setup();
12
+
13
+ const { length } = history;
14
+ if (length > 0) history.go(-length);
15
+
16
+ window.addEventListener("popstate", () => this.onPopState());
17
+ }
18
+
19
+ pushState() {
20
+ if (this.pushedState) return;
21
+ this.pushedState = true;
22
+ window.history.pushState({}, "", "");
23
+ }
24
+
25
+ popState() {
26
+ if (!this.pushedState) return;
27
+ this.pushedState = false;
28
+ window.history.back();
29
+ }
30
+
31
+ private onPopState() {
32
+ this.pushedState = false;
33
+
34
+ const currentScreen =
35
+ this.game.screenStack.current() as unknown as BackNavigationListener | null;
36
+ if (!currentScreen?.onBackNavigation) return;
37
+
38
+ this.pushState();
39
+ currentScreen.onBackNavigation();
40
+ }
41
+
42
+ setupScreen(screen: Screen) {
43
+ super.setupScreen(screen);
44
+ }
45
+
46
+ onCurrentScreenChanged(screen: Screen | null): void {
47
+ const handlesBackNavigation = (
48
+ screen as unknown as BackNavigationListener
49
+ )?.onBackNavigation;
50
+ if (handlesBackNavigation) {
51
+ this.pushState();
52
+ } else {
53
+ this.popState();
54
+ }
55
+ }
56
+ }