UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

108 lines (95 loc) 2.19 kB
/** * * @enum {number} */ export const AssetRequestFlags = { /** * Will always skip the wait queue */ SkipQueue: 1 }; export class AssetRequest { /** * * @param {function(asset:Asset)} successCallback * @param {function(error:*)} failureCallback * @param {function(loaded:number, total:number):void} progressCallback * @constructor */ constructor(successCallback, failureCallback, progressCallback) { /** * * @type {function(Asset)} */ this.successCallback = successCallback; /** * * @type {function(*)} */ this.failureCallback = failureCallback; /** * * @type {function(number, number): void} */ this.pogressCallback = progressCallback; /** * Higher priority requests should be handled first * @type {number} */ this.priority = 1; /** * * @type {AssetRequestScope} */ this.scope = null; /** * * @type {number} */ this.flags = 0; } get scoped_priority() { const _p = this.priority; const scope = this.scope; if (scope === null) { return _p; } return _p * scope.final_priority; } /** * * @param {number|AssetRequestFlags} flag * @returns {void} */ setFlag(flag) { this.flags |= flag; } /** * * @param {number|AssetRequestFlags} flag * @returns {void} */ clearFlag(flag) { this.flags &= ~flag; } /** * * @param {number|AssetRequestFlags} flag * @param {boolean} value */ writeFlag(flag, value) { if (value) { this.setFlag(flag); } else { this.clearFlag(flag); } } /** * * @param {number|AssetRequestFlags} flag * @returns {boolean} */ getFlag(flag) { return (this.flags & flag) === flag; } }