@remvst/game-navigation-core 1.5.1 → 1.6.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 +5 -0
- package/lib/index.js +5 -0
- package/lib/plugins/metrics-game-plugin.d.ts +13 -0
- package/lib/plugins/metrics-game-plugin.js +47 -0
- package/lib/plugins/version-label-game-plugin.d.ts +1 -1
- package/lib/plugins/version-label-game-plugin.js +1 -1
- package/lib/tracking/framerate-counts.d.ts +10 -0
- package/lib/tracking/framerate-counts.js +47 -0
- package/lib/tracking/properties-provider.d.ts +4 -0
- package/lib/tracking/properties-provider.js +2 -0
- package/lib/tracking/tracker.d.ts +7 -0
- package/lib/tracking/tracker.js +2 -0
- package/lib/tracking/tracking-screen-delegate.d.ts +14 -0
- package/lib/tracking/tracking-screen-delegate.js +38 -0
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/plugins/metrics-game-plugin.ts +65 -0
- package/src/plugins/version-label-game-plugin.ts +1 -1
- package/src/tracking/framerate-counts.ts +50 -0
- package/src/tracking/properties-provider.ts +5 -0
- package/src/tracking/tracker.ts +6 -0
- package/src/tracking/tracking-screen-delegate.ts +48 -0
package/lib/index.d.ts
CHANGED
|
@@ -10,11 +10,16 @@ export * from "./ui/screen-delegate";
|
|
|
10
10
|
export * from "./plugins/automation-game-plugin";
|
|
11
11
|
export * from "./plugins/blur-pausing-game-plugin";
|
|
12
12
|
export * from "./plugins/fullscreen-button-game-plugin";
|
|
13
|
+
export * from "./plugins/metrics-game-plugin";
|
|
13
14
|
export * from "./plugins/storage-game-plugin";
|
|
14
15
|
export * from "./plugins/time-keys-game-plugin";
|
|
15
16
|
export * from "./plugins/version-label-game-plugin";
|
|
16
17
|
export * from "./storage/get-client-storage";
|
|
17
18
|
export * from "./storage/in-memory-storage";
|
|
18
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";
|
|
19
24
|
export * from "./util/math";
|
|
20
25
|
export * from "./util/navigation-flow";
|
package/lib/index.js
CHANGED
|
@@ -26,11 +26,16 @@ __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);
|
|
29
30
|
__exportStar(require("./plugins/storage-game-plugin"), exports);
|
|
30
31
|
__exportStar(require("./plugins/time-keys-game-plugin"), exports);
|
|
31
32
|
__exportStar(require("./plugins/version-label-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);
|
|
36
41
|
__exportStar(require("./util/navigation-flow"), exports);
|
|
@@ -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";
|
|
@@ -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:
|
|
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
|
|
16
|
+
return label;
|
|
17
17
|
})();
|
|
18
18
|
this.styleElement = (() => {
|
|
19
19
|
const styleElt = document.createElement("style");
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrackingScreenDelegate = void 0;
|
|
4
|
+
class TrackingScreenDelegate {
|
|
5
|
+
constructor(screen, tracker) {
|
|
6
|
+
this.screen = screen;
|
|
7
|
+
this.tracker = tracker;
|
|
8
|
+
}
|
|
9
|
+
properties(extraProperties) {
|
|
10
|
+
const merged = {
|
|
11
|
+
"screen.id": this.screen.id,
|
|
12
|
+
"screen.age": this.screen.age,
|
|
13
|
+
};
|
|
14
|
+
Object.assign(merged, extraProperties);
|
|
15
|
+
const screenProperties = this.screen
|
|
16
|
+
.properties;
|
|
17
|
+
if (screenProperties) {
|
|
18
|
+
Object.assign(merged, screenProperties);
|
|
19
|
+
}
|
|
20
|
+
return merged;
|
|
21
|
+
}
|
|
22
|
+
track(eventName, extraProperties = {}) {
|
|
23
|
+
this.tracker.track(eventName, this.properties(extraProperties));
|
|
24
|
+
}
|
|
25
|
+
onSetup() {
|
|
26
|
+
this.track("screenSetup");
|
|
27
|
+
}
|
|
28
|
+
onForeground() {
|
|
29
|
+
this.track("screenForeground");
|
|
30
|
+
}
|
|
31
|
+
onBackground() {
|
|
32
|
+
this.track("screenBackground");
|
|
33
|
+
}
|
|
34
|
+
onDestroy() {
|
|
35
|
+
this.track("screenDestroy");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.TrackingScreenDelegate = TrackingScreenDelegate;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./ui/screen-delegate";
|
|
|
14
14
|
export * from "./plugins/automation-game-plugin";
|
|
15
15
|
export * from "./plugins/blur-pausing-game-plugin";
|
|
16
16
|
export * from "./plugins/fullscreen-button-game-plugin";
|
|
17
|
+
export * from "./plugins/metrics-game-plugin";
|
|
17
18
|
export * from "./plugins/storage-game-plugin";
|
|
18
19
|
export * from "./plugins/time-keys-game-plugin";
|
|
19
20
|
export * from "./plugins/version-label-game-plugin";
|
|
@@ -22,5 +23,10 @@ export * from "./storage/get-client-storage";
|
|
|
22
23
|
export * from "./storage/in-memory-storage";
|
|
23
24
|
export * from "./storage/local-json-store";
|
|
24
25
|
|
|
26
|
+
export * from "./tracking/framerate-counts";
|
|
27
|
+
export * from "./tracking/properties-provider";
|
|
28
|
+
export * from "./tracking/tracker";
|
|
29
|
+
export * from "./tracking/tracking-screen-delegate";
|
|
30
|
+
|
|
25
31
|
export * from "./util/math";
|
|
26
32
|
export * from "./util/navigation-flow";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GamePlugin } from "../game/game-plugin";
|
|
2
|
+
import { UserCancelledError } from "../navigation/resolver";
|
|
3
|
+
import { FrameRateCounts } from "../tracking/framerate-counts";
|
|
4
|
+
import { Tracker } from "../tracking/tracker";
|
|
5
|
+
import { TrackingScreenDelegate } from "../tracking/tracking-screen-delegate";
|
|
6
|
+
import { Screen } from "../ui/screen";
|
|
7
|
+
|
|
8
|
+
export class MetricsGamePlugin extends GamePlugin {
|
|
9
|
+
static readonly key = "metrics";
|
|
10
|
+
readonly key = MetricsGamePlugin.key;
|
|
11
|
+
|
|
12
|
+
private framerateCounts: FrameRateCounts;
|
|
13
|
+
|
|
14
|
+
constructor(readonly tracker: Tracker) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setup(): void {
|
|
19
|
+
super.setup();
|
|
20
|
+
|
|
21
|
+
this.framerateCounts = new FrameRateCounts(
|
|
22
|
+
this.game.performanceRecorder,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
window.addEventListener(
|
|
26
|
+
"error",
|
|
27
|
+
(event) => {
|
|
28
|
+
this.tracker.track("errorOccurred", {
|
|
29
|
+
errorType: "error",
|
|
30
|
+
message: event.message,
|
|
31
|
+
lineno: event.lineno,
|
|
32
|
+
});
|
|
33
|
+
return false;
|
|
34
|
+
},
|
|
35
|
+
false,
|
|
36
|
+
);
|
|
37
|
+
window.addEventListener(
|
|
38
|
+
"unhandledrejection",
|
|
39
|
+
(err) => {
|
|
40
|
+
if (err.reason instanceof UserCancelledError) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.tracker.track("errorOccurred", {
|
|
45
|
+
errorType: "unhandledrejection",
|
|
46
|
+
message: err.reason.message,
|
|
47
|
+
});
|
|
48
|
+
return false;
|
|
49
|
+
},
|
|
50
|
+
false,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
this.tracker.track("gameSetup", {});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
cycle(elapsed: number): void {
|
|
57
|
+
super.cycle(elapsed);
|
|
58
|
+
this.framerateCounts.cycle(elapsed);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setupScreen(screen: Screen): void {
|
|
62
|
+
super.setupScreen(screen);
|
|
63
|
+
screen.delegate = new TrackingScreenDelegate(screen, this.tracker);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -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
|
|
11
|
+
return label;
|
|
12
12
|
})();
|
|
13
13
|
|
|
14
14
|
readonly styleElement = (() => {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { PerformanceRecorder } from "@remvst/client-performance";
|
|
2
|
+
import { Properties } from "./tracker";
|
|
3
|
+
|
|
4
|
+
export class FrameRateCounts {
|
|
5
|
+
private readonly counts = {
|
|
6
|
+
above60: 0,
|
|
7
|
+
above45: 0,
|
|
8
|
+
above30: 0,
|
|
9
|
+
above15: 0,
|
|
10
|
+
above0: 0,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
private age = 0;
|
|
14
|
+
|
|
15
|
+
constructor(private readonly performanceRecorder: PerformanceRecorder) {}
|
|
16
|
+
|
|
17
|
+
cycle(elapsed: number) {
|
|
18
|
+
this.age += elapsed;
|
|
19
|
+
|
|
20
|
+
if (this.age > 0.5) {
|
|
21
|
+
const previousFrame = this.performanceRecorder.frame(
|
|
22
|
+
this.performanceRecorder.frameCount - 1,
|
|
23
|
+
);
|
|
24
|
+
const currentFrame = this.performanceRecorder.frame(
|
|
25
|
+
this.performanceRecorder.frameCount,
|
|
26
|
+
);
|
|
27
|
+
const framerate =
|
|
28
|
+
1000 /
|
|
29
|
+
(currentFrame.onStartTimes.get("FRAME") -
|
|
30
|
+
previousFrame.onStartTimes.get("FRAME"));
|
|
31
|
+
let key: keyof typeof this.counts;
|
|
32
|
+
if (framerate > 60) {
|
|
33
|
+
key = "above60";
|
|
34
|
+
} else if (framerate > 45) {
|
|
35
|
+
key = "above45";
|
|
36
|
+
} else if (framerate > 30) {
|
|
37
|
+
key = "above30";
|
|
38
|
+
} else if (framerate > 15) {
|
|
39
|
+
key = "above15";
|
|
40
|
+
} else {
|
|
41
|
+
key = "above0";
|
|
42
|
+
}
|
|
43
|
+
this.counts[key]++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toJson(): Properties {
|
|
48
|
+
return this.counts;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Screen } from "../ui/screen";
|
|
2
|
+
import { ScreenDelegate } from "../ui/screen-delegate";
|
|
3
|
+
import { PropertiesProvider } from "./properties-provider";
|
|
4
|
+
import { Properties, Tracker } from "./tracker";
|
|
5
|
+
|
|
6
|
+
export class TrackingScreenDelegate implements ScreenDelegate {
|
|
7
|
+
constructor(
|
|
8
|
+
private readonly screen: Screen,
|
|
9
|
+
private readonly tracker: Tracker,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
private properties(extraProperties: Properties) {
|
|
13
|
+
const merged: Properties = {
|
|
14
|
+
"screen.id": this.screen.id,
|
|
15
|
+
"screen.age": this.screen.age,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.assign(merged, extraProperties);
|
|
19
|
+
|
|
20
|
+
const screenProperties = (this.screen as any as PropertiesProvider)
|
|
21
|
+
.properties;
|
|
22
|
+
if (screenProperties) {
|
|
23
|
+
Object.assign(merged, screenProperties);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return merged;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private track(eventName: string, extraProperties: Properties = {}) {
|
|
30
|
+
this.tracker.track(eventName, this.properties(extraProperties));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
onSetup(): void {
|
|
34
|
+
this.track("screenSetup");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
onForeground(): void {
|
|
38
|
+
this.track("screenForeground");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onBackground(): void {
|
|
42
|
+
this.track("screenBackground");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onDestroy(): void {
|
|
46
|
+
this.track("screenDestroy");
|
|
47
|
+
}
|
|
48
|
+
}
|