phaser4-rex-plugins
Version:
1,770 lines (1,428 loc) • 82.7 kB
JavaScript
(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.rexcircularprogress = factory());
})(this, (function () { 'use strict';
const GetCalcMatrix = Phaser.GameObjects.GetCalcMatrix;
var WebGLRenderer = function (renderer, src, drawingContext, parentMatrix) {
src.updateData();
var camera = drawingContext.camera;
camera.addToRenderList(src);
var calcMatrix = GetCalcMatrix(src, camera, parentMatrix, !drawingContext.useCanvas).calc;
var dx = src._displayOriginX;
var dy = src._displayOriginY;
var alpha = src.alpha;
var submitter = src.customRenderNodes.Submitter || src.defaultRenderNodes.Submitter;
var shapes = src.geom,
shape;
for (var i = 0, cnt = shapes.length; i < cnt; i++) {
shape = shapes[i];
if (shape.visible) {
shape.webglRender(drawingContext, submitter, calcMatrix, src, alpha, dx, dy);
}
}
};
const SetTransform = Phaser.Renderer.Canvas.SetTransform;
var CanvasRenderer = function (renderer, src, camera, parentMatrix) {
src.updateData();
camera.addToRenderList(src);
var ctx = renderer.currentContext;
if (SetTransform(renderer, ctx, src, camera, parentMatrix)) {
var dx = src._displayOriginX;
var dy = src._displayOriginY;
var shapes = src.geom,
shape;
for (var i = 0, cnt = shapes.length; i < cnt; i++) {
shape = shapes[i];
if (shape.visible) {
shape.canvasRender(ctx, dx, dy);
}
}
// Restore the context saved in SetTransform
ctx.restore();
}
};
var Render = {
renderWebGL: WebGLRenderer,
renderCanvas: CanvasRenderer
};
var Clear = function (obj) {
if ((typeof (obj) !== 'object') || (obj === null)) {
return obj;
}
if (Array.isArray(obj)) {
obj.length = 0;
} else {
for (var key in obj) {
delete obj[key];
}
}
return obj;
};
const Shape = Phaser.GameObjects.Shape;
const RemoveItem = Phaser.Utils.Array.Remove;
class BaseShapes extends Shape {
constructor(scene, x, y, width, height) {
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (width === undefined) {
width = 2;
}
if (height === undefined) {
height = width;
}
super(scene, 'rexShapes', []);
this._width = -1;
this._height = -1;
this.dirty = true;
this.isSizeChanged = true;
this.shapes = {};
this.setPosition(x, y);
this.setSize(width, height);
this.updateDisplayOrigin();
}
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);
}
setDirty(value) {
if (value === undefined) {
value = true;
}
this.dirty = value;
return this;
}
setSize(width, height) {
this.isSizeChanged = this.isSizeChanged || (this._width !== width) || (this._height !== height);
this.dirty = this.dirty || this.isSizeChanged;
this._width = width;
this._height = height;
this.updateDisplayOrigin();
var input = this.input;
if (input && !input.customHitArea) {
input.hitArea.width = width;
input.hitArea.height = height;
}
return this;
}
resize(width, height) {
this.setSize(width, height);
return this;
}
get fillColor() {
return this._fillColor;
}
set fillColor(value) {
this.setFillStyle(value, this._fillAlpha);
}
get fillAlpha() {
return this._fillAlpha;
}
set fillAlpha(value) {
this.setFillStyle(this._fillColor, value);
}
setFillStyle(color, alpha) {
if (alpha === undefined) {
alpha = 1;
}
this.dirty = this.dirty ||
(this.fillColor !== color) ||
(this.fillAlpha !== alpha);
this._fillColor = color;
this._fillAlpha = alpha;
return this;
}
get lineWidth() {
return this._lineWidth;
}
set lineWidth(value) {
this.setStrokeStyle(value, this._strokeColor, this._strokeAlpha);
}
get strokeColor() {
return this._strokeColor;
}
set strokeColor(value) {
this.setStrokeStyle(this._lineWidth, value, this._strokeAlpha);
}
get strokeAlpha() {
return this._strokeAlpha;
}
set strokeAlpha(value) {
this.setStrokeStyle(this._lineWidth, this._strokeColor, value);
}
setStrokeStyle(lineWidth, color, alpha) {
if (alpha === undefined) {
alpha = 1;
}
this.dirty = this.dirty ||
(this.lineWidth !== lineWidth) ||
(this.strokeColor !== color) ||
(this.strokeAlpha !== alpha);
this._lineWidth = lineWidth;
this._strokeColor = color;
this._strokeAlpha = alpha;
return this;
}
updateShapes() {
}
updateData() {
if (!this.dirty) {
return this;
}
this.updateShapes();
var shapes = this.geom;
for (var i = 0, cnt = shapes.length; i < cnt; i++) {
var shape = shapes[i];
if (shape.dirty) {
shape.updateData();
}
}
this.isSizeChanged = false;
this.dirty = false;
return this;
}
clear() {
this.geom.length = 0;
Clear(this.shapes);
this.dirty = true;
return this;
}
getShape(name) {
return this.shapes[name];
}
getShapes() {
return this.geom;
}
addShape(shape) {
this.geom.push(shape);
var name = shape.name;
if (name) {
this.shapes[name] = shape;
}
this.dirty = true;
return this;
}
deleteShape(name) {
var shape = this.getShape(name);
if (shape) {
delete this.shapes[name];
RemoveItem(this.geom, shape);
}
return this;
}
}
Object.assign(
BaseShapes.prototype,
Render
);
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$8 = 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$8(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$7 = 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$7(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$6 = 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$6(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$5 = Phaser.Utils.Objects.GetValue;
const Clamp$2 = Phaser.Math.Clamp;
class Timer {
constructor(config) {
this.resetFromJSON(config);
}
resetFromJSON(o) {
this.state = GetValue$5(o, 'state', IDLE);
this.timeScale = GetValue$5(o, 'timeScale', 1);
this.delay = GetValue$5(o, 'delay', 0);
this.repeat = GetValue$5(o, 'repeat', 0);
this.repeatCounter = GetValue$5(o, 'repeatCounter', 0);
this.repeatDelay = GetValue$5(o, 'repeatDelay', 0);
this.duration = GetValue$5(o, 'duration', 0);
this.nowTime = GetValue$5(o, 'nowTime', 0);
this.justRestart = GetValue$5(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$4 = 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$4(o, 'timer'));
this.setEnable(GetValue$4(o, 'enable', true));
this.setTarget(GetValue$4(o, 'target', this.parent));
this.setDelay(GetAdvancedValue(o, 'delay', 0));
this.setDuration(GetAdvancedValue(o, 'duration', 1000));
this.setEase(GetValue$4(o, 'ease', 'Linear'));
this.setRepeat(GetValue$4(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$3 = 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$3(config, 'key', 'value');
var currentValue = target[this.propertyKey];
this.fromValue = GetValue$3(config, 'from', currentValue);
this.toValue = GetValue$3(config, 'to', currentValue);
this.setEase(GetValue$3(config, 'ease', this.ease));
this.setDuration(GetValue$3(config, 'duration', this.duration));
this.setRepeat(GetValue$3(config, 'repeat', 0));
this.setDelay(GetValue$3(config, 'delay', 0));
this.setRepeatDelay(GetValue$3(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$2 = Phaser.Utils.Objects.GetValue;
const Clamp$1 = Phaser.Math.Clamp;
function ProgressBase (BaseClass) {
class ProgressBase extends BaseClass {
bootProgressBase(config) {
this.eventEmitter = GetValue$2(config, 'eventEmitter', this);
var callback = GetValue$2(config, 'valuechangeCallback', null);
if (callback !== null) {
var scope = GetValue$2(config, 'valuechangeCallbackScope', undefined);
this.eventEmitter.on('valuechange', callback, scope);
}
this
.setEaseValuePropName('value')
.setEaseValueDuration(GetValue$2(config, 'easeValue.duration', 0))
.setEaseValueFunction(GetValue$2(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;
}
var FillStyle = function (color, alpha) {
if (color == null) {
this.isFilled = false;
} else {
if (alpha === undefined) {
alpha = 1;
}
this.isFilled = true;
this.fillColor = color;
this.fillAlpha = alpha;
}
return this;
};
var LineStyle = function (lineWidth, color, alpha) {
if ((lineWidth == null) || (color == null)) {
this.isStroked = false;
} else {
if (alpha === undefined) {
alpha = 1;
}
this.isStroked = true;
this.lineWidth = lineWidth;
this.strokeColor = color;
this.strokeAlpha = alpha;
}
return this;
};
var StyleMethods = {
fillStyle: FillStyle,
lineStyle: LineStyle
};
var GetValue$1 = function (source, key, defaultValue) {
if (!source || typeof source === 'number') {
return defaultValue;
}
if (typeof (key) === 'string') {
if (source.hasOwnProperty(key)) {
return source[key];
}
if (key.indexOf('.') !== -1) {
key = key.split('.');
} else {
return defaultValue;
}
}
var keys = key;
var parent = source;
var value = defaultValue;
// Use for loop here so we can break early
for (var i = 0; i < keys.length; i++) {
key = keys[i];
if (parent.hasOwnProperty(key)) {
// Yes it has a key property, let's carry on down
value = parent[key];
parent = value;
}
else {
// Can't go any further, so reset to default
value = defaultValue;
break;
}
}
return value;
};
var DataMethods = {
enableData() {
if (this.data === undefined) {
this.data = {};
}
return this;
},
setData(key, value) {
this.enableData();
if (arguments.length === 1) {
var data = key;
for (key in data) {
this.data[key] = data[key];
}
} else {
this.data[key] = value;
}
return this;
},
getData(key, defaultValue) {
this.enableData();
return (key === undefined) ? this.data : GetValue$1(this.data, key, defaultValue);
},
incData(key, inc, defaultValue) {
if (defaultValue === undefined) {
defaultValue = 0;
}
this.enableData();
this.setData(key, this.getData(key, defaultValue) + inc);
return this;
},
mulData(key, mul, defaultValue) {
if (defaultValue === undefined) {
defaultValue = 0;
}
this.enableData();
this.setData(key, this.getData(key, defaultValue) * mul);
return this;
},
clearData() {
if (this.data) {
Clear(this.data);
}
return this;
},
};
class BaseGeom {
constructor() {
this.name = undefined;
this.dirty = true;
this.visible = true;
this.data = undefined;
this.isFilled = false;
this.fillColor = undefined;
this.fillAlpha = 1;
this.isStroked = false;
this.lineWidth = 1;
this.strokeColor = undefined;
this.strokeAlpha = 1;
}
setName(name) {
this.name = name;
return this;
}
setVisible(visible) {
if (visible === undefined) {
visible = true;
}
this.visible = visible;
return this;
}
reset() {
this
.setVisible()
.fillStyle()
.lineStyle();
return this;
}
webglRender(drawingContext, submitter, gameObject, calcMatrix, alpha, dx, dy) {
}
canvasRender(ctx, dx, dy) {
}
updateData() {
this.dirty = false;
}
}
Object.assign(
BaseGeom.prototype,
StyleMethods,
DataMethods
);
/*
shapeData: {
fillColor,
fillAlpha,
pathData,
pathIndexes // Earcut(pathData)
}
*/
var Utils$1 = Phaser.Renderer.WebGL.Utils;
var FillPathWebGL = function (drawingContext, submitter, calcMatrix, gameObject, shapeData, alpha, dx, dy) {
// This is very similar to the FillPath RenderNode, but it already
// has access to the Earcut indexes, so it doesn't need to calculate them.
var fillTintColor = Utils$1.getTintAppendFloatAlpha(shapeData.fillColor, shapeData.fillAlpha * alpha);
var path = shapeData.pathData;
var pathIndexes = shapeData.pathIndexes;
var length = path.length;
var pathIndex, pointX, pointY, x, y;
var vertices = Array(length * 2);
var colors = Array(length);
var verticesIndex = 0;
var colorsIndex = 0;
for (pathIndex = 0; pathIndex < length; pathIndex += 2) {
pointX = path[pathIndex] - dx;
pointY = path[pathIndex + 1] - dy;
// Transform the point.
x = calcMatrix.getX(pointX, pointY);
y = calcMatrix.getY(pointX, pointY);
vertices[verticesIndex++] = x;
vertices[verticesIndex++] = y;
colors[colorsIndex++] = fillTintColor;
}
submitter.batch(
drawingContext,
pathIndexes,
vertices,
colors
);
};
/*
shapeData: {
strokeColor,
strokeAlpha,
pathData,
lineWidth,
closePath
}
*/
var Utils = Phaser.Renderer.WebGL.Utils;
var StrokePathWebGL = function (drawingContext, submitter, matrix, gameObject, shapeData, alpha, dx, dy) {
var strokeTintColor = Utils.getTintAppendFloatAlpha(shapeData.strokeColor, shapeData.strokeAlpha * alpha);
var path = shapeData.pathData;
var pathLength = path.length - 1;
var lineWidth = shapeData.lineWidth;
var openPath = !shapeData.closePath;
var strokePath = gameObject.customRenderNodes.StrokePath || gameObject.defaultRenderNodes.StrokePath;
var pointPath = [];
// Don't add the last point to open paths.
if (openPath) {
pathLength -= 2;
}
for (var i = 0; i < pathLength; i += 2) {
var x = path[i] - dx;
var y = path[i + 1] - dy;
if (i > 0) {
if (x === path[i - 2] && y === path[i - 1]) {
// Duplicate point, skip it
continue;
}
}
pointPath.push({
x: x,
y: y,
width: lineWidth
});
}
strokePath.run(
drawingContext,
submitter,
pointPath,
lineWidth,
openPath,
matrix,
strokeTintColor, strokeTintColor, strokeTintColor, strokeTintColor
);
};
var FillStyleCanvas = function (ctx, src, altColor, altAlpha)
{
var fillColor = (altColor) ? altColor : src.fillColor;
var fillAlpha = (altAlpha) ? altAlpha : src.fillAlpha;
var red = ((fillColor & 0xFF0000) >>> 16);
var green = ((fillColor & 0xFF00) >>> 8);
var blue = (fillColor & 0xFF);
ctx.fillStyle = 'rgba(' + red + ',' + green + ',' + blue + ',' + fillAlpha + ')';
};
var LineStyleCanvas = function (ctx, src, altColor, altAlpha)
{
var strokeColor = (altColor) ? altColor : src.strokeColor;
var strokeAlpha = (altAlpha) ? altAlpha : src.strokeAlpha;
var red = ((strokeColor & 0xFF0000) >>> 16);
var green = ((strokeColor & 0xFF00) >>> 8);
var blue = (strokeColor & 0xFF);
ctx.strokeStyle = 'rgba(' + red + ',' + green + ',' + blue + ',' + strokeAlpha + ')';
ctx.lineWidth = src.lineWidth;
};
const Earcut = Phaser.Geom.Polygon.Earcut;
class PathBase extends BaseGeom {
constructor() {
super();
this.pathData = [];
this.pathIndexes = [];
this.closePath = false;
}
updateData() {
this.pathIndexes = Earcut(this.pathData);
super.updateData();
return this;
}
webglRender(drawingContext, submitter, calcMatrix, gameObject, alpha, dx, dy) {
if (this.isFilled) {
FillPathWebGL(drawingContext, submitter, calcMatrix, gameObject, this, alpha, dx, dy);
}
if (this.isStroked) {
StrokePathWebGL(drawingContext, submitter, calcMatrix, gameObject, this, alpha, dx, dy);
}
}
canvasRender(ctx, dx, dy) {
var path = this.pathData;
var pathLength = path.length - 1;
var px1 = path[0] - dx;
var py1 = path[1] - dy;
ctx.beginPath();
ctx.moveTo(px1, py1);
if (!this.closePath) {
pathLength -= 2;
}
for (var i = 2; i < pathLength; i += 2) {
var px2 = path[i] - dx;
var py2 = path[i + 1] - dy;
ctx.lineTo(px2, py2);
}
if (this.closePath) {
ctx.closePath();
}
if (this.isFilled) {
FillStyleCanvas(ctx, this);
ctx.fill();
}
if (this.isStroked) {
LineStyleCanvas(ctx, this);
ctx.stroke();
}
}
}
var LineTo = function (x, y, pathData) {
var cnt = pathData.length;
if (cnt >= 2) {
var lastX = pathData[cnt - 2];
var lastY = pathData[cnt - 1];
if ((x === lastX) && (y === lastY)) {
return pathData;
}
}
pathData.push(x, y);
return pathData;
};
const DegToRad$3 = Phaser.Math.DegToRad;
var ArcTo = function (centerX, centerY, radiusX, radiusY, startAngle, endAngle, antiClockWise, iteration, pathData) {
// startAngle, endAngle: 0 ~ 360
if (antiClockWise && (endAngle > startAngle)) {
endAngle -= 360;
} else if (!antiClockWise && (endAngle < startAngle)) {
endAngle += 360;
}
var deltaAngle = endAngle - startAngle;
var step = DegToRad$3(deltaAngle) / iteration;
startAngle = DegToRad$3(startAngle);
for (var i = 0; i <= iteration; i++) {
var angle = startAngle + (step * i);
var x = centerX + (radiusX * Math.cos(angle));
var y = centerY + (radiusY * Math.sin(angle));
LineTo(x, y, pathData);
}
return pathData;
};
const DegToRad$2 = Phaser.Math.DegToRad;
class Arc extends PathBase {
constructor(x, y, radiusX, radiusY, startAngle, endAngle, anticlockwise, pie) {
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (radiusX === undefined) { radiusX = 0; }
if (radiusY === undefined) { radiusY = 0; }
if (startAngle === undefined) { startAngle = 0; }
if (endAngle === undefined) { endAngle = 360; }
if (anticlockwise === undefined) { anticlockwise = false; }
if (pie === undefined) { pie = false; }
super();
this.setCenterPosition(x, y);
this.setRadius(radiusX, radiusY);
this.setAngle(startAngle, endAngle, anticlockwise);
this.setPie(pie);
this.setIterations(32);
}
get x() {
return this._x;
}
set x(value) {
this.dirty = this.dirty || (this._x !== value);
this._x = value;
}
get y() {
return this._y;
}
set y(value) {
this.dirty = this.dirty || (this._y !== value);
this._y = value;
}
setCenterPosition(x, y) {
if (y === undefined) {
y = x;
}
this.x = x;
this.y = y;
return this;
}
get radiusX() {
return this._radiusX;
}
set radiusX(value) {
this.dirty = this.dirty || (this._radiusX !== value);
this._radiusX = value;
}
get radiusY() {
return this._radiusY;
}
set radiusY(value) {
this.dirty = this.dirty || (this._radiusY !== value);
this._radiusY = value;
}
setRadius(radiusX, radiusY) {
if (radiusY === undefined) {
radiusY = radiusX;
}
this.radiusX = radiusX;
this.radiusY = radiusY;
return this;
}
get startAngle() {
return this._startAngle;
}
set startAngle(value) {
this.dirty = this.dirty || (this._startAngle !== value);
this._startAngle = value;
}
get endAngle() {
return this._endAngle;
}
set endAngle(value) {
this.dirty = this.dirty || (this._endAngle !== value);
this._endAngle = value;
}
get anticlockwise() {
return this._anticlockwise;
}
set anticlockwise(value) {
this.dirty = this.dirty || (this._anticlockwise !== value);
this._anticlockwise = value;
}
setAngle(startAngle, endAngle, anticlockwise) {
// startAngle, endAngle in degrees
if (anticlockwise === undefined) {
anticlockwise = false;
}
this.startAngle = startAngle;
this.endAngle = endAngle;
this.anticlockwise = anticlockwise;
return this;
}
get pie() {
return this._pie;
}
set pie(value) {
this.dirty = this.dirty || (this._pie !== value);
this._pie = value;
}
set