UNPKG

phaser4-rex-plugins

Version:
1,583 lines (1,284 loc) 69.7 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.rexcircularprogresscanvasplugin = factory()); })(this, (function () { 'use strict'; // copy from Phaser.GameObjects.Text var WebGLRenderer = function (renderer, src, drawingContext, parentMatrix) { if (src.dirty) { src.updateTexture(); src.dirty = false; } if ((src.width === 0) || (src.height === 0)) { return; } drawingContext.camera.addToRenderList(src); var customRenderNodes = src.customRenderNodes; var defaultRenderNodes = src.defaultRenderNodes; (customRenderNodes.Submitter || defaultRenderNodes.Submitter).run( drawingContext, src, parentMatrix, 0, customRenderNodes.Texturer || defaultRenderNodes.Texturer, customRenderNodes.Transformer || defaultRenderNodes.Transformer ); }; // copy from Phaser.GameObjects.Text var CanvasRenderer = function (renderer, src, camera, parentMatrix) { if (src.dirty) { src.updateTexture(); src.dirty = false; } if ((src.width === 0) || (src.height === 0)) { return; } camera.addToRenderList(src); renderer.batchSprite(src, src.frame, camera, parentMatrix); }; var Render = { renderWebGL: WebGLRenderer, renderCanvas: CanvasRenderer }; const Color = Phaser.Display.Color; var CanvasMethods = { clear() { this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); this.dirty = true; return this; }, fill(color) { this.context.fillStyle = color; this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); this.dirty = true; return this; }, drawFrame(key, frame, dx, dy, dWidth, dHeight, sxOffset, syOffset, sWidth, sHeight) { var textureFrame = this.scene.sys.textures.getFrame(key, frame); if (!textureFrame) { return this; } var frameWidth = textureFrame.cutWidth, frameHeight = textureFrame.cutHeight; if (dx === undefined) { dx = 0; } if (dy === undefined) { dy = 0; } if (dWidth === undefined) { dWidth = frameWidth; } if (dHeight === undefined) { dHeight = frameHeight; } if (sxOffset === undefined) { sxOffset = 0; } if (syOffset === undefined) { syOffset = 0; } if (sWidth === undefined) { sWidth = frameWidth; } if (sHeight === undefined) { sHeight = frameHeight; } var sx = textureFrame.cutX + sxOffset; var sy = textureFrame.cutY + syOffset; this.context.drawImage( textureFrame.source.image, // image sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight ); this.dirty = true; return this; }, getDataURL(type, encoderOptions) { return this.canvas.toDataURL(type, encoderOptions); }, getPixel(x, y, out) { if (out === undefined) { out = new Color(); } var rgb = this.context.getImageData(x, y, 1, 1); out.setTo(rgb.data[0], rgb.data[1], rgb.data[2], rgb.data[3]); return out; }, setPixel(x, y, r, g, b, a) { if (typeof (r) !== 'number') { var color = r; r = color.red; g = color.green; b = color.blue; a = color.alpha; } if (a === undefined) { a = ((r !== 0) || (g !== 0) || (b !== 0)) ? 255 : 0; } var imgData = this.context.createImageData(1, 1); imgData.data[0] = r; imgData.data[1] = g; imgData.data[2] = b; imgData.data[3] = a; this.context.putImageData(imgData, x, y); this.dirty = true; return this; } }; var CopyCanvasToTexture = function (scene, srcCanvas, key, x, y, width, height) { var textures = scene.sys.textures; var renderer = scene.renderer; if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = srcCanvas.width; } if (height === undefined) { height = srcCanvas.height; } var texture; if (textures.exists(key)) { texture = textures.get(key); } else { texture = textures.createCanvas(key, width, height); } var destCanvas = texture.getSourceImage(); if (destCanvas.width !== width) { destCanvas.width = width; } if (destCanvas.height !== height) { destCanvas.height = height; } var destCtx = destCanvas.getContext('2d', { willReadFrequently: true }); destCtx.clearRect(0, 0, width, height); destCtx.drawImage(srcCanvas, x, y, width, height); if (renderer.gl && texture) { renderer.canvasToTexture(destCanvas, texture.source[0].glTexture, true, 0); } }; var TextureMethods = { updateTexture(callback, scope) { var canvas = this.canvas; var context = this.context; if (callback) { var scale = this.resolution; if (scale !== 1) { this.context.save(); this.context.scale(scale, scale); } if (scope) { callback.call(scope, canvas, context); } else { callback(canvas, context); } if (scale !== 1) { this.context.restore(); } } var newWidth = canvas.width, newHeight = canvas.height; if ((newWidth !== this.frame.width) || (newHeight !== this.frame.height)) { this.frame.setSize(newWidth, newHeight); this.frame.source.updateSize(newWidth, newHeight); this.frame.updateUVs(); } if (this.renderer && this.renderer.gl) { this.frame.source.glTexture = this.renderer.canvasToTexture(canvas, this.frame.source.glTexture, true); if (typeof WEBGL_DEBUG) { this.frame.glTexture.spectorMetadata = { textureKey: 'Canvas Game Object' }; } } this.dirty = false; var input = this.input; if (input && !input.customHitArea) { input.hitArea.width = this.width; input.hitArea.height = this.height; } return this; }, generateTexture(key, x, y, width, height) { var srcCanvas = this.canvas; if (width === undefined) { width = srcCanvas.width; } else { width *= this.resolution; } if (height === undefined) { height = srcCanvas.height; } else { height *= this.resolution; } CopyCanvasToTexture(this.scene, srcCanvas, key, x, y, width, height); return this; }, loadTexture(key, frame) { var textureFrame = this.scene.sys.textures.getFrame(key, frame); if (!textureFrame) { return this; } if ((this.width !== textureFrame.cutWidth) || (this.height !== textureFrame.cutHeight)) { this.setSize(textureFrame.cutWidth, textureFrame.cutHeight); } else { this.clear(); } this.drawFrame(key, frame); this.dirty = true; return this; } }; const MainVersionNumber = 4; const SubVersionNumber = 0; var IsChecked = false; var CheckP3Version = function (minVersion) { if (IsChecked) { return; } if (minVersion === undefined) { minVersion = SubVersionNumber; } var version = Phaser.VERSION.split('.'); var mainVersion = parseInt(version[0]); if (mainVersion === MainVersionNumber) { var subVersion = parseInt(version[1]); if (subVersion < minVersion) { console.error(`Minimum supported version : ${mainVersion}.${subVersion}`); } } else { console.error(`Can't supported version : ${mainVersion}`); } IsChecked = true; }; CheckP3Version(); const CanvasPool = Phaser.Display.Canvas.CanvasPool; const GameObject = Phaser.GameObjects.GameObject; const UUID = Phaser.Utils.String.UUID; const DefaultImageNodes = Phaser.Renderer.WebGL.RenderNodes.Defaults.DefaultImageNodes; class Canvas extends GameObject { constructor(scene, x, y, width, height, resolution) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (width === undefined) { width = 1; } if (height === undefined) { height = 1; } if (resolution === undefined) { resolution = 1; } super(scene, 'rexCanvas'); this.renderer = scene.sys.game.renderer; this._width = width; this._height = height; this.resolution = resolution; width = Math.max(Math.ceil(width * this.resolution), 1); height = Math.max(Math.ceil(height * this.resolution), 1); this.canvas = CanvasPool.create(this, width, height); this.dirty = false; this.setPosition(x, y); this.setOrigin(0.5, 0.5); this.initRenderNodes(this._defaultRenderNodesMap); this._crop = this.resetCropObject(); // Create a Texture for this Text object this._textureKey = UUID(); this.texture = scene.sys.textures.addCanvas(this._textureKey, this.canvas); // Set the context to be the CanvasTexture context this.context = this.texture.context; // Get the frame this.frame = this.texture.get(); // Set the resolution this.frame.source.resolution = this.resolution; if (this.renderer && this.renderer.gl) { // Clear the default 1x1 glTexture, as we override it later this.renderer.deleteTexture(this.frame.source.glTexture); this.frame.source.glTexture = null; } this.dirty = true; } preDestroy() { CanvasPool.remove(this.canvas); this.canvas = null; this.context = null; var texture = this.texture; if (texture) { texture.destroy(); } } get _defaultRenderNodesMap() { return DefaultImageNodes; } setResolution(resolution) { if (this.resolution === resolution) { return this; } this.resolution = resolution; var width = Math.max(Math.ceil(this.width * resolution), 1); var height = Math.max(Math.ceil(this.height * resolution), 1); this.canvas.width = width; this.canvas.height = height; this.frame.source.resolution = resolution; this.dirty = true; return this; } get width() { return this._width; } set width(value) { this.setSize(value, this._height); } get height() { return this._height; } set height(value) { this.setSize(this._width, value); } setCanvasSize(width, height) { if ((this._width === width) && (this._height === height)) { return this; } this._width = width; this._height = height; this.updateDisplayOrigin(); width = Math.max(Math.ceil(width * this.resolution), 1); height = Math.max(Math.ceil(height * this.resolution), 1); this.canvas.width = width; this.canvas.height = height; this.frame.setSize(width, height); this.frame.source.updateSize(width, height); this.frame.updateUVs(); this.dirty = true; return this; } // setSize might be override setSize(width, height) { this.setCanvasSize(width, height); return this; } get displayWidth() { return this.scaleX * this._width; } set displayWidth(value) { this.scaleX = value / this._width; } get displayHeight() { return this.scaleY * this._height; } set displayHeight(value) { this.scaleY = value / this._height; } setDisplaySize(width, height) { this.displayWidth = width; this.displayHeight = height; return this; } getCanvas(readOnly) { if (!readOnly) { this.dirty = true; } return this.canvas; } getContext(readOnly) { if (!readOnly) { this.dirty = true; } return this.context; } needRedraw() { this.dirty = true; return this; } resize(width, height) { this.setSize(width, height); return this; } } const Components = Phaser.GameObjects.Components; Phaser.Class.mixin(Canvas, [ Components.Alpha, Components.BlendMode, Components.Crop, Components.Depth, Components.Flip, Components.GetBounds, Components.Lighting, Components.Mask, Components.Origin, Components.RenderNodes, Components.ScrollFactor, Components.Tint, Components.Transform, Components.Visible, Render, CanvasMethods, TextureMethods, ] ); const Linear$2 = Phaser.Math.Linear; const Percent$1 = Phaser.Math.Percent; var ProgressValueMethods = { setValue(value, min, max) { if ((value === undefined) || (value === null)) { return this; } if (min !== undefined) { value = Percent$1(value, min, max); } this.value = value; return this; }, addValue(inc, min, max) { if (min !== undefined) { inc = Percent$1(inc, min, max); } this.value += inc; return this; }, getValue(min, max) { var value = this.value; if ((min !== undefined) && (max !== undefined)) { value = Linear$2(min, max, value); } return value; } }; var EventEmitterMethods = { 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 []; }, }; const SceneClass = Phaser.Scene; var IsSceneObject = function (object) { return (object instanceof SceneClass); }; var GetSceneObject = function (object) { if ((object == null) || (typeof (object) !== 'object')) { return null; } else if (IsSceneObject(object)) { // object = scene return object; } else if (object.scene && IsSceneObject(object.scene)) { // object = game object return object.scene; } else if (object.parent && object.parent.scene && IsSceneObject(object.parent.scene)) { // parent = bob object return object.parent.scene; } else { return null; } }; const GameClass = Phaser.Game; var IsGame = function (object) { return (object instanceof GameClass); }; var GetGame = function (object) { if ((object == null) || (typeof (object) !== 'object')) { return null; } else if (IsGame(object)) { return object; } else if (IsGame(object.game)) { return object.game; } else if (IsSceneObject(object)) { // object = scene object return object.sys.game; } else if (IsSceneObject(object.scene)) { // object = game object return object.scene.sys.game; } }; const GetValue$7 = Phaser.Utils.Objects.GetValue; class ComponentBase { constructor(parent, config) { this.setParent(parent); // gameObject, scene, or game this.isShutdown = false; // Event emitter, default is private event emitter this.setEventEmitter(GetValue$7(config, 'eventEmitter', true)); // Register callback of parent destroy event, also see `shutdown` method if (this.parent) { if (this.parent === this.scene) { // parent is a scene this.scene.sys.events.once('shutdown', this.onEnvDestroy, this); } else if (this.parent === this.game) { // parent is game this.game.events.once('shutdown', this.onEnvDestroy, this); } else if (this.parent.once) { // parent is game object or something else this.parent.once('destroy', this.onParentDestroy, this); } // bob object does not have event emitter } } shutdown(fromScene) { // Already shutdown if (this.isShutdown) { return; } // parent might not be shutdown yet if (this.parent) { if (this.parent === this.scene) { // parent is a scene this.scene.sys.events.off('shutdown', this.onEnvDestroy, this); } else if (this.parent === this.game) { // parent is game this.game.events.off('shutdown', this.onEnvDestroy, this); } else if (this.parent.once) { // parent is game object or something else this.parent.off('destroy', this.onParentDestroy, this); } // bob object does not have event emitter } this.destroyEventEmitter(); this.parent = undefined; this.scene = undefined; this.game = undefined; this.isShutdown = true; } destroy(fromScene) { this.shutdown(fromScene); } onEnvDestroy() { this.destroy(true); } onParentDestroy(parent, fromScene) { this.destroy(fromScene); } setParent(parent) { this.parent = parent; // gameObject, scene, or game this.scene = GetSceneObject(parent); this.game = GetGame(parent); return this; } } Object.assign( ComponentBase.prototype, EventEmitterMethods ); const GetValue$6 = Phaser.Utils.Objects.GetValue; class TickTask extends ComponentBase { constructor(parent, config) { super(parent, config); this._isRunning = false; this.isPaused = false; this.tickingState = false; this.setTickingMode(GetValue$6(config, 'tickingMode', 1)); // boot() later } // override boot() { if ((this.tickingMode === 2) && (!this.tickingState)) { this.startTicking(); } } // override shutdown(fromScene) { // Already shutdown if (this.isShutdown) { return; } this.stop(); if (this.tickingState) { this.stopTicking(); } super.shutdown(fromScene); } setTickingMode(mode) { if (typeof (mode) === 'string') { mode = TICKINGMODE[mode]; } this.tickingMode = mode; } // override startTicking() { this.tickingState = true; } // override stopTicking() { this.tickingState = false; } get isRunning() { return this._isRunning; } set isRunning(value) { if (this._isRunning === value) { return; } this._isRunning = value; if ((this.tickingMode === 1) && (value != this.tickingState)) { if (value) { this.startTicking(); } else { this.stopTicking(); } } } start() { this.isPaused = false; this.isRunning = true; return this; } pause() { // Only can ba paused in running state if (this.isRunning) { this.isPaused = true; this.isRunning = false; } return this; } resume() { // Only can ba resumed in paused state (paused from running state) if (this.isPaused) { this.isPaused = false; this.isRunning = true; } return this; } stop() { this.isPaused = false; this.isRunning = false; return this; } complete() { this.isPaused = false; this.isRunning = false; this.emit('complete', this.parent, this); } } const TICKINGMODE = { 'no': 0, 'lazy': 1, 'always': 2 }; const GetValue$5 = Phaser.Utils.Objects.GetValue; class SceneUpdateTickTask extends TickTask { constructor(parent, config) { super(parent, config); // scene update : update, preupdate, postupdate, prerender, render // game update : step, poststep, // If this.scene is not available, use game's 'step' event var defaultEventName = (this.scene) ? 'update' : 'step'; this.tickEventName = GetValue$5(config, 'tickEventName', defaultEventName); this.isSceneTicker = !IsGameUpdateEvent(this.tickEventName); } startTicking() { super.startTicking(); if (this.isSceneTicker) { this.scene.sys.events.on(this.tickEventName, this.update, this); } else { this.game.events.on(this.tickEventName, this.update, this); } } stopTicking() { super.stopTicking(); if (this.isSceneTicker && this.scene) { // Scene might be destoryed this.scene.sys.events.off(this.tickEventName, this.update, this); } else if (this.game) { this.game.events.off(this.tickEventName, this.update, this); } } // update(time, delta) { // // } } var IsGameUpdateEvent = function (eventName) { return (eventName === 'step') || (eventName === 'poststep'); }; const GetValue$4 = Phaser.Utils.Objects.GetValue; const Clamp$2 = Phaser.Math.Clamp; class Timer { constructor(config) { this.resetFromJSON(config); } resetFromJSON(o) { this.state = GetValue$4(o, 'state', IDLE); this.timeScale = GetValue$4(o, 'timeScale', 1); this.delay = GetValue$4(o, 'delay', 0); this.repeat = GetValue$4(o, 'repeat', 0); this.repeatCounter = GetValue$4(o, 'repeatCounter', 0); this.repeatDelay = GetValue$4(o, 'repeatDelay', 0); this.duration = GetValue$4(o, 'duration', 0); this.nowTime = GetValue$4(o, 'nowTime', 0); this.justRestart = GetValue$4(o, 'justRestart', false); } toJSON() { return { state: this.state, timeScale: this.timeScale, delay: this.delay, repeat: this.repeat, repeatCounter: this.repeatCounter, repeatDelay: this.repeatDelay, duration: this.duration, nowTime: this.nowTime, justRestart: this.justRestart, } } destroy() { } setTimeScale(timeScale) { this.timeScale = timeScale; return this; } setDelay(delay) { if (delay === undefined) { delay = 0; } this.delay = delay; return this; } setDuration(duration) { this.duration = duration; return this; } setRepeat(repeat) { this.repeat = repeat; return this; } setRepeatInfinity() { this.repeat = -1; return this; } setRepeatDelay(repeatDelay) { this.repeatDelay = repeatDelay; return this; } start() { this.nowTime = (this.delay > 0) ? -this.delay : 0; this.state = (this.nowTime >= 0) ? COUNTDOWN : DELAY; this.repeatCounter = 0; return this; } stop() { this.state = IDLE; return this; } update(time, delta) { if (this.state === IDLE || this.state === DONE || delta === 0 || this.timeScale === 0 ) { return; } this.nowTime += (delta * this.timeScale); this.justRestart = false; if (this.nowTime >= this.duration) { if ((this.repeat === -1) || (this.repeatCounter < this.repeat)) { this.repeatCounter++; this.justRestart = true; this.nowTime -= this.duration; if (this.repeatDelay > 0) { this.nowTime -= this.repeatDelay; this.state = REPEATDELAY; } } else { this.nowTime = this.duration; this.state = DONE; } } else if (this.nowTime >= 0) { this.state = COUNTDOWN; } } get t() { var t; switch (this.state) { case IDLE: case DELAY: case REPEATDELAY: t = 0; break; case COUNTDOWN: t = this.nowTime / this.duration; break; case DONE: t = 1; break; } return Clamp$2(t, 0, 1); } set t(value) { value = Clamp$2(value, -1, 1); if (value < 0) { this.state = DELAY; this.nowTime = -this.delay * value; } else { this.state = COUNTDOWN; this.nowTime = this.duration * value; if ((value === 1) && (this.repeat !== 0)) { this.repeatCounter++; } } } setT(t) { this.t = t; return this; } get isIdle() { return this.state === IDLE; } get isDelay() { return this.state === DELAY; } get isCountDown() { return this.state === COUNTDOWN; } get isRunning() { return this.state === DELAY || this.state === COUNTDOWN; } get isDone() { return this.state === DONE; } get isOddIteration() { return (this.repeatCounter & 1) === 1; } get isEvenIteration() { return (this.repeatCounter & 1) === 0; } } const IDLE = 0; const DELAY = 1; const COUNTDOWN = 2; const REPEATDELAY = 3; const DONE = -1; class TimerTickTask extends SceneUpdateTickTask { constructor(parent, config) { super(parent, config); this.timer = new Timer(); // boot() later } // override shutdown(fromScene) { // Already shutdown if (this.isShutdown) { return; } super.shutdown(fromScene); this.timer.destroy(); this.timer = undefined; } start() { this.timer.start(); super.start(); return this; } stop() { this.timer.stop(); super.stop(); return this; } complete() { this.timer.stop(); super.complete(); return this; } } const GetValue$3 = Phaser.Utils.Objects.GetValue; const GetAdvancedValue = Phaser.Utils.Objects.GetAdvancedValue; const GetEaseFunction = Phaser.Tweens.Builders.GetEaseFunction; class EaseValueTaskBase extends TimerTickTask { resetFromJSON(o) { this.timer.resetFromJSON(GetValue$3(o, 'timer')); this.setEnable(GetValue$3(o, 'enable', true)); this.setTarget(GetValue$3(o, 'target', this.parent)); this.setDelay(GetAdvancedValue(o, 'delay', 0)); this.setDuration(GetAdvancedValue(o, 'duration', 1000)); this.setEase(GetValue$3(o, 'ease', 'Linear')); this.setRepeat(GetValue$3(o, 'repeat', 0)); return this; } setEnable(e) { if (e == undefined) { e = true; } this.enable = e; return this; } setTarget(target) { if (target === undefined) { target = this.parent; } this.target = target; return this; } setDelay(time) { this.delay = time; // Assign `this.timer.setRepeat(repeat)` manually return this; } setDuration(time) { this.duration = time; return this; } setRepeat(repeat) { this.repeat = repeat; // Assign `this.timer.setRepeat(repeat)` manually return this; } setRepeatDelay(repeatDelay) { this.repeatDelay = repeatDelay; // Assign `this.timer.setRepeatDelay(repeatDelay)` manually return this; } setEase(ease) { if (ease === undefined) { ease = 'Linear'; } this.ease = ease; this.easeFn = GetEaseFunction(ease); return this; } // Override start() { // Ignore start if timer is running, i.e. in DELAY, o RUN state if (this.timer.isRunning) { return this; } super.start(); return this; } restart() { this.timer.stop(); this.start.apply(this, arguments); return this; } stop(toEnd) { if (toEnd === undefined) { toEnd = false; } super.stop(); if (toEnd) { this.timer.setT(1); this.updateTarget(this.target, this.timer); this.complete(); } return this; } update(time, delta) { if ( (!this.isRunning) || (!this.enable) || (this.parent.hasOwnProperty('active') && !this.parent.active) ) { return this; } var target = this.target, timer = this.timer; timer.update(time, delta); // isDelay, isCountDown, isDone if (!timer.isDelay) { this.updateTarget(target, timer); } this.emit('update', target, this); if (timer.isDone) { this.complete(); } return this; } // Override updateTarget(target, timer) { } } const GetValue$2 = Phaser.Utils.Objects.GetValue; const Linear$1 = Phaser.Math.Linear; class EaseValueTask extends EaseValueTaskBase { constructor(gameObject, config) { super(gameObject, config); // this.parent = gameObject; // this.timer this.resetFromJSON(); this.boot(); } start(config) { if (this.timer.isRunning) { return this; } var target = this.target; this.propertyKey = GetValue$2(config, 'key', 'value'); var currentValue = target[this.propertyKey]; this.fromValue = GetValue$2(config, 'from', currentValue); this.toValue = GetValue$2(config, 'to', currentValue); this.setEase(GetValue$2(config, 'ease', this.ease)); this.setDuration(GetValue$2(config, 'duration', this.duration)); this.setRepeat(GetValue$2(config, 'repeat', 0)); this.setDelay(GetValue$2(config, 'delay', 0)); this.setRepeatDelay(GetValue$2(config, 'repeatDelay', 0)); this.timer .setDuration(this.duration) .setRepeat(this.repeat) .setDelay(this.delay) .setRepeatDelay(this.repeatDelay); target[this.propertyKey] = this.fromValue; super.start(); return this; } updateTarget(target, timer) { var t = timer.t; t = this.easeFn(t); target[this.propertyKey] = Linear$1(this.fromValue, this.toValue, t); } } const Percent = Phaser.Math.Percent; var EaseValueMethods = { setEaseValuePropName(name) { this.easeValuePropName = name; return this; }, setEaseValueDuration(duration) { this.easeValueDuration = duration; return this; }, setEaseValueFunction(ease) { this.easeFunction = ease; return this; }, stopEaseValue() { if (this.easeValueTask) { this.easeValueTask.stop(); } return this; }, easeValueTo(value, min, max) { if ((value === undefined) || (value === null)) { return this; } if (min !== undefined) { value = Percent(value, min, max); } if (this.easeValueTask === undefined) { this.easeValueTask = new EaseValueTask(this, { eventEmitter: null }); } this.easeValueTask.restart({ key: this.easeValuePropName, to: value, duration: this.easeValueDuration, ease: this.easeFunction, }); return this; }, easeValueRepeat(from, to, repeat, repeatDelay) { if (repeat === undefined) { repeat = -1; } if (repeatDelay === undefined) { repeatDelay = 0; } if (this.easeValueTask === undefined) { this.easeValueTask = new EaseValueTask(this, { eventEmitter: null }); } this.easeValueTask.restart({ key: this.easeValuePropName, from: from, to: to, duration: this.easeValueDuration, ease: this.easeFunction, repeat: repeat, repeatDelay: repeatDelay, }); return this; }, }; const GetValue$1 = Phaser.Utils.Objects.GetValue; const Clamp$1 = Phaser.Math.Clamp; function ProgressBase (BaseClass) { class ProgressBase extends BaseClass { bootProgressBase(config) { this.eventEmitter = GetValue$1(config, 'eventEmitter', this); var callback = GetValue$1(config, 'valuechangeCallback', null); if (callback !== null) { var scope = GetValue$1(config, 'valuechangeCallbackScope', undefined); this.eventEmitter.on('valuechange', callback, scope); } this .setEaseValuePropName('value') .setEaseValueDuration(GetValue$1(config, 'easeValue.duration', 0)) .setEaseValueFunction(GetValue$1(config, 'easeValue.ease', 'Linear')); return this; } get value() { return this._value; } set value(value) { value = Clamp$1(value, 0, 1); var oldValue = this._value; var valueChanged = (oldValue != value); this.dirty = this.dirty || valueChanged; this._value = value; if (valueChanged) { this.eventEmitter.emit('valuechange', this._value, oldValue, this.eventEmitter); } } } Object.assign( ProgressBase.prototype, ProgressValueMethods, EaseValueMethods ); return ProgressBase; } const Pad = Phaser.Utils.String.Pad; var GetStyle = function (style, canvas, context) { if (style == null) { return style; } switch (typeof (style)) { case 'string': return style; case 'number': return `#${Pad(Math.floor(style).toString(16), 6, '0', 1)}`; case 'function': return style(canvas, context); case 'object': if (style.hasOwnProperty('r')) { if (style.hasOwnProperty('a')) { // rgba return `rgba(${style.r},${style.g},${style.b},${style.a})`; } else { // rgb return `rgb(${style.r},${style.g},${style.b})`; } } else if (style.hasOwnProperty('h')) { if (style.hasOwnProperty('a')) { // hsla return `hsla(${style.h},${style.s},${style.l},${style.a})`; } else { // hsl return `hsl(${style.h},${style.s},${style.l})`; } } else { return style; // Not a valid input } default: return style; } }; var DrawCircle = function ( canvas, context, x, y, rx, ry, fillStyle, strokeStyle, lineWidth, startAngle, endAngle, anticlockwise ) { if (startAngle === undefined) { startAngle = 0; } if (endAngle === undefined) { endAngle = 2 * Math.PI; } if (anticlockwise === undefined) { anticlockwise = false; } context.beginPath(); context.ellipse(x, y, rx, ry, 0, startAngle, endAngle, anticlockwise); if (fillStyle != null) { context.fillStyle = fillStyle; context.fill(); } if (strokeStyle != null) { context.strokeStyle = strokeStyle; context.lineWidth = lineWidth; context.stroke(); } }; const ColorNames = ['AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque', 'Black', 'BlanchedAlmond', 'Blue', 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue', 'Chartreuse', 'Chocolate', 'Coral', 'CornflowerBlue', 'Cornsilk', 'Crimson', 'Cyan', 'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGrey', 'DarkGreen', 'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrange', 'DarkOrchid', 'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray', 'DarkSlateGrey', 'DarkTurquoise', 'DarkViolet', 'DeepPink', 'DeepSkyBlue', 'DimGray', 'DimGrey', 'DodgerBlue', 'FireBrick', 'FloralWhite', 'ForestGreen', 'Fuchsia', 'Gainsboro', 'GhostWhite', 'Gold', 'GoldenRod', 'Gray', 'Grey', 'Green', 'GreenYellow', 'HoneyDew', 'HotPink', 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender', 'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue', 'LightCoral', 'LightCyan', 'LightGoldenRodYellow', 'LightGray', 'LightGrey', 'LightGreen', 'LightPink', 'LightSalmon', 'LightSeaGreen', 'LightSkyBlue', 'LightSlateGray', 'LightSlateGrey', 'LightSteelBlue', 'LightYellow', 'Lime', 'LimeGreen', 'Linen', 'Magenta', 'Maroon', 'MediumAquaMarine', 'MediumBlue', 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue', 'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed', 'MidnightBlue', 'MintCream', 'MistyRose', 'Moccasin', 'NavajoWhite', 'Navy', 'OldLace', 'Olive', 'OliveDrab', 'Orange', 'OrangeRed', 'Orchid', 'PaleGoldenRod', 'PaleGreen', 'PaleTurquoise', 'PaleVioletRed', 'PapayaWhip', 'PeachPuff', 'Peru', 'Pink', 'Plum', 'PowderBlue', 'Purple', 'RebeccaPurple', 'Red', 'RosyBrown', 'RoyalBlue', 'SaddleBrown', 'Salmon', 'SandyBrown', 'SeaGreen', 'SeaShell', 'Sienna', 'Silver', 'SkyBlue', 'SlateBlue', 'SlateGray', 'SlateGrey', 'Snow', 'SpringGreen', 'SteelBlue', 'Tan', 'Teal', 'Thistle', 'Tomato', 'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen']; const ColorValues = [0xf0f8ff, 0xfaebd7, 0x00ffff, 0x7fffd4, 0xf0ffff, 0xf5f5dc, 0xffe4c4, 0x000000, 0xffebcd, 0x0000ff, 0x8a2be2, 0xa52a2a, 0xdeb887, 0x5f9ea0, 0x7fff00, 0xd2691e, 0xff7f50, 0x6495ed, 0xfff8dc, 0xdc143c, 0x00ffff, 0x00008b, 0x008b8b, 0xb8860b, 0xa9a9a9, 0xa9a9a9, 0x006400, 0xbdb76b, 0x8b008b, 0x556b2f, 0xff8c00, 0x9932cc, 0x8b0000, 0xe9967a, 0x8fbc8f, 0x483d8b, 0x2f4f4f, 0x2f4f4f, 0x00ced1, 0x9400d3, 0xff1493, 0x00bfff, 0x696969, 0x696969, 0x1e90ff, 0xb22222, 0xfffaf0, 0x228b22, 0xff00ff, 0xdcdcdc, 0xf8f8ff, 0xffd700, 0xdaa520, 0x808080, 0x808080, 0x008000, 0xadff2f, 0xf0fff0, 0xff69b4, 0xcd5c5c, 0x4b0082, 0xfffff0, 0xf0e68c, 0xe6e6fa, 0xfff0f5, 0x7cfc00, 0xfffacd, 0xadd8e6, 0xf08080, 0xe0ffff, 0xfafad2, 0xd3d3d3, 0xd3d3d3, 0x90ee90, 0xffb6c1, 0xffa07a, 0x20b2aa, 0x87cefa, 0x778899, 0x778899, 0xb0c4de, 0xffffe0, 0x00ff00, 0x32cd32, 0xfaf0e6, 0xff00ff, 0x800000, 0x66cdaa, 0x0000cd, 0xba55d3, 0x9370db, 0x3cb371, 0x7b68ee, 0x00fa9a, 0x48d1cc, 0xc71585, 0x191970, 0xf5fffa, 0xffe4e1, 0xffe4b5, 0xffdead, 0x000080, 0xfdf5e6, 0x808000, 0x6b8e23, 0xffa500, 0xff4500, 0xda70d6, 0xeee8aa, 0x98fb98, 0xafeeee, 0xdb7093, 0xffefd5, 0xffdab9, 0xcd853f, 0xffc0cb, 0xdda0dd, 0xb0e0e6, 0x800080, 0x663399, 0xff0000, 0xbc8f8f, 0x4169e1, 0x8b4513, 0xfa8072, 0xf4a460, 0x2e8b57, 0xfff5ee, 0xa0522d, 0xc0c0c0, 0x87ceeb, 0x6a5acd, 0x708090, 0x708090, 0xfffafa, 0x00ff7f, 0x4682b4, 0xd2b48c, 0x008080, 0xd8bfd8, 0xff6347, 0x40e0d0, 0xee82ee, 0xf5deb3, 0xffffff, 0xf5f5f5, 0xffff00, 0x9acd32]; var ColorNameToIntegerDict = {}, name; for (var i = 0, cnt = ColorNames.length; i < cnt; i++) { name = ColorNames[i].toLowerCase(); ColorNameToIntegerDict[name] = ColorValues[i]; } var ColorNameToInteger = function (colorName) { colorName = colorName.toLowerCase(); if (ColorNameToIntegerDict.hasOwnProperty(colorName)) { return ColorNameToIntegerDict[colorName]; } else { return null; } }; var ColorStringToInteger = function (value) { if (typeof (value) !== 'string') { return value; } if (value.startsWith('#')) { value = parseInt(value.substring(1), 16); } else if (value.startsWith('0x')) { value = parseInt(value.substring(2), 16); } else { value = ColorNameToInteger(value); } return value; }; var GetRGB = function (colorInt, out) { if (out === undefined) { out = {}; } out.r = (colorInt >> 16) & 0xff; out.g = (colorInt >> 8) & 0xff; out.b = (colorInt) & 0xff; return out; }; const DegToRad = Phaser.Math.DegToRad; const Linear = Phaser.Math.Linear; var DrawGradientArc = function ( canvas, context, x, y, rx, ry, startColor, endColor, lineWidth, startAngle, endAngle, anticlockwise, AngleStepDeg ) { if (startAngle === undefined) { startAngle = 0; } if (endAngle === undefined) { endAngle = 2 * Math.PI; } if (anticlockwise === undefined) { anticlockwise = false; } if (AngleStepDeg === undefined) { AngleStepDeg = 2; } startColor = ColorStringToInteger(startColor); endColor = ColorStringToInteger(