UNPKG

@awayjs/core

Version:
139 lines (138 loc) 4.87 kB
import { __extends } from "tslib"; import { AbstractMethodError } from '../errors/AbstractMethodError'; import { AssetEvent } from '../events/AssetEvent'; import { EventDispatcher } from '../events/EventDispatcher'; import { UUID } from './UUID'; var AssetBase = /** @class */ (function (_super) { __extends(AssetBase, _super); function AssetBase() { var _this = _super.call(this) || this; _this._abstractionPool = {}; _this.id = UUID.Next(); return _this; } Object.defineProperty(AssetBase.prototype, "finalizer", { get: function () { var _this = this; return this.__finalizer || (this.__finalizer = new FinalizationRegistry(function (poolId) { var abstraction = _this._abstractionPool[poolId]; if (abstraction) { // check abstraction hasn't already been cleared console.debug('[' + abstraction.constructor.name + '] abstraction was deleted by GC:', poolId); abstraction.onClear(null); } })); }, enumerable: false, configurable: true }); Object.defineProperty(AssetBase.prototype, "adaptee", { get: function () { return this; }, enumerable: false, configurable: true }); Object.defineProperty(AssetBase.prototype, "adapter", { /** * adapter is used to provide MovieClip to scripts taken from different platforms * setter typically managed by factory. getter defaults to AwayJS class */ get: function () { return this._adapter || this; }, set: function (value) { this._adapter = value; }, enumerable: false, configurable: true }); Object.defineProperty(AssetBase.prototype, "assetType", { /** * */ get: function () { throw new AbstractMethodError(); }, enumerable: false, configurable: true }); Object.defineProperty(AssetBase.prototype, "name", { get: function () { return this._name; }, set: function (val) { var prev = this._name; this._name = val; if (this._name == null) this._name = 'null'; this.dispatchEvent(new AssetEvent(AssetEvent.RENAME, this, prev)); }, enumerable: false, configurable: true }); /** * */ AssetBase.prototype.invalidate = function () { for (var key in this._abstractionPool) this._abstractionPool[key].onInvalidate(null); }; /** * @inheritDoc */ AssetBase.prototype.dispose = function () { throw new AbstractMethodError(); }; AssetBase.prototype.clone = function () { throw new AbstractMethodError(); }; AssetBase.prototype.clear = function () { for (var key in this._abstractionPool) this._abstractionPool[key].onClear(null); }; Object.defineProperty(AssetBase.prototype, "assetNamespace", { get: function () { return this._namespace; }, set: function (value) { this._namespace = value ? value : AssetBase.DEFAULT_NAMESPACE; }, enumerable: false, configurable: true }); AssetBase.prototype.assetPathEquals = function (name, ns) { return (this._name == name && (!ns || this._namespace == ns)); }; AssetBase.prototype.isAsset = function (assetClass) { return this.assetType == assetClass.assetType; }; AssetBase.prototype.resetAssetPath = function (name, ns) { if (ns === void 0) { ns = null; } this._name = name ? name : 'null'; this._namespace = ns ? ns : AssetBase.DEFAULT_NAMESPACE; }; AssetBase.prototype.getAbstraction = function (pool) { return this._abstractionPool[pool.id] || (this._abstractionPool[pool.id] = this.getNewAbstraction(pool)); }; AssetBase.prototype.checkAbstraction = function (pool) { return this._abstractionPool[pool.id]; }; AssetBase.prototype.clearAbstraction = function (pool) { // in cases where pool has been GC'd, we still need to remove abstraction from _abstractionPool if (typeof pool == 'number') { delete this._abstractionPool[pool]; return; } pool.storeAbstraction(this._abstractionPool[pool.id]); delete this._abstractionPool[pool.id]; }; AssetBase.prototype.getNewAbstraction = function (pool) { var abstraction = pool.requestAbstraction(this); abstraction.init(this, pool); return abstraction; }; AssetBase.DEFAULT_NAMESPACE = 'default'; return AssetBase; }(EventDispatcher)); export { AssetBase };