UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

95 lines (76 loc) 2 kB
import { Color } from "../../../../../core/color/Color.js"; import { computeStringHash } from "../../../../../core/primitives/strings/computeStringHash.js"; import { assert } from "../../../../../core/assert.js"; export class Decal { /** * Asset URL * @type {string} */ uri = ""; /** * Controls draw order * @type {number} */ priority = 0; /** * Color of the decal will be pre-multiplied by this * @type {Color} */ color = new Color(1, 1, 1, 1); /** * Internal transient reference to loaded asset * @type {Sampler2D|null} * @private */ __cached_sampler = null; /** * * @type {String|null} * @private */ __cached_uri = null; static fromJSON(j) { const r = new Decal(); r.fromJSON(j); return r; } toJSON() { return { uri: this.uri, priority: this.priority, color: this.color.toCssRGBAString() }; } fromJSON({ uri, priority = 0, color = '#FFFFFF' }) { assert.isString(uri, 'uri'); assert.isNumber(priority, 'priority'); assert.notNaN(priority, 'priority'); this.uri = uri; this.priority = priority; if (uri !== this.__cached_uri) { // reset sampler this.__cached_sampler = null; this.__cached_uri = null; } this.color.parse(color); } hash() { return computeStringHash(this.uri) ^ this.color.hash() } /** * * @param {Decal} other * @returns {boolean} */ equals(other) { return this.uri === other.uri && this.color.equals(other.color) && this.priority === other.priority ; } } Decal.typeName = 'Decal';