UNPKG

@petkoneo/phaser3-rex-plugins

Version:
1,737 lines (1,433 loc) 473 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.rextextplayerplugin = factory()); })(this, (function () { 'use strict'; var EventEmitterMethods$1 = { setEventEmitter(eventEmitter, EventEmitterClass) { if (EventEmitterClass === undefined) { EventEmitterClass = Phaser.Events.EventEmitter; // Use built-in EventEmitter class by default } this._privateEE = (eventEmitter === true) || (eventEmitter === undefined); this._eventEmitter = (this._privateEE) ? (new EventEmitterClass()) : eventEmitter; return this; }, destroyEventEmitter() { if (this._eventEmitter && this._privateEE) { this._eventEmitter.shutdown(); } return this; }, getEventEmitter() { return this._eventEmitter; }, on() { if (this._eventEmitter) { this._eventEmitter.on.apply(this._eventEmitter, arguments); } return this; }, once() { if (this._eventEmitter) { this._eventEmitter.once.apply(this._eventEmitter, arguments); } return this; }, off() { if (this._eventEmitter) { this._eventEmitter.off.apply(this._eventEmitter, arguments); } return this; }, emit(event) { if (this._eventEmitter && event) { this._eventEmitter.emit.apply(this._eventEmitter, arguments); } return this; }, addListener() { if (this._eventEmitter) { this._eventEmitter.addListener.apply(this._eventEmitter, arguments); } return this; }, removeListener() { if (this._eventEmitter) { this._eventEmitter.removeListener.apply(this._eventEmitter, arguments); } return this; }, removeAllListeners() { if (this._eventEmitter) { this._eventEmitter.removeAllListeners.apply(this._eventEmitter, arguments); } return this; }, listenerCount() { if (this._eventEmitter) { return this._eventEmitter.listenerCount.apply(this._eventEmitter, arguments); } return 0; }, listeners() { if (this._eventEmitter) { return this._eventEmitter.listeners.apply(this._eventEmitter, arguments); } return []; }, eventNames() { if (this._eventEmitter) { return this._eventEmitter.eventNames.apply(this._eventEmitter, arguments); } return []; }, }; var PropertyMethods$1 = { hasProperty(property) { var gameObject = this.gameObject; if (gameObject.hasOwnProperty(property)) { return true; } else { var value = gameObject[property]; return (value !== undefined); } }, getProperty(property) { return this.gameObject[property]; }, setProperty(property, value) { this.gameObject[property] = value; return this; }, easeProperty(config) { var property = config.property; var value = config.value; var duration = config.duration; var delay = config.delay; var ease = config.ease; var repeat = config.repeat; var isYoyo = config.yoyo; var isFrom = config.from; var onComplete = config.complete; var target = config.target; if (duration === undefined) { duration = 1000; } if (delay === undefined) { delay = 0; } if (ease === undefined) { ease = 'Linear'; } if (repeat === undefined) { repeat = 0; } if (isYoyo === undefined) { isYoyo = false; } if (target === undefined) { target = this.gameObject; } if (isFrom) { var startValue = value; value = target[property]; target[property] = startValue; } var config = { targets: target, duration: duration, delay: delay, ease: ease, repeat: repeat, yoyo: isYoyo, onComplete: onComplete, }; config[property] = value; this.addTweenTask(property, config); return this; }, addTweenTask(name, config) { var tweenTasks = this.tweens; var tweenTask = tweenTasks[name]; if (tweenTask) { tweenTask.remove(); } var onComplete = config.onComplete; config.onComplete = function () { tweenTasks[name].remove(); tweenTasks[name] = null; if (onComplete) { onComplete(config.targets, name); } }; tweenTask = this.scene.tweens.add(config); tweenTask.timeScale = this.timeScale; tweenTasks[name] = tweenTask; return this; }, getTweenTask(property) { return this.tweens[property]; }, freeTweens() { var tweenTasks = this.tweens, tweenTask; for (var propName in tweenTasks) { tweenTask = tweenTasks[propName]; if (tweenTask) { tweenTask.remove(); } tweenTasks[propName] = null; } return this; } }; var CallMethods$1 = { hasMethod(methodName) { return typeof (this.gameObject[methodName]) === 'function'; }, call(methodName, ...parameters) { if (!this.hasMethod(methodName)) { console.warn(`[GameObjectManager] Game object '${this.name}' does not have method '${methodName}'`); return this; } var gameObject = this.gameObject; gameObject[methodName].apply(gameObject, parameters); return this; } }; var DataMethods$2 = { hasData(dataKey) { var gameObject = this.gameObject; return (gameObject.data) ? gameObject.data.has(dataKey) : false; }, getData(dataKey) { return this.gameObject.getData(dataKey); }, setData(dataKey, value) { this.gameObject.setData(dataKey, value); return this; }, }; class BobBase { constructor(GOManager, gameObject, name) { this.GOManager = GOManager; this.tweens = {}; this.effects = {}; this.setGO(gameObject, name); } get scene() { return this.GOManager.scene; } get timeScale() { return this.GOManager.timeScale; } destroy() { this.freeGO(); this.GOManager = undefined; } freeGO() { this.freeTweens(); this.gameObject.bob = undefined; this.gameObject.destroy(); this.gameObject = undefined; return this; } setGO(gameObject, name) { gameObject.goName = name; gameObject.goType = this.GOManager.name; gameObject.bob = this; this.gameObject = gameObject; this.name = name; this.freeTweens(); return this; } setTimeScale(timeScale) { var tweenTasks = this.tweens; for (var key in tweenTasks) { var tweenTask = tweenTasks[key]; if (tweenTask) { tweenTask.timeScale = timeScale; } } return this; } } Object.assign( BobBase.prototype, PropertyMethods$1, CallMethods$1, DataMethods$2, ); var IsEmpty = function (source) { for (var k in source) { return false; } return true; }; var IsSingleBob = function (name) { return name && (name.charAt(0) !== '!'); }; var GetMethods = { has(name) { return this.bobs.hasOwnProperty(name); }, exists(name) { return this.bobs.hasOwnProperty(name); }, get(name, out) { if (IsSingleBob(name)) { return this.bobs[name]; } else { if (out === undefined) { out = []; } if (name) { name = name.substring(1); } for (var key in this.bobs) { if (name && (key === name)) { continue; } out.push(this.bobs[key]); } return out; } }, getFitst(excluded) { if (excluded && (excluded.charAt(0) === '!')) { excluded = excluded.substring(1); } for (var name in this.bobs) { if (excluded && (excluded === name)) { continue; } return this.bobs[name]; } return null; }, getGO(name, out) { var bob = this.get(name); if (!bob) { return null; } else if (!Array.isArray(bob)) { return bob.gameObject; } else { if (out === undefined) { out = []; } var bobs = bob; bobs.forEach(function (bob) { out.push(bob.gameObject); }); return out; } }, forEachGO(callback, scope) { for (var name in this.bobs) { var gameObject = this.bobs[name].gameObject; var stopLoop; if (scope) { stopLoop = callback.call(scope, gameObject, name, this); } else { stopLoop = callback(gameObject, name, this); } if (stopLoop) { break; } } return this; }, getAllGO(out) { if (out === undefined) { out = []; } for (var name in this.bobs) { var gameObject = this.bobs[name].gameObject; out.push(gameObject); } return out; } }; var GetR = function (colorInt) { return (colorInt >> 16) & 0xff; }; var GetG = function (colorInt) { return (colorInt >> 8) & 0xff; }; var GetB = function (colorInt) { return (colorInt) & 0xff; }; const MaskR = (~(0xff << 16) & 0xffffff); const MaskG = (~(0xff << 8) & 0xffffff); const MaskB = (~(0xff) & 0xffffff); var SetR = function (colorInt, r) { return ((r & 0xff) << 16) | (colorInt & MaskR); }; var SetG = function (colorInt, g) { return ((g & 0xff) << 8) | (colorInt & MaskG); }; var SetB = function (colorInt, b) { return (b & 0xff) | (colorInt & MaskB); }; var SetRGB = function (colorInt, r, g, b) { return ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff)); }; var AddTintRGBProperties = function (gameObject, tintRGB) { // Don't attach properties again if (gameObject.hasOwnProperty('tintR')) { return gameObject; } if (tintRGB === undefined) { tintRGB = 0xffffff; } var tintR = GetR(tintRGB); var tintG = GetG(tintRGB); var tintB = GetB(tintRGB); // Override tint property Object.defineProperty(gameObject, 'tint', { get: function () { return tintRGB; }, set: function (value) { value = Math.floor(value) & 0xffffff; if (gameObject.setTint) { gameObject.setTint(value); } if (tintRGB !== value) { tintRGB = value; tintR = GetR(tintRGB); tintG = GetG(tintRGB); tintB = GetB(tintRGB); // gameObject.emit('_tintchange', value, tintR, tintG, tintB); } } }); Object.defineProperty(gameObject, 'tintR', { get: function () { return tintR; }, set: function (value) { value = Math.floor(value) & 0xff; if (tintR !== value) { tintR = value; gameObject.tint = SetR(tintRGB, value); } }, }); Object.defineProperty(gameObject, 'tintG', { get: function () { return tintG; }, set: function (value) { value = Math.floor(value) & 0xff; if (tintG !== value) { tintG = value; gameObject.tint = SetG(tintRGB, value); } }, }); Object.defineProperty(gameObject, 'tintB', { get: function () { return tintB; }, set: function (value) { value = Math.floor(value) & 0xff; if (tintB !== value) { tintB = value; gameObject.tint = SetB(tintRGB, value); } }, }); Object.defineProperty(gameObject, 'tintGray', { get: function () { return Math.floor((tintR + tintG + tintB) / 3); }, set: function (value) { value = Math.floor(value) & 0xff; if ((tintR !== value) || (tintG !== value) || (tintB !== value)) { tintR = value; tintG = value; tintB = value; gameObject.tint = SetRGB(tintRGB, value, value, value); } }, }); gameObject.tint = tintRGB; return gameObject; }; const EventEmitter$1 = Phaser.Events.EventEmitter; var MonitorViewport = function (viewport) { // Don't monitor properties again if (viewport.events) { return viewport; } var events = new EventEmitter$1(); var x = viewport.x; Object.defineProperty(viewport, 'x', { get: function () { return x; }, set: function (value) { if (x !== value) { x = value; events.emit('update', viewport); } }, }); var y = viewport.y; Object.defineProperty(viewport, 'y', { get: function () { return y; }, set: function (value) { if (y !== value) { y = value; events.emit('update', viewport); } }, }); var width = viewport.width; Object.defineProperty(viewport, 'width', { get: function () { return width; }, set: function (value) { if (width !== value) { width = value; events.emit('update', viewport); } }, }); var height = viewport.height; Object.defineProperty(viewport, 'height', { get: function () { return height; }, set: function (value) { if (height !== value) { height = value; events.emit('update', viewport); } }, }); viewport.events = events; return viewport; }; var VPXYToXY = function (vpx, vpy, vpxOffset, vpyOffset, viewport, out) { if (out === undefined) { out = {}; } else if (out === true) { out = GlobXY; } if (typeof (vpxOffset) !== 'number') { vpxOffset = 0; vpyOffset = 0; } out.x = viewport.x + (viewport.width * vpx) + vpxOffset; out.y = viewport.y + (viewport.height * vpy) + vpyOffset; return out; }; var GlobXY = {}; var AddViewportCoordinateProperties = function (gameObject, viewport, vpx, vpy, vpxOffset, vpyOffset, transformCallback) { // Don't attach properties again if (gameObject.hasOwnProperty('vp')) { return gameObject; } if (typeof (vpx) === 'function') { transformCallback = vpx; vpx = undefined; } if (typeof (vpxOffset) === 'function') { transformCallback = vpxOffset; vpxOffset = undefined; } if (vpx === undefined) { vpx = 0.5; } if (vpy === undefined) { vpy = 0.5; } if (vpxOffset === undefined) { vpxOffset = 0; } if (vpyOffset === undefined) { vpyOffset = 0; } if (transformCallback === undefined) { transformCallback = VPXYToXY; } MonitorViewport(viewport); var events = viewport.events; gameObject.vp = viewport; // Set position of game object when view-port changed. var Transform = function () { transformCallback(vpx, vpy, vpxOffset, vpyOffset, viewport, gameObject); }; events.on('update', Transform); gameObject.once('destroy', function () { events.off('update', Transform); gameObject.vp = undefined; }); Object.defineProperty(gameObject, 'vpx', { get: function () { return vpx; }, set: function (value) { if (vpx !== value) { vpx = value; Transform(); } }, }); Object.defineProperty(gameObject, 'vpy', { get: function () { return vpy; }, set: function (value) { if (vpy !== value) { vpy = value; Transform(); } }, }); Object.defineProperty(gameObject, 'vpxOffset', { get: function () { return vpxOffset; }, set: function (value) { if (vpxOffset !== value) { vpxOffset = value; Transform(); } }, }); Object.defineProperty(gameObject, 'vpyOffset', { get: function () { return vpyOffset; }, set: function (value) { if (vpyOffset !== value) { vpyOffset = value; Transform(); } }, }); Transform(); }; var HasProperty = function (obj, prop) { if (!obj) { return false; } if (obj.hasOwnProperty(prop)) { return true; } while (obj) { if (Object.getOwnPropertyDescriptor(obj, prop)) { return true; } obj = obj.__proto__; } return false; }; var GetFXFactory = function (gameObject) { if (gameObject.preFX) { return gameObject.preFX; } if (gameObject.postFX) { return gameObject.postFX; } return null; }; var AddClearEffectCallback = function (gameObject, effectSwitchName) { if (!gameObject._effectSwitchNames) { gameObject._effectSwitchNames = []; gameObject.clearAllEffects = function () { var effectSwitchNames = gameObject._effectSwitchNames; for (var i = 0, cnt = effectSwitchNames.length; i < cnt; i++) { gameObject[effectSwitchNames[i]] = null; } return gameObject; }; gameObject.on('destroy', gameObject.clearAllEffects, gameObject); } gameObject._effectSwitchNames.push(effectSwitchName); }; var AddBarrelProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'barrel')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var barrel; Object.defineProperty(gameObject, 'barrel', { get: function () { return barrel; }, set: function (value) { if (barrel === value) { return; } barrel = value; if ((barrel === null) || (barrel === false)) { if (gameObject._barrelEffect) { fxFactory.remove(gameObject._barrelEffect); gameObject._barrelEffect = undefined; } } else { if (!gameObject._barrelEffect) { gameObject._barrelEffect = fxFactory.addBarrel(); } gameObject._barrelEffect.amount = barrel; } }, }); gameObject.barrel = null; AddClearEffectCallback(gameObject, 'barrel'); return gameObject; }; var AddColorMatrixEffectPropertiesBase = function (gameObject, effectName, inputMode) { // Don't attach properties again if (HasProperty(gameObject, effectName)) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var EffectInstancePropertyName = `_${effectName}Effect`; var currentValue; Object.defineProperty(gameObject, effectName, { get: function () { return currentValue; }, set: function (value) { if (currentValue === value) { return; } currentValue = value; if ((currentValue === null) || (currentValue === false)) { if (gameObject[EffectInstancePropertyName]) { fxFactory.remove(gameObject[EffectInstancePropertyName]); gameObject[EffectInstancePropertyName] = undefined; } } else { if (!gameObject[EffectInstancePropertyName]) { gameObject[EffectInstancePropertyName] = fxFactory.addColorMatrix(); } var effectInstance = gameObject[EffectInstancePropertyName]; effectInstance[effectName]((inputMode === 1) ? value : undefined); } }, }); gameObject[effectName] = null; AddClearEffectCallback(gameObject, effectName); return gameObject; }; var AddBlackWhiteProperties = function (gameObject) { AddColorMatrixEffectPropertiesBase(gameObject, 'blackWhite'); return gameObject; }; var AddBloomProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'bloomColor')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var bloomColor, bloomOffsetX = 1, bloomOffsetY = 1, bloomBlurStrength = 1, bloomStrength = 1, bloomSteps = 4; Object.defineProperty(gameObject, 'bloomColor', { get: function () { return bloomColor; }, set: function (value) { if (bloomColor === value) { return; } bloomColor = value; if ((bloomColor === null) || (bloomColor === false)) { if (gameObject._bloom) { fxFactory.remove(gameObject._bloom); gameObject._bloom = undefined; fxFactory.setPadding(0); } } else { if (!gameObject._bloom) { gameObject._bloom = fxFactory.addBloom(bloomColor, bloomOffsetX, bloomOffsetY, bloomBlurStrength, bloomStrength, bloomSteps); fxFactory.setPadding(Math.max(bloomOffsetX, bloomOffsetY) + 1); } gameObject._bloom.color = bloomColor; } }, }); Object.defineProperty(gameObject, 'bloomOffsetX', { get: function () { return bloomOffsetX; }, set: function (value) { if (bloomOffsetX === value) { return; } bloomOffsetX = value; if (gameObject._bloom) { var offset = Math.max(bloomOffsetX, bloomOffsetY); fxFactory.setPadding(offset + 1); gameObject._bloom.offsetX = bloomOffsetX; } }, }); Object.defineProperty(gameObject, 'bloomOffsetY', { get: function () { return bloomOffsetY; }, set: function (value) { if (bloomOffsetY === value) { return; } bloomOffsetY = value; if (gameObject._bloom) { var offset = Math.max(bloomOffsetX, bloomOffsetY); fxFactory.setPadding(offset + 1); gameObject._bloom.offsetY = bloomOffsetY; } }, }); Object.defineProperty(gameObject, 'bloomBlurStrength', { get: function () { return bloomBlurStrength; }, set: function (value) { if (bloomBlurStrength === value) { return; } bloomBlurStrength = value; if (gameObject._bloom) { gameObject._bloom.blurStrength = bloomBlurStrength; } }, }); Object.defineProperty(gameObject, 'bloomStrength', { get: function () { return bloomStrength; }, set: function (value) { if (bloomStrength === value) { return; } bloomStrength = value; if (gameObject._bloom) { gameObject._bloom.strength = bloomStrength; } }, }); Object.defineProperty(gameObject, 'bloomSteps', { get: function () { return bloomSteps; }, set: function (value) { if (bloomSteps === value) { return; } bloomSteps = value; if (gameObject._bloom) { gameObject._bloom.steps = bloomSteps; } }, }); gameObject.bloomColor = null; AddClearEffectCallback(gameObject, 'bloomColor'); return gameObject; }; var AddBlurProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'blurColor')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var blurColor, blurQuality = 0, blurX = 1, blurY = 1, blurStrength = 1, blurSteps = 4; Object.defineProperty(gameObject, 'blurColor', { get: function () { return blurColor; }, set: function (value) { if (blurColor === value) { return; } blurColor = value; if ((blurColor === null) || (blurColor === false)) { if (gameObject._blur) { fxFactory.remove(gameObject._blur); gameObject._blur = undefined; fxFactory.setPadding(0); } } else { if (!gameObject._blur) { gameObject._blur = fxFactory.addBlur(blurQuality, blurX, blurY, blurStrength, blurColor, blurSteps); fxFactory.setPadding(Math.max(blurX, blurY) + 1); } gameObject._blur.color = blurColor; } }, }); Object.defineProperty(gameObject, 'blurQuality', { get: function () { return blurQuality; }, set: function (value) { if (blurQuality === value) { return; } blurQuality = value; if (gameObject._blur) { gameObject._blur.quality = blurQuality; } }, }); Object.defineProperty(gameObject, 'blurX', { get: function () { return blurX; }, set: function (value) { if (blurX === value) { return; } blurX = value; if (gameObject._blur) { var offset = Math.max(blurX, blurY); fxFactory.setPadding(offset + 1); gameObject._blur.x = blurX; } }, }); Object.defineProperty(gameObject, 'blurY', { get: function () { return blurY; }, set: function (value) { if (blurY === value) { return; } blurY = value; if (gameObject._blur) { var offset = Math.max(blurX, blurY); fxFactory.setPadding(offset + 1); gameObject._blur.y = blurY; } }, }); Object.defineProperty(gameObject, 'blurStrength', { get: function () { return blurStrength; }, set: function (value) { if (blurStrength === value) { return; } blurStrength = value; if (gameObject._blur) { gameObject._blur.strength = blurStrength; } }, }); Object.defineProperty(gameObject, 'blurSteps', { get: function () { return blurSteps; }, set: function (value) { if (blurSteps === value) { return; } blurSteps = value; if (gameObject._blur) { gameObject._blur.steps = blurSteps; } }, }); gameObject.blurColor = null; AddClearEffectCallback(gameObject, 'blurColor'); return gameObject; }; var AddBokehProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'bokehRadius')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var bokehRadius, bokehAmount = 1, bokehContrast = 0.2; Object.defineProperty(gameObject, 'bokehRadius', { get: function () { return bokehRadius; }, set: function (value) { if (bokehRadius === value) { return; } bokehRadius = value; if ((bokehRadius === null) || (bokehRadius === false)) { if (gameObject._bokeh) { fxFactory.remove(gameObject._bokeh); gameObject._bokeh = undefined; } } else { if (!gameObject._bokeh) { gameObject._bokeh = fxFactory.addBokeh(bokehRadius, bokehAmount, bokehContrast); } gameObject._bokeh.radius = bokehRadius; } }, }); Object.defineProperty(gameObject, 'bokehAmount', { get: function () { return bokehAmount; }, set: function (value) { if (bokehAmount === value) { return; } bokehAmount = value; if (gameObject._bokeh) { gameObject._bokeh.amount = bokehAmount; } }, }); Object.defineProperty(gameObject, 'bokehContrast', { get: function () { return bokehContrast; }, set: function (value) { if (bokehContrast === value) { return; } bokehContrast = value; if (gameObject._bokeh) { gameObject._bokeh.contrast = bokehContrast; } }, }); gameObject.bokehRadius = null; AddClearEffectCallback(gameObject, 'bokehRadius'); return gameObject; }; var AddBrightnessProperties = function (gameObject) { AddColorMatrixEffectPropertiesBase(gameObject, 'brightness', 1); return gameObject; }; var AddBrownProperties = function (gameObject) { AddColorMatrixEffectPropertiesBase(gameObject, 'brown'); return gameObject; }; var AddCircleProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'circleColor')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var circleColor, circleThickness = 8, circleBackgroundColor = 0x000000, circleBackgroundAlpha = 0.4, circleScale = 1, circleFeather = 0.005; Object.defineProperty(gameObject, 'circleColor', { get: function () { return circleColor; }, set: function (value) { if (circleColor === value) { return; } circleColor = value; if ((circleColor === null) || (circleColor === false)) { if (gameObject._circle) { fxFactory.remove(gameObject._circle); gameObject._circle = undefined; } } else { if (!gameObject._circle) { gameObject._circle = fxFactory.addCircle(circleThickness, circleColor, circleBackgroundColor, circleScale, circleFeather); gameObject.circleBackgroundAlpha = circleBackgroundAlpha; } gameObject._circle.color = circleColor; } }, }); Object.defineProperty(gameObject, 'circleThickness', { get: function () { return circleThickness; }, set: function (value) { if (circleThickness === value) { return; } circleThickness = value; if (gameObject._circle) { gameObject._circle.thickness = circleThickness; } }, }); Object.defineProperty(gameObject, 'circleBackgroundColor', { get: function () { return circleBackgroundColor; }, set: function (value) { if (circleBackgroundColor === value) { return; } circleBackgroundColor = value; if (gameObject._circle) { gameObject._circle.backgroundColor = circleBackgroundColor; } }, }); Object.defineProperty(gameObject, 'circleBackgroundAlpha', { get: function () { return circleBackgroundAlpha; }, set: function (value) { if (circleBackgroundAlpha === value) { return; } circleBackgroundAlpha = value; if (gameObject._circle) { gameObject._circle.glcolor2[3] = circleBackgroundAlpha; } }, }); Object.defineProperty(gameObject, 'circleScale', { get: function () { return circleScale; }, set: function (value) { if (circleScale === value) { return; } circleScale = value; if (gameObject._circle) { gameObject._circle.scale = circleScale; } }, }); Object.defineProperty(gameObject, 'circleFeather', { get: function () { return circleFeather; }, set: function (value) { if (circleFeather === value) { return; } circleFeather = value; if (gameObject._circle) { gameObject._circle.feather = circleFeather; } }, }); gameObject.circleColor = null; AddClearEffectCallback(gameObject, 'circleColor'); return gameObject; }; var AddContrastProperties = function (gameObject) { AddColorMatrixEffectPropertiesBase(gameObject, 'contrast', 1); return gameObject; }; var AddDesaturateProperties = function (gameObject) { AddColorMatrixEffectPropertiesBase(gameObject, 'desaturate', 1); return gameObject; }; var AddDesaturateLuminanceProperties = function (gameObject) { AddColorMatrixEffectPropertiesBase(gameObject, 'desaturateLuminance'); return gameObject; }; var AddDisplacementProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'displacementKey')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var displacementKey, displacementX = 0.005, displacementY = 0.005; Object.defineProperty(gameObject, 'displacementKey', { get: function () { return displacementKey; }, set: function (value) { if (displacementKey === value) { return; } displacementKey = value; if ((displacementKey === null) || (displacementKey === false)) { if (gameObject._displacement) { fxFactory.remove(gameObject._displacement); gameObject._displacement = undefined; } } else { if (!gameObject._displacement) { gameObject._displacement = fxFactory.addDisplacement(displacementKey, displacementX, displacementY); } gameObject._displacement.setTexture(displacementKey); } }, }); Object.defineProperty(gameObject, 'displacementX', { get: function () { return displacementX; }, set: function (value) { if (displacementX === value) { return; } displacementX = value; if (gameObject._displacement) { gameObject._displacement.x = displacementX; } }, }); Object.defineProperty(gameObject, 'displacementY', { get: function () { return displacementY; }, set: function (value) { if (displacementY === value) { return; } displacementY = value; if (gameObject._displacement) { gameObject._displacement.y = displacementY; } }, }); gameObject.displacementKey = null; AddClearEffectCallback(gameObject, 'displacementKey'); return gameObject; }; var AddGlowProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'glowColor')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var glowColor, glowOuterStrength = 4, glowInnerStrength = 0; Object.defineProperty(gameObject, 'glowColor', { get: function () { return glowColor; }, set: function (value) { if (glowColor === value) { return; } glowColor = value; if ((glowColor === null) || (glowColor === false)) { if (gameObject._glow) { fxFactory.remove(gameObject._glow); gameObject._glow = undefined; fxFactory.setPadding(0); } } else { if (!gameObject._glow) { gameObject._glow = fxFactory.addGlow(glowColor, glowOuterStrength, glowInnerStrength); fxFactory.setPadding(glowOuterStrength + 1); } gameObject._glow.color = glowColor; } }, }); Object.defineProperty(gameObject, 'glowOuterStrength', { get: function () { return glowOuterStrength; }, set: function (value) { if (glowOuterStrength === value) { return; } glowOuterStrength = value; if (gameObject._glow) { fxFactory.setPadding(glowOuterStrength + 1); gameObject._glow.outerStrength = glowOuterStrength; } }, }); Object.defineProperty(gameObject, 'glowInnerStrength', { get: function () { return glowInnerStrength; }, set: function (value) { if (glowInnerStrength === value) { return; } glowInnerStrength = value; if (gameObject._glow) { gameObject._glow.innerStrength = glowInnerStrength; } }, }); gameObject.glowColor = null; AddClearEffectCallback(gameObject, 'glowColor'); return gameObject; }; var AddGradientProperties = function (gameObject) { // Don't attach properties again if (HasProperty(gameObject, 'gradientColor')) { return gameObject; } var fxFactory = GetFXFactory(gameObject); if (!fxFactory) { return gameObject; } var gradientColor1, gradientColor2, gradientAlpha = 0.5, gradientFromX = 0, gradientFromY = 0, gradientToX = 0, gradientToY = 1, gradientSize = 0; Object.defineProperty(gameObject, 'gradientColor', { get: function () { return [gradientColor1, gradientColor2]; }, set: function (value) { var color1, color2; if ((value === null) || (value === false)) { color1 = null; color2 = null; } else { color1 = value[0]; color2 = value[1]; } if ((gradientColor1 === color1) && (gradientColor2 === color2)) { return; } gradientColor1 = color1; gradientColor2 = color2; if ((gradientColor1 === null) || (gradientColor1 === false)) { if (gameObject._gradient) { fxFactory.remove(gameObject._gradient); gameObject._gradient = undefined; } } else { if (!gameObject._gradient) { gameObject._gradient = fxFactory.addGradient(gradientColor1, gradientColor2, gradientAlpha, gradientFromX, gradientFromY, gradientToX, gradientToY, gradientSize); } gameObject._gradient.color1 = gradientColor1; gameObject._gradient.color2 = gradientColor2; } }, }); Object.defineProperty(gameObject, 'gradientColor1', { get: function () { return gradientColor1; }, set: function (value) { if ((value === null) || (value === false)) { gameObject.gradientColor = value; return; } if (gradientColor1 === value) { return; } gradientColor1 = value; if (gameObject._gradient) { gameObject._gradient.color1 = gradientColor1; } }, }); Object.defineProperty(gameObject, 'gradientColor2', { get: function () { return gradientColor2; }, set: function (value) { if ((value === null) || (value === false)) { gameObject.gradientColor = value; return; } if (gradientColor2 === value) { return; } gradientColor2 = value; if (gameObject._gradient) { gameObject._gradient.color2 = gradientColor2; } }, }); Object.defineProperty(gameObject, 'gradientAlpha', { get: function () { return gradientAlpha; }, set: function (value) { if (gradientAlpha === value) { return; } gradientAlpha = value; if (gameObject._gradient) { gameObject._gradient.alpha = gradientAlpha; } }, }); Object.defineProperty(gameObject, 'gradientFromX', { get: function () { return gradientFromX; }, set: function (value) { if (gradientFromX === value) { return; } gradientFromX = value; if (gameObject._gradient) { gameObject._gradient.fromX = gradientFromX; } }, }); Object.defineProperty(gameObject, 'gradientFromY', { get: function () { return gradientFromY; }, set: function (value) { if (gradientFromY === value) { return; } gradientFromY = value; if (gameObject._gradient) { gameObject._gradient.fromY = gradientFromY; } }, }); Object.defineProperty(gameObject, 'gradientToX', { get: function () { return gradientToX; }, set: function (value) { if (gradientToX === value) { return; } gradientToX = value; if (gameObject._gradient) { gameObject._gradient.toX = gradientToX; } }, }); Object.definePropert