@akashic/akashic-sandbox
Version:
Standalone runner for Akashic contents
62 lines (61 loc) • 2.76 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// ビルド時はnode_modules下のakashic-engineモジュールのgを参照しているが、実際に利用するgはjs下のengineFilesV*_*_*.jsのものなので、本来なら実行時に参照するgを動的に決定できるようにすべき
// game.ejs で参照されるため、未使用の lint エラーを抑止
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var SandboxScriptAsset = /** @class */ (function (_super) {
__extends(SandboxScriptAsset, _super);
function SandboxScriptAsset(id, path) {
var _this = _super.call(this, id, path) || this;
// いきなり読んじゃう
var heads = document.getElementsByTagName("head");
var container = (heads.length === 0) ? document.body : heads[0];
var script = document.createElement("script");
script.onload = function () {
_this.script = script.text; // TODO: とれない・・
_this.loading = false;
};
script.onerror = function () {
_this.loading = false;
};
_this.script = undefined;
_this.loading = true;
script.src = _this.path;
container.appendChild(script);
return _this;
}
SandboxScriptAsset.prototype._load = function (loader) {
var _this = this;
var waitLoader = function () {
if (_this.loading) {
setTimeout(waitLoader, 100);
return;
}
if (_this.script !== undefined) {
loader._onAssetLoad(_this);
}
else {
loader._onAssetError(_this, g.ExceptionFactory.createAssetLoadError("can not load script"));
}
};
setTimeout(waitLoader, this.loading ? 100 : 0);
};
SandboxScriptAsset.prototype.execute = function (execEnv) {
window.gScriptContainer[this.path](execEnv);
return execEnv.module.exports;
};
return SandboxScriptAsset;
}(g.ScriptAsset));