@akashic/engine-files-reftest-helper 1.3.0-beta.2 → 1.3.0-beta.3
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 +10 -3
- package/lib/index.js +28 -37
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.js +0 -1
- package/package.json +1 -1
- package/lib/types/CustomWindow.d.ts +0 -5
- package/lib/types/CustomWindow.js +0 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ConsoleApiParameter, OutputType } from "./types";
|
|
2
|
+
export interface ReftestHelperBridge {
|
|
3
|
+
outputType: OutputType;
|
|
4
|
+
consoleApiUrl: string;
|
|
5
|
+
postConsole: (param: ConsoleApiParameter) => Promise<Response>;
|
|
6
|
+
screenshot: (fileName: string, base64: string) => Promise<Response | void>;
|
|
7
|
+
finish: () => Promise<Response | void>;
|
|
8
|
+
getImageDataUrlFromCanvas: () => string;
|
|
9
|
+
}
|
|
2
10
|
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
3
11
|
export declare const SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
4
12
|
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
@@ -7,5 +15,4 @@ export declare function postConsole(param: ConsoleApiParameter): Promise<Respons
|
|
|
7
15
|
export declare function screenshot(fileName: string, base64: string): Promise<Response | void>;
|
|
8
16
|
export declare function finish(): Promise<Response | void>;
|
|
9
17
|
export declare function getImageDataUrlFromCanvas(): string;
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function setPropsToCustomWindow(outputType: OutputType, consoleApiUrl: string): void;
|
|
18
|
+
export declare function getReftestHelperBridge(): ReftestHelperBridge;
|
package/lib/index.js
CHANGED
|
@@ -5,24 +5,23 @@ exports.postConsole = postConsole;
|
|
|
5
5
|
exports.screenshot = screenshot;
|
|
6
6
|
exports.finish = finish;
|
|
7
7
|
exports.getImageDataUrlFromCanvas = getImageDataUrlFromCanvas;
|
|
8
|
-
exports.
|
|
9
|
-
exports.setPropsToCustomWindow = setPropsToCustomWindow;
|
|
8
|
+
exports.getReftestHelperBridge = getReftestHelperBridge;
|
|
10
9
|
// TODO 以下2つの定数は大規模化したら別リポジトリに切り出す
|
|
11
10
|
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
12
11
|
exports.SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
13
12
|
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
14
13
|
exports.END_NOTIFICATION_MESSAGE = "engine-files-reftest:finish";
|
|
15
14
|
function postConsole(param) {
|
|
16
|
-
const
|
|
15
|
+
const reftest = getReftestHelperBridge();
|
|
17
16
|
const headers = {
|
|
18
17
|
"Accept": "application/json",
|
|
19
18
|
"Content-Type": "application/json; charset=utf-8"
|
|
20
19
|
};
|
|
21
|
-
return fetch(
|
|
20
|
+
return fetch(reftest.consoleApiUrl, { method: "POST", headers, body: JSON.stringify(param) });
|
|
22
21
|
}
|
|
23
22
|
function screenshot(fileName, base64) {
|
|
24
|
-
const
|
|
25
|
-
switch (
|
|
23
|
+
const reftest = getReftestHelperBridge();
|
|
24
|
+
switch (reftest.outputType) {
|
|
26
25
|
case "post":
|
|
27
26
|
return postConsole({ commandName: "screenshot", screenshotData: { fileName, base64 } });
|
|
28
27
|
case "console":
|
|
@@ -31,8 +30,8 @@ function screenshot(fileName, base64) {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
function finish() {
|
|
34
|
-
const
|
|
35
|
-
switch (
|
|
33
|
+
const reftest = getReftestHelperBridge();
|
|
34
|
+
switch (reftest.outputType) {
|
|
36
35
|
case "post":
|
|
37
36
|
return postConsole({ commandName: "finish" });
|
|
38
37
|
case "console":
|
|
@@ -41,7 +40,12 @@ function finish() {
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
function getImageDataUrlFromCanvas() {
|
|
44
|
-
|
|
43
|
+
if (typeof window === "undefined" || !window.document) {
|
|
44
|
+
throw new Error("window or document is undefined");
|
|
45
|
+
}
|
|
46
|
+
if (typeof g === "undefined" || !g.game) {
|
|
47
|
+
throw new Error("g.game is undefined");
|
|
48
|
+
}
|
|
45
49
|
g.game.render(); // 描画がスキップされてしまうことがあるので、スクリーンショット取得前に現フレームでの描画を行う
|
|
46
50
|
const canvasElements = window.document.getElementsByTagName("canvas");
|
|
47
51
|
const imageUrl = canvasElements[0].toDataURL("image/png");
|
|
@@ -51,24 +55,22 @@ function getImageDataUrlFromCanvas() {
|
|
|
51
55
|
}
|
|
52
56
|
return data[1];
|
|
53
57
|
}
|
|
54
|
-
function
|
|
55
|
-
if (typeof
|
|
56
|
-
throw new Error("
|
|
58
|
+
function getReftestHelperBridge() {
|
|
59
|
+
if (typeof g === "undefined" || !g.game || !g.game.vars || !g.game.vars.reftest) {
|
|
60
|
+
throw new Error("g.game.vars.reftest is undefined");
|
|
57
61
|
}
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
function setPropsToCustomWindow(outputType, consoleApiUrl) {
|
|
61
|
-
const windowAsCustom = getCustomWindow();
|
|
62
|
-
windowAsCustom.outputType = outputType;
|
|
63
|
-
windowAsCustom.consoleApiUrl = consoleApiUrl;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
setPropsToCustomWindow("console", "");
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
// window がない環境で必ずエラーになるので無視する
|
|
62
|
+
return g.game.vars.reftest;
|
|
70
63
|
}
|
|
71
64
|
if (typeof g !== "undefined") {
|
|
65
|
+
// reftest 関連のプロパティを g.game.vars にセットする
|
|
66
|
+
g.game.vars.reftest = {
|
|
67
|
+
outputType: "console",
|
|
68
|
+
consoleApiUrl: "",
|
|
69
|
+
postConsole,
|
|
70
|
+
screenshot,
|
|
71
|
+
finish,
|
|
72
|
+
getImageDataUrlFromCanvas
|
|
73
|
+
};
|
|
72
74
|
const screenshotPromises = [];
|
|
73
75
|
const handleScenario = (msg) => {
|
|
74
76
|
var _a;
|
|
@@ -77,12 +79,8 @@ if (typeof g !== "undefined") {
|
|
|
77
79
|
switch (eventData.command.name) {
|
|
78
80
|
case "init":
|
|
79
81
|
const option = eventData.command.options;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
// window がない環境で必ずエラーになるので無視する
|
|
85
|
-
}
|
|
82
|
+
g.game.vars.reftest.outputType = option.outputType;
|
|
83
|
+
g.game.vars.reftest.consoleApiUrl = option.outputUrl;
|
|
86
84
|
break;
|
|
87
85
|
case "screenshot":
|
|
88
86
|
try {
|
|
@@ -108,11 +106,4 @@ if (typeof g !== "undefined") {
|
|
|
108
106
|
scene.message.add({ func: handleScenario, name: handlerName });
|
|
109
107
|
}
|
|
110
108
|
});
|
|
111
|
-
// エントリポイント以外からも参照できるようにするために g.game.vars に格納しておく
|
|
112
|
-
g.game.vars = {
|
|
113
|
-
postConsole,
|
|
114
|
-
screenshot,
|
|
115
|
-
finish,
|
|
116
|
-
getImageDataUrlFromCanvas
|
|
117
|
-
};
|
|
118
109
|
}
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -19,4 +19,3 @@ __exportStar(require("./ConsoleApiParameter"), exports);
|
|
|
19
19
|
__exportStar(require("./InitCommandOption"), exports);
|
|
20
20
|
__exportStar(require("./OutputType"), exports);
|
|
21
21
|
__exportStar(require("./ScreenshotData"), exports);
|
|
22
|
-
__exportStar(require("./CustomWindow"), exports);
|
package/package.json
CHANGED