@remvst/game-navigation-core 1.0.0 → 1.0.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/game/game-plugin.d.ts +4 -3
- package/lib/game/game-plugin.js +6 -0
- package/lib/game/game.js +7 -0
- package/lib/plugins/automation-game-plugin.js +2 -0
- package/lib/plugins/blur-pausing-game-plugin.d.ts +1 -3
- package/lib/plugins/blur-pausing-game-plugin.js +5 -8
- package/lib/plugins/time-keys-game-plugin.d.ts +0 -2
- package/lib/plugins/time-keys-game-plugin.js +0 -4
- package/package.json +1 -1
- package/src/game/game-plugin.ts +13 -3
- package/src/game/game.ts +9 -1
- package/src/plugins/automation-game-plugin.ts +4 -0
- package/src/plugins/blur-pausing-game-plugin.ts +5 -9
- package/src/plugins/time-keys-game-plugin.ts +0 -6
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Game } from "./game";
|
|
2
2
|
import { Screen } from '../ui/screen';
|
|
3
3
|
export declare abstract class GamePlugin {
|
|
4
|
+
abstract get key(): string;
|
|
4
5
|
protected game: Game;
|
|
5
6
|
get timeFactor(): number;
|
|
6
7
|
bind(game: Game): void;
|
|
8
|
+
setup(): void;
|
|
7
9
|
setupScreen(screen: Screen): void;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
abstract render(): void;
|
|
10
|
+
cycle(elapsed: number): void;
|
|
11
|
+
render(): void;
|
|
11
12
|
}
|
package/lib/game/game-plugin.js
CHANGED
package/lib/game/game.js
CHANGED
|
@@ -77,6 +77,10 @@ class Game {
|
|
|
77
77
|
for (const plugin of this.plugins) {
|
|
78
78
|
adjusted *= plugin.timeFactor;
|
|
79
79
|
}
|
|
80
|
+
const screen = this.screenStack.current();
|
|
81
|
+
if (screen) {
|
|
82
|
+
adjusted *= this.screenStack.current().timeFactor;
|
|
83
|
+
}
|
|
80
84
|
this.age += elapsed;
|
|
81
85
|
const screens = this.screenStack.screens.slice();
|
|
82
86
|
for (let i = screens.length - 1; i >= 0; i--) {
|
|
@@ -87,6 +91,9 @@ class Game {
|
|
|
87
91
|
break;
|
|
88
92
|
}
|
|
89
93
|
}
|
|
94
|
+
for (const plugin of this.plugins) {
|
|
95
|
+
plugin.cycle(elapsed);
|
|
96
|
+
}
|
|
90
97
|
}
|
|
91
98
|
getDebugValues(out) {
|
|
92
99
|
this.screenStack.current()?.addDebugValues(out);
|
|
@@ -12,11 +12,13 @@ class AutomationGamePlugin extends game_plugin_1.GamePlugin {
|
|
|
12
12
|
this.key = AutomationGamePlugin.key;
|
|
13
13
|
}
|
|
14
14
|
setup() {
|
|
15
|
+
super.setup();
|
|
15
16
|
this.automationLabel = document.createElement('div');
|
|
16
17
|
this.automationLabel.id = 'automation-label';
|
|
17
18
|
document.body.appendChild(this.automationLabel);
|
|
18
19
|
}
|
|
19
20
|
render() {
|
|
21
|
+
super.render();
|
|
20
22
|
const automation = {};
|
|
21
23
|
this.getAutomationValues(automation);
|
|
22
24
|
this.automationLabel.innerText = JSON.stringify(automation);
|
|
@@ -2,8 +2,6 @@ import { GamePlugin } from "../game/game-plugin";
|
|
|
2
2
|
export declare class BlurPausingGamePlugin extends GamePlugin {
|
|
3
3
|
static readonly key = "blur-pausing-game";
|
|
4
4
|
readonly key = "blur-pausing-game";
|
|
5
|
-
hasFocus: boolean;
|
|
6
5
|
setup(): void;
|
|
7
|
-
|
|
8
|
-
windowHasFocus(hasFocus: boolean): void;
|
|
6
|
+
private focusChanged;
|
|
9
7
|
}
|
|
@@ -6,17 +6,14 @@ class BlurPausingGamePlugin extends game_plugin_1.GamePlugin {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
this.key = BlurPausingGamePlugin.key;
|
|
9
|
-
this.hasFocus = true;
|
|
10
9
|
}
|
|
11
10
|
setup() {
|
|
12
|
-
|
|
13
|
-
window.addEventListener('
|
|
11
|
+
super.setup();
|
|
12
|
+
window.addEventListener('blur', () => this.focusChanged(), false);
|
|
13
|
+
window.addEventListener('focus', () => this.focusChanged(), false);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
windowHasFocus(hasFocus) {
|
|
18
|
-
this.hasFocus = hasFocus;
|
|
19
|
-
if (hasFocus) {
|
|
15
|
+
focusChanged() {
|
|
16
|
+
if (document.hasFocus()) {
|
|
20
17
|
this.game.scheduleFrame();
|
|
21
18
|
}
|
|
22
19
|
else {
|
package/package.json
CHANGED
package/src/game/game-plugin.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { Screen } from '../ui/screen';
|
|
|
3
3
|
|
|
4
4
|
export abstract class GamePlugin {
|
|
5
5
|
|
|
6
|
+
abstract get key(): string;
|
|
7
|
+
|
|
6
8
|
protected game: Game;
|
|
7
9
|
|
|
8
10
|
get timeFactor(): number {
|
|
@@ -13,11 +15,19 @@ export abstract class GamePlugin {
|
|
|
13
15
|
this.game = game;
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
setup(): void {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
setupScreen(screen: Screen): void {
|
|
17
23
|
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
cycle(elapsed: number) {
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
|
|
32
|
+
}
|
|
23
33
|
}
|
package/src/game/game.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GameInputs } from '../interaction/inputs';
|
|
2
2
|
import { GameParams } from './game-params';
|
|
3
3
|
import { GamePlugin } from './game-plugin';
|
|
4
|
-
import { Screen } from '../ui/screen';
|
|
5
4
|
import { ScreenStack } from '../navigation/screen-stack';
|
|
6
5
|
import { PerformanceRecorder } from '@remvst/client-performance';
|
|
7
6
|
|
|
@@ -114,6 +113,11 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
114
113
|
adjusted *= plugin.timeFactor;
|
|
115
114
|
}
|
|
116
115
|
|
|
116
|
+
const screen = this.screenStack.current();
|
|
117
|
+
if (screen) {
|
|
118
|
+
adjusted *= this.screenStack.current().timeFactor;
|
|
119
|
+
}
|
|
120
|
+
|
|
117
121
|
this.age += elapsed;
|
|
118
122
|
|
|
119
123
|
const screens = this.screenStack.screens.slice();
|
|
@@ -126,6 +130,10 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
126
130
|
break;
|
|
127
131
|
}
|
|
128
132
|
}
|
|
133
|
+
|
|
134
|
+
for (const plugin of this.plugins) {
|
|
135
|
+
plugin.cycle(elapsed);
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
|
|
131
139
|
getDebugValues(out: {[key: string]: any}) {
|
|
@@ -17,12 +17,16 @@ export class AutomationGamePlugin extends GamePlugin {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
setup(): void {
|
|
20
|
+
super.setup();
|
|
21
|
+
|
|
20
22
|
this.automationLabel = document.createElement('div');
|
|
21
23
|
this.automationLabel.id = 'automation-label';
|
|
22
24
|
document.body.appendChild(this.automationLabel);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
render(): void {
|
|
28
|
+
super.render();
|
|
29
|
+
|
|
26
30
|
const automation = {};
|
|
27
31
|
this.getAutomationValues(automation);
|
|
28
32
|
this.automationLabel.innerText = JSON.stringify(automation);
|
|
@@ -5,19 +5,15 @@ export class BlurPausingGamePlugin extends GamePlugin {
|
|
|
5
5
|
static readonly key = 'blur-pausing-game';
|
|
6
6
|
readonly key = BlurPausingGamePlugin.key;
|
|
7
7
|
|
|
8
|
-
hasFocus = true;
|
|
9
|
-
|
|
10
8
|
setup(): void {
|
|
11
|
-
|
|
12
|
-
window.addEventListener('focus', () => this.windowHasFocus(true), false);
|
|
13
|
-
}
|
|
9
|
+
super.setup();
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
window.addEventListener('blur', () => this.focusChanged(), false);
|
|
12
|
+
window.addEventListener('focus', () => this.focusChanged(), false);
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (hasFocus) {
|
|
15
|
+
private focusChanged() {
|
|
16
|
+
if (document.hasFocus()) {
|
|
21
17
|
this.game.scheduleFrame();
|
|
22
18
|
} else {
|
|
23
19
|
this.game.stopLoop();
|