UNPKG

@akashic/akashic-sandbox

Version:
1,361 lines (1,353 loc) 2.03 MB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.engineFilesV3_0_17 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ module.exports = require("./lib/index"); },{"./lib/index":77}],2:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssetAccessor = void 0; /** * アセットへのアクセスを提供するアクセッサ群。 * * 実態は `AssetManager` のいくつかのメソッドに対するラッパーである。 * このクラスにより、パス・アセットID・パターン・フィルタから、対応する読み込み済みアセットを取得できる。 * * 通常、ゲーム開発者はこのクラスのオブジェクトを生成する必要はない。 * `g.Scene#asset` に代入されている値を利用すればよい。 */ var AssetAccessor = /** @class */ (function () { /** * `AssetAccessor` のインスタンスを生成する。 * * @param ラップする `AssetManager` */ function AssetAccessor(assetManager) { this._assetManager = assetManager; } /** * パスから読み込み済みの画像アセットを取得する。 * * パスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスでなければならない。 * 当該の画像アセットが読み込まれていない場合、エラー。 * * @param path 取得する画像アセットのパス */ AssetAccessor.prototype.getImage = function (path) { return this._assetManager.peekLiveAssetByAccessorPath(path, "image"); }; /** * パスから読み込み済みのオーディオアセットを取得する。 * * パスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスでなければならない。 * さらにオーディオアセットに限り、拡張子を省いたものでなければならない。(e.g. `"/audio/bgm01"`) * * 当該のオーディオアセットが読み込まれていない場合、エラー。 * * @param path 取得するオーディオアセットのパス */ AssetAccessor.prototype.getAudio = function (path) { return this._assetManager.peekLiveAssetByAccessorPath(path, "audio"); }; /** * パスから読み込み済みのスクリプトアセットを取得する。 * * パスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスでなければならない。 * 当該のスクリプトアセットが読み込まれていない場合、エラー。 * * @param path 取得するスクリプトアセットのパス */ AssetAccessor.prototype.getScript = function (path) { return this._assetManager.peekLiveAssetByAccessorPath(path, "script"); }; /** * パスから読み込み済みのテキストアセットを取得する。 * * パスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスでなければならない。 * 当該のテキストアセットが読み込まれていない場合、エラー。 * * @param path 取得するテキストアセットのパス */ AssetAccessor.prototype.getText = function (path) { return this._assetManager.peekLiveAssetByAccessorPath(path, "text"); }; /** * パスから読み込み済みのテキストアセットを取得し、その内容の文字列を返す。 * * パスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスでなければならない。 * 当該のテキストアセットが読み込まれていない場合、エラー。 * * @param path 内容の文字列を取得するテキストアセットのパス */ AssetAccessor.prototype.getTextContent = function (path) { return this.getText(path).data; }; /** * パスから読み込み済みのテキストアセットを取得し、その内容をJSONとしてパースした値を返す。 * * パスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスでなければならない。 * 当該のテキストアセットが読み込まれていない場合、エラー。 * * @param path 内容のJSONを取得するテキストアセットのパス */ AssetAccessor.prototype.getJSONContent = function (path) { return JSON.parse(this.getTextContent(path)); }; /** * 与えられたパターンまたはフィルタにマッチするパスを持つ、読み込み済みの全画像アセットを取得する。 * * ここでパスはgame.jsonのあるディレクトリをルート (`/`) とする、 `/` 区切りの絶対パスである。 * * パターンは、パス文字列、またはパス中に0個以上の `**`, `*`, `?` を含む文字列である。 * ここで `**` は0個以上の任意のディレクトリを、 `*` は0個以上の `/` でない文字を、 * `?` は1個の `/` でない文字を表す。 (e.g. "/images/monsters??/*.png") * * フィルタは、パスを受け取ってbooleanを返す関数である。 * フィルタを与えた場合、読み込み済みの全アセットのうち、フィルタが偽でない値を返したものを返す。 * * @param patternOrFilter 取得する画像アセットのパスパターンまたはフィルタ。省略した場合、読み込み済みの全て */ AssetAccessor.prototype.getAllImages = function (patternOrFilter) { return this._assetManager.peekAllLiveAssetsByPattern(patternOrFilter !== null && patternOrFilter !== void 0 ? patternOrFilter : "**/*", "image"); }; /** * 与えられたパターンまたはフィルタにマッチするパスを持つ、読み込み済みの全オーディオアセットを取得する。 * 引数の仕様については `AssetAccessor#getAllImages()` の仕様を参照のこと。 * ただしオーディオアセットに限り、拡張子を省いたものでなければならない。(e.g. `"/audio/bgm*"`) * * @param patternOrFilter 取得するオーディオアセットのパスパターンまたはフィルタ。省略した場合、読み込み済みの全て */ AssetAccessor.prototype.getAllAudios = function (patternOrFilter) { return this._assetManager.peekAllLiveAssetsByPattern(patternOrFilter !== null && patternOrFilter !== void 0 ? patternOrFilter : "**/*", "audio"); }; /** * 与えられたパターンまたはフィルタにマッチするパスを持つ、読み込み済みの全スクリプトアセットを取得する。 * 引数の仕様については `AssetAccessor#getAllImages()` の仕様を参照のこと。 * * @param patternOrFilter 取得するスクリプトアセットのパスパターンまたはフィルタ。省略した場合、読み込み済みの全て */ AssetAccessor.prototype.getAllScripts = function (patternOrFilter) { return this._assetManager.peekAllLiveAssetsByPattern(patternOrFilter !== null && patternOrFilter !== void 0 ? patternOrFilter : "**/*", "script"); }; /** * 与えられたパターンまたはフィルタにマッチするパスを持つ、読み込み済みの全テキストアセットを取得する。 * 引数の仕様については `AssetAccessor#getAllImages()` の仕様を参照のこと。 * * @param patternOrFilter 取得するテキストアセットのパスパターンまたはフィルタ。省略した場合、読み込み済みの全て */ AssetAccessor.prototype.getAllTexts = function (patternOrFilter) { return this._assetManager.peekAllLiveAssetsByPattern(patternOrFilter !== null && patternOrFilter !== void 0 ? patternOrFilter : "**/*", "text"); }; /** * アセットIDから読み込み済みの画像アセットを取得する。 * 当該の画像アセットが読み込まれていない場合、エラー。 * * @param assetId 取得する画像アセットのID */ AssetAccessor.prototype.getImageById = function (assetId) { return this._assetManager.peekLiveAssetById(assetId, "image"); }; /** * アセットIDから読み込み済みのオーディオアセットを取得する。 * 当該のオーディオアセットが読み込まれていない場合、エラー。 * * @param assetId 取得するオーディオアセットのID */ AssetAccessor.prototype.getAudioById = function (assetId) { return this._assetManager.peekLiveAssetById(assetId, "audio"); }; /** * アセットIDから読み込み済みのスクリプトアセットを取得する。 * 当該のスクリプトアセットが読み込まれていない場合、エラー。 * * @param assetId 取得するスクリプトアセットのID */ AssetAccessor.prototype.getScriptById = function (assetId) { return this._assetManager.peekLiveAssetById(assetId, "script"); }; /** * アセットIDから読み込み済みのテキストアセットを取得する。 * 当該のテキストアセットが読み込まれていない場合、エラー。 * * @param assetId 取得するテキストアセットのID */ AssetAccessor.prototype.getTextById = function (assetId) { return this._assetManager.peekLiveAssetById(assetId, "text"); }; /** * アセットIDから読み込み済みのテキストアセットを取得し、その内容の文字列を返す。 * 当該のテキストアセットが読み込まれていない場合、エラー。 * * @param assetId 内容の文字列を取得するテキストアセットのID */ AssetAccessor.prototype.getTextContentById = function (assetId) { return this.getTextById(assetId).data; }; /** * アセットIDから読み込み済みのテキストアセットを取得し、その内容をJSONとしてパースして返す。 * 当該のテキストアセットが読み込まれていない場合、エラー。 * * @param assetId 内容のJSONを取得するテキストアセットのID */ AssetAccessor.prototype.getJSONContentById = function (assetId) { return JSON.parse(this.getTextById(assetId).data); }; return AssetAccessor; }()); exports.AssetAccessor = AssetAccessor; },{}],3:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); },{}],4:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssetHolder = void 0; var ExceptionFactory_1 = require("./ExceptionFactory"); /** * シーンのアセットの読み込みと破棄を管理するクラス。 * 本クラスのインスタンスをゲーム開発者が直接生成することはなく、ゲーム開発者が利用する必要もない。 */ var AssetHolder = /** @class */ (function () { function AssetHolder(param) { var assetManager = param.assetManager; var assetIds = param.assetIds ? param.assetIds.concat() : []; assetIds.push.apply(assetIds, assetManager.resolvePatternsToAssetIds(param.assetPaths || [])); this.waitingAssetsCount = assetIds.length; this.userData = param.userData; this._assetManager = assetManager; this._assetIds = assetIds; this._assets = []; this._handlerSet = param.handlerSet; this._requested = false; } AssetHolder.prototype.request = function () { if (this.waitingAssetsCount === 0) return false; if (this._requested) return true; this._requested = true; this._assetManager.requestAssets(this._assetIds, this); return true; }; AssetHolder.prototype.destroy = function () { if (this._requested) { this._assetManager.unrefAssets(this._assets); } this.waitingAssetsCount = 0; this.userData = undefined; this._handlerSet = undefined; this._assetIds = undefined; this._requested = false; }; AssetHolder.prototype.destroyed = function () { return !this._handlerSet; }; /** * @private */ AssetHolder.prototype._onAssetError = function (asset, error) { var hs = this._handlerSet; if (this.destroyed() || hs.owner.destroyed()) return; var failureInfo = { asset: asset, error: error, cancelRetry: false }; hs.handleLoadFailure.call(hs.owner, failureInfo); if (error.retriable && !failureInfo.cancelRetry) { this._assetManager.retryLoad(asset); } else { // game.json に定義されていればゲームを止める。それ以外 (DynamicAsset) では続行。 if (this._assetManager.configuration[asset.id]) { hs.handleFinish.call(hs.owner, this, false); } } }; /** * @private */ AssetHolder.prototype._onAssetLoad = function (asset) { var hs = this._handlerSet; if (this.destroyed() || hs.owner.destroyed()) return; hs.handleLoad.call(hs.owner, asset); this._assets.push(asset); --this.waitingAssetsCount; if (this.waitingAssetsCount > 0) return; if (this.waitingAssetsCount < 0) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetHolder#_onAssetLoad: broken waitingAssetsCount"); hs.handleFinish.call(hs.owner, this, true); }; return AssetHolder; }()); exports.AssetHolder = AssetHolder; },{"./ExceptionFactory":24}],5:[function(require,module,exports){ arguments[4][3][0].apply(exports,arguments) },{"dup":3}],6:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssetManager = void 0; var ExceptionFactory_1 = require("./ExceptionFactory"); var VideoSystem_1 = require("./VideoSystem"); /** * @ignore */ var AssetLoadingInfo = /** @class */ (function () { function AssetLoadingInfo(asset, handler) { this.asset = asset; this.handlers = [handler]; this.errorCount = 0; this.loading = false; } return AssetLoadingInfo; }()); function normalizeAudioSystemConfMap(confMap) { if (confMap === void 0) { confMap = {}; } var systemDefaults = { music: { loop: true, hint: { streaming: true } }, sound: { loop: false, hint: { streaming: false } } }; for (var key in systemDefaults) { if (!(key in confMap)) { confMap[key] = systemDefaults[key]; } } return confMap; } /** * パスパターンを関数に変換する。 * * パスパターンは、パス文字列、または0個以上の `**`, `*`, `?` を含むパス文字列である。 * (実装の単純化のため、いわゆる glob のうちよく使われそうなものだけをサポートしている。) * 詳細は `AssetAccessor#getAllImages()` の仕様を参照のこと。 * * 戻り値は、文字列一つを受け取り、パターンにマッチするか否かを返す関数。 * * @param pattern パターン文字列 */ function patternToFilter(pattern) { var parserRe = /([^\*\\\?]*)(\\\*|\\\?|\?|\*(?!\*)|\*\*\/|$)/g; // [----A-----][--------------B---------------] // A: パターンの特殊文字でない文字の塊。そのままマッチさせる(ためにエスケープして正規表現にする) // B: パターンの特殊文字一つ(*, ** など)かそのエスケープ。patternSpecialsTable で対応する正規表現に変換 var patternSpecialsTable = { "": "", "\\*": "\\*", "\\?": "\\?", "*": "[^/]*", "?": "[^/]", "**/": "(?:^/)?(?:[^/]+/)*" // [--C--][----D----] // C: 行頭の `/` (行頭でなければないので ? つき) // D: ディレクトリ一つ分(e.g. "foo/")が0回以上 }; var regExpSpecialsRe = /[\\^$.*+?()[\]{}|]/g; function escapeRegExp(s) { return s.replace(regExpSpecialsRe, "\\$&"); } var code = ""; for (var match = parserRe.exec(pattern); match && match[0] !== ""; match = parserRe.exec(pattern)) { code += escapeRegExp(match[1]) + patternSpecialsTable[match[2]]; } var re = new RegExp("^" + code + "$"); return function (path) { return re.test(path); }; } /** * `Asset` を管理するクラス。 * * このクラスのインスタンスは `Game` に一つデフォルトで存在する(デフォルトアセットマネージャ)。 * デフォルトアセットマネージャは、game.json に記述された通常のアセットを読み込むために利用される。 * * ゲーム開発者は、game.json に記述のないリソースを取得するために、このクラスのインスタンスを独自に生成してよい。 */ var AssetManager = /** @class */ (function () { /** * `AssetManager` のインスタンスを生成する。 * * @param gameParams このインスタンスが属するゲーム。 * @param conf このアセットマネージャに与えるアセット定義。game.json の `"assets"` に相当。 * @param audioSystemConfMap このアセットマネージャに与えるオーディオシステムの宣言。 * @param moduleMainScripts このアセットマネージャに与える require() 解決用のエントリポイント。 */ function AssetManager(gameParams, conf, audioSystemConfMap, moduleMainScripts) { this._resourceFactory = gameParams.resourceFactory; this._audioSystemManager = gameParams.audio; this._defaultAudioSystemId = gameParams.defaultAudioSystemId; this.configuration = this._normalize(conf || {}, normalizeAudioSystemConfMap(audioSystemConfMap)); this._assets = {}; this._virtualPathToIdTable = {}; this._liveAssetVirtualPathTable = {}; this._liveAssetPathTable = {}; this._moduleMainScripts = moduleMainScripts ? moduleMainScripts : {}; this._refCounts = {}; this._loadings = {}; var assetIds = Object.keys(this.configuration); for (var i = 0; i < assetIds.length; ++i) { var assetId = assetIds[i]; var conf_1 = this.configuration[assetId]; this._virtualPathToIdTable[conf_1.virtualPath] = assetId; } } /** * このインスタンスを破棄する。 */ AssetManager.prototype.destroy = function () { var assetIds = Object.keys(this._refCounts); for (var i = 0; i < assetIds.length; ++i) { this._releaseAsset(assetIds[i]); } this.configuration = undefined; this._assets = undefined; this._liveAssetVirtualPathTable = undefined; this._liveAssetPathTable = undefined; this._refCounts = undefined; this._loadings = undefined; }; /** * このインスタンスが破棄済みであるかどうかを返す。 */ AssetManager.prototype.destroyed = function () { return this._assets === undefined; }; /** * `Asset` の読み込みを再試行する。 * * 引数 `asset` は読み込みの失敗が (`Scene#assetLoadFail` で) 通知されたアセットでなければならない。 * @param asset 読み込みを再試行するアセット */ AssetManager.prototype.retryLoad = function (asset) { if (!this._loadings.hasOwnProperty(asset.id)) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#retryLoad: invalid argument."); var loadingInfo = this._loadings[asset.id]; if (loadingInfo.errorCount > AssetManager.MAX_ERROR_COUNT) { // DynamicAsset はエラーが規定回数超えた場合は例外にせず諦める。 if (!this.configuration[asset.id]) return; throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#retryLoad: too many retrying."); } if (!loadingInfo.loading) { loadingInfo.loading = true; asset._load(this); } }; /** * グローバルアセットのIDを全て返す。 */ AssetManager.prototype.globalAssetIds = function () { var ret = []; var conf = this.configuration; for (var p in conf) { if (!conf.hasOwnProperty(p)) continue; if (conf[p].global) ret.push(p); } return ret; }; /** * パターンまたはフィルタに合致するパスを持つアセットIDを全て返す。 * * 戻り値は読み込み済みでないアセットのIDを含むことに注意。 * 読み込み済みのアセットにアクセスする場合は、 `peekAllLiveAssetsByPattern()` を利用すること。 * * @param patternOrFilters パターンまたはフィルタ。仕様は `AssetAccessor#getAllImages()` を参照 */ AssetManager.prototype.resolvePatternsToAssetIds = function (patternOrFilters) { if (patternOrFilters.length === 0) return []; var vpaths = Object.keys(this._virtualPathToIdTable); var ret = []; for (var i = 0; i < patternOrFilters.length; ++i) { var patternOrFilter = patternOrFilters[i]; var filter = typeof patternOrFilter === "string" ? patternToFilter(this._replaceModulePathToAbsolute(patternOrFilter)) : patternOrFilter; for (var j = 0; j < vpaths.length; ++j) { var vpath = vpaths[j]; var accessorPath = "/" + vpath; // virtualPath に "/" を足すと accessorPath という仕様 if (filter(accessorPath)) ret.push(this._virtualPathToIdTable[vpath]); } } return ret; }; /** * アセットの取得を要求する。 * * 要求したアセットが読み込み済みでない場合、読み込みが行われる。 * 取得した結果は `handler` を通して通知される。 * ゲーム開発者はこのメソッドを呼び出してアセットを取得した場合、 * 同じアセットID(または取得したアセット)で `unrefAsset()` を呼び出さなければならない。 * * @param assetIdOrConf 要求するアセットのIDまたは設定 * @param handler 要求結果を受け取るハンドラ */ AssetManager.prototype.requestAsset = function (assetIdOrConf, handler) { var assetId = typeof assetIdOrConf === "string" ? assetIdOrConf : assetIdOrConf.id; var waiting = false; var loadingInfo; if (this._assets.hasOwnProperty(assetId)) { ++this._refCounts[assetId]; handler._onAssetLoad(this._assets[assetId]); } else if (this._loadings.hasOwnProperty(assetId)) { loadingInfo = this._loadings[assetId]; loadingInfo.handlers.push(handler); ++this._refCounts[assetId]; waiting = true; } else { var a = this._createAssetFor(assetIdOrConf); loadingInfo = new AssetLoadingInfo(a, handler); this._loadings[assetId] = loadingInfo; this._refCounts[assetId] = 1; waiting = true; loadingInfo.loading = true; a._load(this); } return waiting; }; /** * アセットの参照カウントを減らす。 * 引数の各要素で `unrefAsset()` を呼び出す。 * * @param assetOrId 参照カウントを減らすアセットまたはアセットID */ AssetManager.prototype.unrefAsset = function (assetOrId) { var assetId = typeof assetOrId === "string" ? assetOrId : assetOrId.id; if (--this._refCounts[assetId] > 0) return; this._releaseAsset(assetId); }; /** * 複数のアセットの取得を要求する。 * 引数の各要素で `requestAsset()` を呼び出す。 * * @param assetIdOrConfs 取得するアセットのIDまたはアセット定義 * @param handler 取得の結果を受け取るハンドラ */ AssetManager.prototype.requestAssets = function (assetIdOrConfs, handler) { var waitingCount = 0; for (var i = 0, len = assetIdOrConfs.length; i < len; ++i) { if (this.requestAsset(assetIdOrConfs[i], handler)) { ++waitingCount; } } return waitingCount; }; /** * 複数のアセットを解放する。 * 引数の各要素で `unrefAsset()` を呼び出す。 * * @param assetOrIds 参照カウントを減らすアセットまたはアセットID * @private */ AssetManager.prototype.unrefAssets = function (assetOrIds) { for (var i = 0, len = assetOrIds.length; i < len; ++i) { this.unrefAsset(assetOrIds[i]); } }; /** * アクセッサパスで指定された読み込み済みのアセットを返す。 * * ここでアクセッサパスとは、 `AssetAccessor` が使うパス * (game.jsonのディレクトリをルート (`/`) とする、 `/` 区切りの絶対パス形式の仮想パス)である。 * これは `/` を除けばアセットの仮想パス (virtualPath) と同一である。 * * @param accessorPath 取得するアセットのアクセッサパス * @param type 取得するアセットのタイプ。対象のアセットと合致しない場合、エラー */ AssetManager.prototype.peekLiveAssetByAccessorPath = function (accessorPath, type) { accessorPath = this._replaceModulePathToAbsolute(accessorPath); if (accessorPath[0] !== "/") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#peekLiveAssetByAccessorPath(): accessorPath must start with '/'"); var vpath = accessorPath.slice(1); // accessorPath から "/" を削ると virtualPath という仕様 var asset = this._liveAssetVirtualPathTable[vpath]; if (!asset || type !== asset.type) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#peekLiveAssetByAccessorPath(): No " + type + " asset for " + accessorPath); return asset; }; /** * アセットIDで指定された読み込み済みのアセットを返す。 * * @param assetId 取得するアセットのID * @param type 取得するアセットのタイプ。対象のアセットと合致しない場合、エラー */ AssetManager.prototype.peekLiveAssetById = function (assetId, type) { var asset = this._assets[assetId]; if (!asset || type !== asset.type) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("SceneAssetManager#_getById(): No " + type + " asset for id " + assetId); return asset; }; /** * パターンまたはフィルタにマッチするパスを持つ、指定されたタイプの全読み込み済みアセットを返す。 * * 戻り値の要素の順序は保証されない。 * パターンとフィルタについては `AssetAccessor#getAllImages()` の仕様を参照のこと。 * * @param patternOrFilter 取得するアセットのパスパターンまたはフィルタ * @param type 取得するアセットのタイプ。 null の場合、全てのタイプとして扱われる。 */ AssetManager.prototype.peekAllLiveAssetsByPattern = function (patternOrFilter, type) { var vpaths = Object.keys(this._liveAssetVirtualPathTable); var filter = typeof patternOrFilter === "string" ? patternToFilter(this._replaceModulePathToAbsolute(patternOrFilter)) : patternOrFilter; var ret = []; for (var i = 0; i < vpaths.length; ++i) { var vpath = vpaths[i]; var asset = this._liveAssetVirtualPathTable[vpath]; if (type && asset.type !== type) continue; var accessorPath = "/" + vpath; // virtualPath に "/" を足すと accessorPath という仕様 if (filter(accessorPath)) ret.push(asset); } return ret; }; /** * @ignore */ AssetManager.prototype._normalize = function (configuration, audioSystemConfMap) { var ret = {}; if (!(configuration instanceof Object)) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: invalid arguments."); for (var p in configuration) { if (!configuration.hasOwnProperty(p)) continue; var conf = Object.create(configuration[p]); if (!conf.path) { throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: No path given for: " + p); } if (!conf.virtualPath) { throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: No virtualPath given for: " + p); } if (!conf.type) { throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: No type given for: " + p); } if (conf.type === "image") { if (typeof conf.width !== "number") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: wrong width given for the image asset: " + p); if (typeof conf.height !== "number") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: wrong height given for the image asset: " + p); } if (conf.type === "audio") { // durationというメンバは後から追加したため、古いgame.jsonではundefinedになる場合がある if (conf.duration === undefined) conf.duration = 0; var audioSystemConf = audioSystemConfMap[conf.systemId]; if (conf.loop === undefined) { conf.loop = !!audioSystemConf && !!audioSystemConf.loop; } if (conf.hint === undefined) { conf.hint = audioSystemConf ? audioSystemConf.hint : {}; } if (conf.systemId !== "music" && conf.systemId !== "sound") { throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: wrong systemId given for the audio asset: " + p); } } if (conf.type === "video") { if (!conf.useRealSize) { if (typeof conf.width !== "number") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: wrong width given for the video asset: " + p); if (typeof conf.height !== "number") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_normalize: wrong height given for the video asset: " + p); conf.useRealSize = false; } } if (!conf.global) conf.global = false; ret[p] = conf; } return ret; }; /** * @private */ AssetManager.prototype._createAssetFor = function (idOrConf) { var id; var uri; var conf; if (typeof idOrConf === "string") { id = idOrConf; conf = this.configuration[id]; uri = this.configuration[id].path; } else { var dynConf = idOrConf; id = dynConf.id; conf = dynConf; uri = dynConf.uri; } var resourceFactory = this._resourceFactory; if (!conf) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_createAssetFor: unknown asset ID: " + id); switch (conf.type) { case "image": var asset = resourceFactory.createImageAsset(id, uri, conf.width, conf.height); asset.initialize(conf.hint); return asset; case "audio": var system = conf.systemId ? this._audioSystemManager[conf.systemId] : this._audioSystemManager[this._defaultAudioSystemId]; return resourceFactory.createAudioAsset(id, uri, conf.duration, system, !!conf.loop, conf.hint); case "text": return resourceFactory.createTextAsset(id, uri); case "script": return resourceFactory.createScriptAsset(id, uri); case "video": // VideoSystemはまだ中身が定義されていなが、将来のためにVideoAssetにVideoSystemを渡すという体裁だけが整えられている。 // 以上を踏まえ、ここでは簡単のために都度新たなVideoSystemインスタンスを生成している。 var videoSystem = new VideoSystem_1.VideoSystem(); return resourceFactory.createVideoAsset(id, uri, conf.width, conf.height, videoSystem, !!conf.loop, !!conf.useRealSize); default: throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssertionError#_createAssetFor: unknown asset type " + conf.type + " for asset ID: " + id); } }; /** * @ignore */ AssetManager.prototype._releaseAsset = function (assetId) { var asset = this._assets[assetId] || (this._loadings[assetId] && this._loadings[assetId].asset); var path = null; if (asset) { path = asset.path; if (asset.inUse()) { if (asset.type === "audio") { asset._system.requestDestroy(asset); } else if (asset.type === "video") { // NOTE: 一旦再生完了を待たずに破棄することにする // TODO: 再生中の動画を破棄するタイミングをどのように扱うか検討し実装 asset.destroy(); } else { throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#unrefAssets: Unsupported in-use " + asset.id); } } else { asset.destroy(); } } delete this._refCounts[assetId]; delete this._loadings[assetId]; delete this._assets[assetId]; if (this.configuration[assetId]) { var virtualPath = this.configuration[assetId].virtualPath; if (virtualPath && this._liveAssetVirtualPathTable.hasOwnProperty(virtualPath)) delete this._liveAssetVirtualPathTable[virtualPath]; if (path && this._liveAssetPathTable.hasOwnProperty(path)) delete this._liveAssetPathTable[path]; } }; /** * 現在ロード中のアセットの数。(デバッグ用; 直接の用途はない) * @private */ AssetManager.prototype._countLoadingAsset = function () { return Object.keys(this._loadings).length; }; /** * @private */ AssetManager.prototype._onAssetError = function (asset, error) { // ロード中に Scene が破棄されていた場合などで、asset が破棄済みになることがある if (this.destroyed() || asset.destroyed()) return; var loadingInfo = this._loadings[asset.id]; var hs = loadingInfo.handlers; loadingInfo.loading = false; ++loadingInfo.errorCount; if (loadingInfo.errorCount > AssetManager.MAX_ERROR_COUNT && error.retriable) { error = ExceptionFactory_1.ExceptionFactory.createAssetLoadError("Retry limit exceeded", false, null, error); } if (!error.retriable) delete this._loadings[asset.id]; for (var i = 0; i < hs.length; ++i) hs[i]._onAssetError(asset, error, this.retryLoad.bind(this)); }; /** * @private */ AssetManager.prototype._onAssetLoad = function (asset) { // ロード中に Scene が破棄されていた場合などで、asset が破棄済みになることがある if (this.destroyed() || asset.destroyed()) return; var loadingInfo = this._loadings[asset.id]; loadingInfo.loading = false; delete this._loadings[asset.id]; this._assets[asset.id] = asset; // DynamicAsset の場合は configuration に書かれていないので以下の判定が偽になる if (this.configuration[asset.id]) { var virtualPath = this.configuration[asset.id].virtualPath; if (!this._liveAssetVirtualPathTable.hasOwnProperty(virtualPath)) { this._liveAssetVirtualPathTable[virtualPath] = asset; } else { if (this._liveAssetVirtualPathTable[virtualPath].path !== asset.path) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AssetManager#_onAssetLoad(): duplicated asset path"); } if (!this._liveAssetPathTable.hasOwnProperty(asset.path)) this._liveAssetPathTable[asset.path] = virtualPath; } var hs = loadingInfo.handlers; for (var i = 0; i < hs.length; ++i) hs[i]._onAssetLoad(asset); }; /** * @private */ AssetManager.prototype._replaceModulePathToAbsolute = function (accessorPath) { if (accessorPath[0] === "/" || accessorPath[0] === "*" // パスに `**/*` が指定された場合 ) { return accessorPath; } for (var moduleName in this._moduleMainScripts) { if (!this._moduleMainScripts.hasOwnProperty(moduleName)) continue; if (accessorPath.lastIndexOf(moduleName, 0) === 0) { return "/node_modules/" + accessorPath; } } return accessorPath; }; AssetManager.MAX_ERROR_COUNT = 3; return AssetManager; }()); exports.AssetManager = AssetManager; },{"./ExceptionFactory":24,"./VideoSystem":66}],7:[function(require,module,exports){ arguments[4][3][0].apply(exports,arguments) },{"dup":3}],8:[function(require,module,exports){ "use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.SoundAudioSystem = exports.MusicAudioSystem = exports.AudioSystem = void 0; var ExceptionFactory_1 = require("./ExceptionFactory"); var AudioSystem = /** @class */ (function () { function AudioSystem(param) { this.id = param.id; this._volume = param.volume || 1; this._destroyRequestedAssets = {}; this._explicitMuted = param.muted || false; this._suppressed = false; this._muted = false; this._resourceFactory = param.resourceFactory; this._updateMuted(); } Object.defineProperty(AudioSystem.prototype, "volume", { // volumeの変更時には通知が必要なのでアクセサを使う。 // 呼び出し頻度が少ないため許容。 get: function () { return this._volume; }, set: function (value) { if (value < 0 || value > 1 || isNaN(value) || typeof value !== "number") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AudioSystem#volume: expected: 0.0-1.0, actual: " + value); this._volume = value; this._onVolumeChanged(); }, enumerable: false, configurable: true }); AudioSystem.prototype.requestDestroy = function (asset) { this._destroyRequestedAssets[asset.id] = asset; }; /** * @private */ AudioSystem.prototype._reset = function () { this.stopAll(); this._volume = 1; this._destroyRequestedAssets = {}; this._muted = false; this._suppressed = false; this._explicitMuted = false; }; /** * @private */ AudioSystem.prototype._setMuted = function (value) { var before = this._explicitMuted; this._explicitMuted = !!value; if (this._explicitMuted !== before) { this._updateMuted(); this._onMutedChanged(); } }; /** * @private */ AudioSystem.prototype._setPlaybackRate = function (value) { if (value < 0 || isNaN(value) || typeof value !== "number") throw ExceptionFactory_1.ExceptionFactory.createAssertionError("AudioSystem#playbackRate: expected: greater or equal to 0.0, actual: " + value); this._suppressed = value !== 1.0; this._updateMuted(); }; /** * @private */ AudioSystem.prototype._updateMuted = function () { this._muted = this._explicitMuted || this._suppressed; }; return AudioSystem; }()); exports.AudioSystem = AudioSystem; var MusicAudioSystem = /** @class */ (function (_super) { __extends(MusicAudioSystem, _super); function MusicAudioSystem(param) { var _this = _super.call(this, param) || this; _this._player = undefined; return _this; } Object.defineProperty(MusicAudioSystem.prototype, "player", { // Note: 音楽のないゲームの場合に無駄なインスタンスを作るのを避けるため、アクセサを使う get: function () { if (!this._player) { this._player = this._resourceFactory.createAudioPlayer(this); this._player.onPlay.add(this._handlePlay, this); this._player.onStop.add(this._handleStop, this); } return this._player; }, set: function (v) { this._player = v; }, enumerable: false, configurable: true }); MusicAudioSystem.prototype.findPlayers = function (asset) { if (this.player.currentAudio && this.player.currentAudio.id === asset.id) return [this.player]; return []; }; MusicAudioSystem.prototype.createPlayer = function () { return this.player; }; MusicAudioSystem.prototype.stopAll = function () { if (!this._player) return; this._player.stop(); }; /** * @private */ MusicAudioSystem.prototype._reset = function () { _super.prototype._reset.call(this); if (this._player) { this._player.onPlay.remove(this._handlePlay, this); this._player.onStop.remove(this._handleStop, this); } this._player = undefined; }; /** * @private */ MusicAudioSystem.prototype._onVolumeChanged = function () { this.player._notifyVolumeChanged(); }; /** * @private */ MusicAudioSystem.prototype._onMutedChanged = function () { this.player._changeMuted(this._muted); }; /** * @private */ MusicAudioSystem.prototype._setPlaybackRate = function (rate) { _super.prototype._setPlaybackRate.call(this, rate); this.player._changeMuted(this._muted); }; /** * @private */ MusicAudioSystem.prototype._handlePlay = function (e) { if (e.player !== this._player) throw ExceptionFactory_1.ExceptionFactory.createAssertionError("MusicAudioSystem#_onPlayerPlayed: unexpected audio player"); }; /** * @private */ MusicAudioSystem.prototype._handleStop = function (e) { if (this._destroyRequestedAssets[e.audio.id]) { delete this._destroyRequestedAssets[e.audio.id]; e.audio.destroy(); } }; return MusicAudioSystem; }(AudioSystem)); exports.MusicAudioSystem = MusicAudioSystem; var SoundAudioSystem = /** @class */ (function (_super) { __extends(SoundAudioSystem, _super); function SoundAudioSystem(param) { var _this = _super.call(this, param) || this; _this.players = []; return _this; } SoundAudioSystem.prototype.createPlayer = function () { var player = this._resourceFactory.createAudioPlayer(this); if (player.canHandleStopped()) this.players.push(player); player.onPlay.add(this._handlePlay, this); player.onStop.add(this._handleStop, this); return player; }; SoundAudioSystem.prototype.findPlayers = function (asset) { var ret = []; for (var i = 0; i < this.players.length; ++i) { var currentAudio = this.players[i].currentAudio; if (currentAudio && currentAudio.id === asset.id) ret.push(this.players[i]); } return ret; }; SoundAudioSystem.prototype.stopAll = function () { var players = this.players.concat(); for (var i = 0; i < players.length; ++i) { players[i].stop(); // auto remove } }; /** * @private */ SoundAudioSystem.prototype._reset = function () { _super.prototype._reset.call(this); for (var i = 0; i < this.players.length; ++i) { var player = this.players[i]; player.onPlay.remove(this._handlePlay, this); player.onStop.remove(this._handleStop, this); } this.players = []; }; /** * @private */ SoundAudioSystem.prototype._onMutedChanged = function () { var players = this.players; for (var i = 0; i < players.length; ++i) { players[i]._changeMuted(this._muted); } }; /** * @private */ SoundAudioSystem.prototype._setPlaybackRate = function (rate) { _super.prototype._setPlaybackRate.call(this, rate); var players = this.players; if (this._suppressed) { for (var i = 0; i < players.length; ++i) { players[i]._changeMuted(true); } } }; /** * @private */ SoundAudioSystem.prototype._handlePlay = function (_e) { // do nothing }; /** * @private */ SoundAudioSystem.prototype._handleStop = function (e) { var index = this.players.indexOf(e.player); if (index < 0) return; e.player.onStop.remove(this._handleStop, this); this.players.splice(index, 1); if (this._destroyRequestedAssets[e.audio.id]) { delete this._destroyRequestedAssets[e.audio.id]; e.audio.destroy(); } }; /** * @private */ SoundAudioSystem.prototype._onVolumeChanged = function () { for (var i = 0; i < this.players.length; ++i) { this.players[i]._notifyVolumeChanged(); } }; return SoundAudioSystem; }(AudioSystem)); exports.SoundAudioSystem = SoundAudioSystem; },{"./ExceptionFactory":24}],9:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AudioSystemManager = void 0; var AudioSystem_1 = require("./AudioSystem"); /** * `AudioSystem` の管理クラス。 * * 複数の `AudioSystem` に一括で必要な状態設定を行う。 * 本クラスのインスタンスをゲーム開発者が直接生成することはなく、ゲーム開発者が利用する必要もない。 */ var AudioSystemManager = /** @class */ (function () { function AudioSystemManager(resourceFactory) { this._muted = false; this._initializeAudioSystems(resourceFactory); } /** * @private */ AudioSystemManager.prototype._reset = function () { this._muted = false; this.music._reset(); this.sound._reset(); }; /** * @private */ AudioSystemManager.prototype._setMuted = function (muted) { if (this._muted === muted) return; this._muted = muted; this.music._setMuted(muted); this.sound._setMuted(muted); }; /** * @private */ AudioSystemManager.prototype._setPlaybackRate = function (rate) { this.music._setPlaybackRate(rate); this.sound._setPlaybackRate(rate); }; /** * @private */ AudioSystemManager.prototype._initializeAudioSystems = function (resourceFactory) { this.music = new AudioSystem_1.MusicAudioSystem({ id: "music", muted: this._muted, resourceFactory: resourceFactory }); this.sound = new AudioSystem_1.SoundAudioSystem({ id: "sound", muted: this._muted, resourceFactory: resourceFactory }); }; AudioSystemManager.prototype.stopAll = function () { this.music.stopAll(); this.sound.stopAll(); }; return AudioSystemManager; }()); exports.AudioSystemManager = AudioSystemManager; },{"./AudioSystem":8}],10:[function(require,module,exports){ "use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BitmapFont = void 0; var Font_1 = require("./Font"); var SurfaceUtil_1 = require("./SurfaceUtil"); /** * ラスタ画像によるフォント。 */ var BitmapFont = /** @class */ (function (_super) { __extends(BitmapFont, _super); /** * 各種パラメータを指定して `BitmapFont` のインスタンスを生成する。 * @param param `BitmapFont` に設定するパラメータ */ function BitmapFont(param) { var _this = _super.call(this) || this; // @ts-ignore _this.surface = SurfaceUtil_1.SurfaceUtil.asSurface(param.src); if (param.glyphInfo) { _this.map = param.glyphInfo.map; _this.defaultGlyphWidth = param.glyphInfo.width; _this.defaultGlyphHeight = param.glyphInfo.height; _this.missingGlyph = param.glyphInfo.missingGlyph; _this.size = param.glyphInfo.height; } else { _this.map = param.map || {}; _this.defaultGlyphWidth = param.defaultGlyphWidth || 0; _this.defaultGlyphHeight = param.defaultGlyphHeight || 0; _this.missingGlyph = param.missingGlyph; _this.size = param.defaultGlyphHeight || 0; } return _this; } /** * コードポイントに対応するグリフを返す。 * @param code コードポイント */ BitmapFont.prototype.glyphForCharacter = function (code) { var g = this.map[code] || this.missingGlyph; if (!g) { return null; } var w = g.width === undefined ? this.defaultGlyphWidth : g.width; var h = g.height === undefined ? this.defaultGlyphHeight : g.height; var offsetX = g.offsetX || 0; var offsetY = g.offsetY || 0; var advanceWidth = g.advanceWidth === undefined ? w : g.advanceWidth; var surface = w === 0 || h === 0 ? undefined : this.surface; return { code: code, x: g.x, y: g.y, width: w, height: h, surface: surface, offsetX: offsetX, offsetY: offsetY, advanceWidth: advanceWidth, isSurfaceValid: true, _atlas: null }; }; /** * 利用している `Surface` を破棄した上で、このフォントを破棄する。 */ BitmapFont.prototype.destroy = function () { if (this.surface && !this.surface.destroyed()) { this.surface.destroy(); } this.map = undefined; }; /** * 破棄されたオブジェクトかどうかを判定する。 */ BitmapFont.prototype.destroyed = function () { // mapをfalsy値で作成された場合最初から破棄扱いになるが、仕様とする return !this.map; }; return BitmapFont; }(Font_1.Font)); exports.BitmapFont = BitmapFont; },{"./Font":25,"./SurfaceUtil":58}],11:[function(require,module,exports){ arguments[4][3][0].apply(exports,arguments) },{"dup":3}],12:[function(require,module,exports){ "use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Camera2D = void 0; var Object2D_1 = require("./Object2D"); /** * 2D世界におけるカメラ。 */ var Camera2D = /** @class */ (function (_super) { __extends(Camera2D, _super); /** * 指定されたパラメータで `Camera2D` のインスタンスを生成する。 * @param param 初期化に用いるパラメータのオブジェクト */ function Camera2D(param) { var _this = _super.call(this, param) || this; _this.local = !!param.local; _this.name = param.name; _this._modifiedCount = 0; return _this; } /** * 与えられたシリアリゼーションでカメラを復元する。 * * @param ser `Camera2D#serialize()` の戻り値 */ Camera2D.deserialize = function (ser) { var s = ser; var ret = new Camera2D(s.param); return ret; }; /** * カメラ状態の変更をエンジンに通知する。 * * このメソッドの呼び出し後、このカメラのプロパティに対する変更が各 `Renderer` の描画に反映される。 * ただし逆は真ではない。すなわち、再描画は他の要因によって行われることもある。 * ゲーム開発者は、このメソッドを呼び出していないことをもって再描画が行われていないことを仮定してはならない。 * * 本メソッドは、このオブジェクトの `Object2D` 由来のプロパティ (`x`, `y`, `angle` など) を変更した場合にも呼びだす必要がある。 */ Camera2D.prototype.modified = function () { this._modifiedCount = (this._modifiedCount + 1) % 32768; if (this._matrix) this._matrix._modified = true; }; /** * このカメラをシリアライズする。 * * このメソッドの戻り値を `Camera2D#deserialize()` に渡すことで同じ値を持つカメラを復元することができる。 */ Camera2D.prototype.serialize = function () { var ser = { param: { local: this.local, name: this.name, x: this.x, y: this.y, width: this.width, height: this.height, opacity: this.opacity, scaleX: this.scaleX, scaleY: this.scaleY, angle: this.angle, anchorX: this.anchorX, anchorY: this.anchorY, compositeOperation: this.compositeOperation } }; return ser; }; /** * @private */ Camera2D.prototype._applyTransformToRenderer = function (renderer) { if (this.angle || this.scaleX !== 1 || this.scaleY !== 1 || this.anchorX !== 0 || this.anchorY !== 0) { // Note: this.scaleX/scaleYが0の場合描画した結果何も表示されない事になるが、特殊扱いはしない renderer.transform(this.getMatrix()._matrix); } else { renderer.translate(-this.x, -this.y); } if (this.opacity !== 1) renderer.opacity(this.opacity); }; /** * @private */ Camera2D.prototype._updateMatrix = function () { if (!this._matrix) return; // カメラの angle, x, y はエンティティと逆方向に作用することに注意。 if (this.angle || this.scaleX !