Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to run local game.json #23

Merged
merged 10 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/headless-driver-runner-v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prepublish": "npm run build",
"build": "rimraf ./lib && tsc -p ./tsconfig.json && npm run formatter",
"formatter": "prettier --write \"src/**/*.ts\" --config ../prettier.config.js",
"test": "npm run build && npm run lint",
"test": "npm run lint",
"lint": "tslint -c ../tslint.json src/**/*.ts -p tsconfig.json -e \"**/node_modules/**\""
},
"publishConfig": {
Expand All @@ -22,13 +22,11 @@
"typings": "lib/index.d.ts",
"dependencies": {
"@akashic/engine-files": "1.1.9",
"@akashic/headless-driver-runner": "0.4.0",
"node-fetch": "2.3.0"
"@akashic/headless-driver-runner": "0.4.0"
},
"devDependencies": {
"@types/node-fetch": "2.1.2",
"prettier": "^1.17.0",
"rimraf": "2.6.3",
"rimraf": "^2.6.3",
"tslint": "^5.16.0",
"typescript": "^3.4.5"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { akashicEngine as g } from "@akashic/engine-files";
import fetch from "node-fetch";
import { loadFile } from "@akashic/headless-driver-runner";

export class NodeScriptAsset extends g.ScriptAsset {
static PRE_SCRIPT: string = "(function(exports, require, module, __filename, __dirname) {\n";
Expand All @@ -12,8 +12,7 @@ export class NodeScriptAsset extends g.ScriptAsset {
}

_load(loader: g.AssetLoadHandler): void {
fetch(this.path, { method: "GET" })
.then(res => res.text())
loadFile<string>(this.path, { json: false })
.then(text => {
this.script = text;
return loader._onAssetLoad(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { akashicEngine as g } from "@akashic/engine-files";
import fetch from "node-fetch";
import { loadFile } from "@akashic/headless-driver-runner";

export class NodeTextAsset extends g.TextAsset {
_load(loader: g.AssetLoadHandler): void {
fetch(this.path, { method: "GET" })
.then(res => res.text())
loadFile<string>(this.path, { json: false })
.then(text => {
this.data = text;
return loader._onAssetLoad(this);
Expand Down
8 changes: 3 additions & 5 deletions packages/headless-driver-runner-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prepublish": "npm run build",
"build": "rimraf ./lib && tsc -p ./tsconfig.json && npm run formatter",
"formatter": "prettier --write \"src/**/*.ts\" --config ../prettier.config.js",
"test": "npm run build && npm run lint",
"test": "npm run lint",
"lint": "tslint -c ../tslint.json src/**/*.ts -p tsconfig.json -e \"**/node_modules/**\""
},
"publishConfig": {
Expand All @@ -22,13 +22,11 @@
"typings": "lib/index.d.ts",
"dependencies": {
"@akashic/engine-files": "2.1.16",
"@akashic/headless-driver-runner": "0.4.0",
"node-fetch": "2.3.0"
"@akashic/headless-driver-runner": "0.4.0"
},
"devDependencies": {
"@types/node-fetch": "2.1.2",
"prettier": "^1.17.0",
"rimraf": "2.6.3",
"rimraf": "^2.6.3",
"tslint": "^5.16.0",
"typescript": "^3.4.5"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { akashicEngine as g } from "@akashic/engine-files";
import fetch from "node-fetch";
import { loadFile } from "@akashic/headless-driver-runner";

export class NodeScriptAsset extends g.ScriptAsset {
static PRE_SCRIPT: string = "(function(exports, require, module, __filename, __dirname) {\n";
Expand All @@ -12,13 +12,14 @@ export class NodeScriptAsset extends g.ScriptAsset {
}

_load(loader: g.AssetLoadHandler): void {
fetch(this.path, { method: "GET" })
.then(res => res.text())
loadFile<string>(this.path, { json: false })
.then(text => {
this.script = text;
return loader._onAssetLoad(this);
})
.catch(e => loader._onAssetError(this, e));
.catch(e => {
loader._onAssetError(this, e);
});
}

execute(execEnv: g.ScriptAssetExecuteEnvironment): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { akashicEngine as g } from "@akashic/engine-files";
import fetch from "node-fetch";
import { loadFile } from "@akashic/headless-driver-runner";

export class NodeTextAsset extends g.TextAsset {
_load(loader: g.AssetLoadHandler): void {
fetch(this.path, { method: "GET" })
.then(res => res.text())
loadFile<string>(this.path, { json: false })
.then(text => {
this.data = text;
return loader._onAssetLoad(this);
Expand Down
12 changes: 6 additions & 6 deletions packages/headless-driver-runner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/headless-driver-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prepublish": "npm run build",
"build": "rimraf ./lib && tsc -p ./tsconfig.json && npm run formatter",
"formatter": "prettier --write \"src/**/*.ts\" --config ../prettier.config.js",
"test": "npm run build && npm run lint",
"test": "npm run lint",
"lint": "tslint -c ../tslint.json src/**/*.ts -p tsconfig.json -e \"**/node_modules/**\""
},
"publishConfig": {
Expand All @@ -23,12 +23,12 @@
"dependencies": {
"@akashic/amflow": "0.2.2",
"@akashic/trigger": "0.1.5",
"node-fetch": "2.3.0"
"node-fetch": "2.5.0"
},
"devDependencies": {
"@types/node-fetch": "2.1.2",
"@types/node-fetch": "2.3.3",
"prettier": "^1.16.0",
"rimraf": "2.6.3",
"rimraf": "^2.6.3",
"tslint": "^5.16.0",
"typescript": "^3.4.5"
}
Expand Down
13 changes: 4 additions & 9 deletions packages/headless-driver-runner/src/Platform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AMFlow } from "@akashic/amflow";
import fetch from "node-fetch";
import { loadFile } from "./utils";

export interface PlatformParameters {
assetBaseUrl: string;
Expand Down Expand Up @@ -30,13 +30,8 @@ export abstract class Platform {
}

loadGameConfiguration(url: string, callback: (err: Error, data?: object) => void): void {
fetch(url, { method: "GET" })
.then(res => res.json())
.then(data => {
callback(null, data);
})
.catch(e => {
callback(e);
});
loadFile<any>(url, { json: true })
.then(json => callback(null, json))
.catch(e => callback(e));
}
}
5 changes: 5 additions & 0 deletions packages/headless-driver-runner/src/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface RunnerParameters {
runnerId: string;
amflow: AMFlow;
executionMode: RunnerExecutionMode;
external?: { [key: string]: string };
gameArgs?: any;
player?: RunnerPlayer;
}
Expand Down Expand Up @@ -73,6 +74,10 @@ export abstract class Runner {
return this.params.player;
}

get external(): { [key: string]: string } | undefined {
return this.params.external;
}

constructor(params: RunnerParameters) {
this.params = params;
}
Expand Down
1 change: 1 addition & 0 deletions packages/headless-driver-runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./Runner";
export * from "./Platform";
export * from "./Looper";
export * from "./utils";
36 changes: 36 additions & 0 deletions packages/headless-driver-runner/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { readFileSync } from "fs";
import fetch from "node-fetch";

export interface ReadFileOption {
encoding?: string;
json?: boolean;
}

/**
* テキストファイルの読み込みを行う。
*
* @param url url または path
*/
export async function loadFile(url: string): Promise<string>;

/**
* ファイルの読み込みを行う。
*
* @param url url または path
* @param opt オプション
*/
export async function loadFile<T>(url: string, opt?: ReadFileOption): Promise<T>;

export async function loadFile<T>(url: string, opt?: ReadFileOption): Promise<T> {
if (isHttpProtocol(url)) {
const res = await fetch(url, { method: "GET" });
return opt.json ? res.json() : res.text();
} else {
const str = readFileSync(url, { encoding: opt.encoding ? opt.encoding : "utf8" });
return opt.json ? JSON.parse(str) : str;
}
}

export function isHttpProtocol(url: string): boolean {
return /^(http|https)\:\/\//.test(url);
}
6 changes: 2 additions & 4 deletions packages/headless-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prepublish": "npm run build",
"build": "rimraf ./lib && tsc -p ./tsconfig.json && npm run formatter",
"formatter": "prettier --write \"src/**/*.ts\" --config ../prettier.config.js",
"test": "npm run build && npm run run:jest && npm run lint",
"test": "npm run run:jest && npm run lint",
"run:jest": "jest",
"lint": "tslint -c ../tslint.json -p tsconfig.json -e \"**/node_modules/**\""
},
Expand All @@ -29,14 +29,12 @@
"@akashic/playlog": "1.3.1",
"@akashic/trigger": "0.1.5",
"js-sha256": "0.9.0",
"lodash.clonedeep": "4.5.0",
"node-fetch": "2.3.0"
"lodash.clonedeep": "4.5.0"
},
"devDependencies": {
"@types/get-port": "4.0.0",
"@types/jest": "24.0.12",
"@types/lodash.clonedeep": "4.5.4",
"@types/node-fetch": "2.1.2",
"get-port": "^5.0.0",
"jest": "^24.8.0",
"prettier": "^1.17.0",
Expand Down
Loading