@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
65 lines (56 loc) • 1.18 kB
JavaScript
/**
* @template T
*
*/
export class Asset {
/**
* @template T
* @param {function():T} [factory]
* @param {number} [byteSize] byte size of the asset in RAM
* @constructor
*/
constructor(factory, byteSize = 0) {
/**
*
* @type {function(): T}
*/
this.factory = factory;
/**
*
* @type {number}
*/
this.byteSize = byteSize;
/**
*
* @type {Array<AssetDescription>}
*/
this.dependencies = [];
/**
*
* @type {AssetDescription}
*/
this.description = null;
}
/**
*
* @param {Asset} other
* @returns {boolean}
*/
equals(other) {
return this === other
|| this.description === other.description
|| this.description.equals(other.description)
;
}
hash() {
return this.description.hash();
}
/**
*
* @returns {T}
*/
create() {
return this.factory();
}
}
Asset.prototype.byteSize = 0;