phaser3-rex-plugins
Version:
1,628 lines (1,573 loc) • 77.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.rexspinner = factory());
})(this, (function () { 'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {
while (!Object.prototype.hasOwnProperty.call(object, property)) {
object = _getPrototypeOf(object);
if (object === null) break;
}
return object;
}
function _get() {
if (typeof Reflect !== "undefined" && Reflect.get) {
_get = Reflect.get.bind();
} else {
_get = function _get(target, property, receiver) {
var base = _superPropBase(target, property);
if (!base) return;
var desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.get) {
return desc.get.call(arguments.length < 3 ? target : receiver);
}
return desc.value;
};
}
return _get.apply(this, arguments);
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var GetCalcMatrix = Phaser.GameObjects.GetCalcMatrix;
var WebGLRenderer = function WebGLRenderer(renderer, src, camera, parentMatrix) {
src.updateData();
camera.addToRenderList(src);
var pipeline = renderer.pipelines.set(src.pipeline);
var result = GetCalcMatrix(src, camera, parentMatrix);
var calcMatrix = pipeline.calcMatrix.copyFrom(result.calc);
var dx = src._displayOriginX;
var dy = src._displayOriginY;
var alpha = camera.alpha * src.alpha;
renderer.pipelines.preBatch(src);
var shapes = src.geom;
for (var i = 0, cnt = shapes.length; i < cnt; i++) {
shapes[i].webglRender(pipeline, calcMatrix, alpha, dx, dy);
}
renderer.pipelines.postBatch(src);
};
var SetTransform = Phaser.Renderer.Canvas.SetTransform;
var CanvasRenderer = function CanvasRenderer(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;
for (var i = 0, cnt = shapes.length; i < cnt; i++) {
shapes[i].canvasRender(ctx, dx, dy);
}
// Restore the context saved in SetTransform
ctx.restore();
}
};
var Render = {
renderWebGL: WebGLRenderer,
renderCanvas: CanvasRenderer
};
var Clear = function Clear(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;
};
var Shape = Phaser.GameObjects.Shape;
var RemoveItem = Phaser.Utils.Array.Remove;
var BaseShapes = /*#__PURE__*/function (_Shape) {
_inherits(BaseShapes, _Shape);
var _super = _createSuper(BaseShapes);
function BaseShapes(scene, x, y, width, height) {
var _this;
_classCallCheck(this, BaseShapes);
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (width === undefined) {
width = 2;
}
if (height === undefined) {
height = width;
}
_this = _super.call(this, 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();
return _this;
}
_createClass(BaseShapes, [{
key: "width",
get: function get() {
return this._width;
},
set: function set(value) {
this.setSize(value, this._height);
}
}, {
key: "height",
get: function get() {
return this._height;
},
set: function set(value) {
this.setSize(this._width, value);
}
}, {
key: "setDirty",
value: function setDirty(value) {
if (value === undefined) {
value = true;
}
this.dirty = value;
return this;
}
}, {
key: "setSize",
value: function 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;
}
}, {
key: "resize",
value: function resize(width, height) {
this.setSize(width, height);
return this;
}
}, {
key: "fillColor",
get: function get() {
return this._fillColor;
},
set: function set(value) {
this.setFillStyle(value, this._fillAlpha);
}
}, {
key: "fillAlpha",
get: function get() {
return this._fillAlpha;
},
set: function set(value) {
this.setFillStyle(this._fillColor, value);
}
}, {
key: "setFillStyle",
value: function 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;
}
}, {
key: "lineWidth",
get: function get() {
return this._lineWidth;
},
set: function set(value) {
this.setStrokeStyle(value, this._strokeColor, this._strokeAlpha);
}
}, {
key: "strokeColor",
get: function get() {
return this._strokeColor;
},
set: function set(value) {
this.setStrokeStyle(this._lineWidth, value, this._strokeAlpha);
}
}, {
key: "strokeAlpha",
get: function get() {
return this._strokeAlpha;
},
set: function set(value) {
this.setStrokeStyle(this._lineWidth, this._strokeColor, value);
}
}, {
key: "setStrokeStyle",
value: function 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;
}
}, {
key: "updateShapes",
value: function updateShapes() {}
}, {
key: "updateData",
value: function 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;
}
}, {
key: "clear",
value: function clear() {
this.geom.length = 0;
Clear(this.shapes);
return this;
}
}, {
key: "getShape",
value: function getShape(name) {
return this.shapes[name];
}
}, {
key: "getShapes",
value: function getShapes() {
return this.geom;
}
}, {
key: "addShape",
value: function addShape(shape) {
this.geom.push(shape);
var name = shape.name;
if (name) {
this.shapes[name] = shape;
}
this.dirty = true;
return this;
}
}, {
key: "deleteShape",
value: function deleteShape(name) {
var shape = this.getShape(name);
if (shape) {
delete this.shapes[name];
RemoveItem(this.geom, shape);
}
return this;
}
}]);
return BaseShapes;
}(Shape);
Object.assign(BaseShapes.prototype, Render);
var EventEmitterMethods = {
setEventEmitter: function 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: function destroyEventEmitter() {
if (this._eventEmitter && this._privateEE) {
this._eventEmitter.shutdown();
}
return this;
},
getEventEmitter: function getEventEmitter() {
return this._eventEmitter;
},
on: function on() {
if (this._eventEmitter) {
this._eventEmitter.on.apply(this._eventEmitter, arguments);
}
return this;
},
once: function once() {
if (this._eventEmitter) {
this._eventEmitter.once.apply(this._eventEmitter, arguments);
}
return this;
},
off: function off() {
if (this._eventEmitter) {
this._eventEmitter.off.apply(this._eventEmitter, arguments);
}
return this;
},
emit: function emit(event) {
if (this._eventEmitter && event) {
this._eventEmitter.emit.apply(this._eventEmitter, arguments);
}
return this;
},
addListener: function addListener() {
if (this._eventEmitter) {
this._eventEmitter.addListener.apply(this._eventEmitter, arguments);
}
return this;
},
removeListener: function removeListener() {
if (this._eventEmitter) {
this._eventEmitter.removeListener.apply(this._eventEmitter, arguments);
}
return this;
},
removeAllListeners: function removeAllListeners() {
if (this._eventEmitter) {
this._eventEmitter.removeAllListeners.apply(this._eventEmitter, arguments);
}
return this;
},
listenerCount: function listenerCount() {
if (this._eventEmitter) {
return this._eventEmitter.listenerCount.apply(this._eventEmitter, arguments);
}
return 0;
},
listeners: function listeners() {
if (this._eventEmitter) {
return this._eventEmitter.listeners.apply(this._eventEmitter, arguments);
}
return [];
},
eventNames: function eventNames() {
if (this._eventEmitter) {
return this._eventEmitter.eventNames.apply(this._eventEmitter, arguments);
}
return [];
}
};
var SceneClass = Phaser.Scene;
var IsSceneObject = function IsSceneObject(object) {
return object instanceof SceneClass;
};
var GetSceneObject = function GetSceneObject(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;
}
};
var GameClass = Phaser.Game;
var IsGame = function IsGame(object) {
return object instanceof GameClass;
};
var GetGame = function GetGame(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;
}
};
var GetValue$7 = Phaser.Utils.Objects.GetValue;
var ComponentBase = /*#__PURE__*/function () {
function ComponentBase(parent, config) {
_classCallCheck(this, ComponentBase);
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
}
}
_createClass(ComponentBase, [{
key: "shutdown",
value: function 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;
}
}, {
key: "destroy",
value: function destroy(fromScene) {
this.shutdown(fromScene);
}
}, {
key: "onEnvDestroy",
value: function onEnvDestroy() {
this.destroy(true);
}
}, {
key: "onParentDestroy",
value: function onParentDestroy(parent, fromScene) {
this.destroy(fromScene);
}
}, {
key: "setParent",
value: function setParent(parent) {
this.parent = parent; // gameObject, scene, or game
this.scene = GetSceneObject(parent);
this.game = GetGame(parent);
return this;
}
}]);
return ComponentBase;
}();
Object.assign(ComponentBase.prototype, EventEmitterMethods);
var GetValue$6 = Phaser.Utils.Objects.GetValue;
var TickTask = /*#__PURE__*/function (_ComponentBase) {
_inherits(TickTask, _ComponentBase);
var _super = _createSuper(TickTask);
function TickTask(parent, config) {
var _this;
_classCallCheck(this, TickTask);
_this = _super.call(this, parent, config);
_this._isRunning = false;
_this.isPaused = false;
_this.tickingState = false;
_this.setTickingMode(GetValue$6(config, 'tickingMode', 1));
// boot() later
return _this;
}
// override
_createClass(TickTask, [{
key: "boot",
value: function boot() {
if (this.tickingMode === 2 && !this.tickingState) {
this.startTicking();
}
}
// override
}, {
key: "shutdown",
value: function shutdown(fromScene) {
// Already shutdown
if (this.isShutdown) {
return;
}
this.stop();
if (this.tickingState) {
this.stopTicking();
}
_get(_getPrototypeOf(TickTask.prototype), "shutdown", this).call(this, fromScene);
}
}, {
key: "setTickingMode",
value: function setTickingMode(mode) {
if (typeof mode === 'string') {
mode = TICKINGMODE[mode];
}
this.tickingMode = mode;
}
// override
}, {
key: "startTicking",
value: function startTicking() {
this.tickingState = true;
}
// override
}, {
key: "stopTicking",
value: function stopTicking() {
this.tickingState = false;
}
}, {
key: "isRunning",
get: function get() {
return this._isRunning;
},
set: function set(value) {
if (this._isRunning === value) {
return;
}
this._isRunning = value;
if (this.tickingMode === 1 && value != this.tickingState) {
if (value) {
this.startTicking();
} else {
this.stopTicking();
}
}
}
}, {
key: "start",
value: function start() {
this.isPaused = false;
this.isRunning = true;
return this;
}
}, {
key: "pause",
value: function pause() {
// Only can ba paused in running state
if (this.isRunning) {
this.isPaused = true;
this.isRunning = false;
}
return this;
}
}, {
key: "resume",
value: function resume() {
// Only can ba resumed in paused state (paused from running state)
if (this.isPaused) {
this.isRunning = true;
}
return this;
}
}, {
key: "stop",
value: function stop() {
this.isPaused = false;
this.isRunning = false;
return this;
}
}, {
key: "complete",
value: function complete() {
this.isPaused = false;
this.isRunning = false;
this.emit('complete', this.parent, this);
}
}]);
return TickTask;
}(ComponentBase);
var TICKINGMODE = {
'no': 0,
'lazy': 1,
'always': 2
};
var GetValue$5 = Phaser.Utils.Objects.GetValue;
var SceneUpdateTickTask = /*#__PURE__*/function (_TickTask) {
_inherits(SceneUpdateTickTask, _TickTask);
var _super = _createSuper(SceneUpdateTickTask);
function SceneUpdateTickTask(parent, config) {
var _this;
_classCallCheck(this, SceneUpdateTickTask);
_this = _super.call(this, 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);
return _this;
}
_createClass(SceneUpdateTickTask, [{
key: "startTicking",
value: function startTicking() {
_get(_getPrototypeOf(SceneUpdateTickTask.prototype), "startTicking", this).call(this);
if (this.isSceneTicker) {
this.scene.sys.events.on(this.tickEventName, this.update, this);
} else {
this.game.events.on(this.tickEventName, this.update, this);
}
}
}, {
key: "stopTicking",
value: function stopTicking() {
_get(_getPrototypeOf(SceneUpdateTickTask.prototype), "stopTicking", this).call(this);
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) {
//
// }
}]);
return SceneUpdateTickTask;
}(TickTask);
var IsGameUpdateEvent = function IsGameUpdateEvent(eventName) {
return eventName === 'step' || eventName === 'poststep';
};
var GetValue$4 = Phaser.Utils.Objects.GetValue;
var Clamp = Phaser.Math.Clamp;
var Timer = /*#__PURE__*/function () {
function Timer(config) {
_classCallCheck(this, Timer);
this.resetFromJSON(config);
}
_createClass(Timer, [{
key: "resetFromJSON",
value: function 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);
}
}, {
key: "toJSON",
value: function 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
};
}
}, {
key: "destroy",
value: function destroy() {}
}, {
key: "setTimeScale",
value: function setTimeScale(timeScale) {
this.timeScale = timeScale;
return this;
}
}, {
key: "setDelay",
value: function setDelay(delay) {
if (delay === undefined) {
delay = 0;
}
this.delay = delay;
return this;
}
}, {
key: "setDuration",
value: function setDuration(duration) {
this.duration = duration;
return this;
}
}, {
key: "setRepeat",
value: function setRepeat(repeat) {
this.repeat = repeat;
return this;
}
}, {
key: "setRepeatInfinity",
value: function setRepeatInfinity() {
this.repeat = -1;
return this;
}
}, {
key: "setRepeatDelay",
value: function setRepeatDelay(repeatDelay) {
this.repeatDelay = repeatDelay;
return this;
}
}, {
key: "start",
value: function start() {
this.nowTime = this.delay > 0 ? -this.delay : 0;
this.state = this.nowTime >= 0 ? COUNTDOWN : DELAY;
this.repeatCounter = 0;
return this;
}
}, {
key: "stop",
value: function stop() {
this.state = IDLE;
return this;
}
}, {
key: "update",
value: function 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;
}
}
}, {
key: "t",
get: function get() {
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(t, 0, 1);
},
set: function set(value) {
value = Clamp(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++;
}
}
}
}, {
key: "setT",
value: function setT(t) {
this.t = t;
return this;
}
}, {
key: "isIdle",
get: function get() {
return this.state === IDLE;
}
}, {
key: "isDelay",
get: function get() {
return this.state === DELAY;
}
}, {
key: "isCountDown",
get: function get() {
return this.state === COUNTDOWN;
}
}, {
key: "isRunning",
get: function get() {
return this.state === DELAY || this.state === COUNTDOWN;
}
}, {
key: "isDone",
get: function get() {
return this.state === DONE;
}
}, {
key: "isOddIteration",
get: function get() {
return (this.repeatCounter & 1) === 1;
}
}, {
key: "isEvenIteration",
get: function get() {
return (this.repeatCounter & 1) === 0;
}
}]);
return Timer;
}();
var IDLE = 0;
var DELAY = 1;
var COUNTDOWN = 2;
var REPEATDELAY = 3;
var DONE = -1;
var TimerTickTask = /*#__PURE__*/function (_TickTask) {
_inherits(TimerTickTask, _TickTask);
var _super = _createSuper(TimerTickTask);
function TimerTickTask(parent, config) {
var _this;
_classCallCheck(this, TimerTickTask);
_this = _super.call(this, parent, config);
_this.timer = new Timer();
// boot() later
return _this;
}
// override
_createClass(TimerTickTask, [{
key: "shutdown",
value: function shutdown(fromScene) {
// Already shutdown
if (this.isShutdown) {
return;
}
_get(_getPrototypeOf(TimerTickTask.prototype), "shutdown", this).call(this, fromScene);
this.timer.destroy();
this.timer = undefined;
}
}, {
key: "start",
value: function start() {
this.timer.start();
_get(_getPrototypeOf(TimerTickTask.prototype), "start", this).call(this);
return this;
}
}, {
key: "stop",
value: function stop() {
this.timer.stop();
_get(_getPrototypeOf(TimerTickTask.prototype), "stop", this).call(this);
return this;
}
}, {
key: "complete",
value: function complete() {
this.timer.stop();
_get(_getPrototypeOf(TimerTickTask.prototype), "complete", this).call(this);
return this;
}
}]);
return TimerTickTask;
}(SceneUpdateTickTask);
var GetValue$3 = Phaser.Utils.Objects.GetValue;
var GetAdvancedValue = Phaser.Utils.Objects.GetAdvancedValue;
var GetEaseFunction = Phaser.Tweens.Builders.GetEaseFunction;
var EaseValueTaskBase = /*#__PURE__*/function (_TimerTask) {
_inherits(EaseValueTaskBase, _TimerTask);
var _super = _createSuper(EaseValueTaskBase);
function EaseValueTaskBase() {
_classCallCheck(this, EaseValueTaskBase);
return _super.apply(this, arguments);
}
_createClass(EaseValueTaskBase, [{
key: "resetFromJSON",
value: function 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;
}
}, {
key: "setEnable",
value: function setEnable(e) {
if (e == undefined) {
e = true;
}
this.enable = e;
return this;
}
}, {
key: "setTarget",
value: function setTarget(target) {
if (target === undefined) {
target = this.parent;
}
this.target = target;
return this;
}
}, {
key: "setDelay",
value: function setDelay(time) {
this.delay = time;
// Assign `this.timer.setRepeat(repeat)` manually
return this;
}
}, {
key: "setDuration",
value: function setDuration(time) {
this.duration = time;
return this;
}
}, {
key: "setRepeat",
value: function setRepeat(repeat) {
this.repeat = repeat;
// Assign `this.timer.setRepeat(repeat)` manually
return this;
}
}, {
key: "setRepeatDelay",
value: function setRepeatDelay(repeatDelay) {
this.repeatDelay = repeatDelay;
// Assign `this.timer.setRepeatDelay(repeatDelay)` manually
return this;
}
}, {
key: "setEase",
value: function setEase(ease) {
if (ease === undefined) {
ease = 'Linear';
}
this.ease = ease;
this.easeFn = GetEaseFunction(ease);
return this;
}
// Override
}, {
key: "start",
value: function start() {
// Ignore start if timer is running, i.e. in DELAY, o RUN state
if (this.timer.isRunning) {
return this;
}
_get(_getPrototypeOf(EaseValueTaskBase.prototype), "start", this).call(this);
return this;
}
}, {
key: "restart",
value: function restart() {
this.timer.stop();
this.start.apply(this, arguments);
return this;
}
}, {
key: "stop",
value: function stop(toEnd) {
if (toEnd === undefined) {
toEnd = false;
}
_get(_getPrototypeOf(EaseValueTaskBase.prototype), "stop", this).call(this);
if (toEnd) {
this.timer.setT(1);
this.updateGameObject(this.target, this.timer);
this.complete();
}
return this;
}
}, {
key: "update",
value: function update(time, delta) {
if (!this.isRunning || !this.enable || !this.parent.active) {
return this;
}
var target = this.target,
timer = this.timer;
timer.update(time, delta);
// isDelay, isCountDown, isDone
if (!timer.isDelay) {
this.updateGameObject(target, timer);
}
this.emit('update', target, this);
if (timer.isDone) {
this.complete();
}
return this;
}
// Override
}, {
key: "updateGameObject",
value: function updateGameObject(target, timer) {}
}]);
return EaseValueTaskBase;
}(TimerTickTask);
var GetValue$2 = Phaser.Utils.Objects.GetValue;
var Linear$1 = Phaser.Math.Linear;
var EaseValueTask = /*#__PURE__*/function (_EaseValueTaskBase) {
_inherits(EaseValueTask, _EaseValueTaskBase);
var _super = _createSuper(EaseValueTask);
function EaseValueTask(gameObject, config) {
var _this;
_classCallCheck(this, EaseValueTask);
_this = _super.call(this, gameObject, config);
// this.parent = gameObject;
// this.timer
_this.resetFromJSON();
_this.boot();
return _this;
}
_createClass(EaseValueTask, [{
key: "start",
value: function 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;
_get(_getPrototypeOf(EaseValueTask.prototype), "start", this).call(this);
return this;
}
}, {
key: "updateGameObject",
value: function updateGameObject(target, timer) {
var t = timer.t;
t = this.easeFn(t);
target[this.propertyKey] = Linear$1(this.fromValue, this.toValue, t);
}
}]);
return EaseValueTask;
}(EaseValueTaskBase);
var Start = function Start(duration) {
if (!this.easeValueTask) {
this.easeValueTask = new EaseValueTask(this, {
eventEmitter: null
});
}
if (duration !== undefined) {
this.duration = duration;
this.easeValueTask.stop(); // Will restart with new duration
}
// Won't restart if easeValueTask is running
if (this.easeValueTask.isRunning) {
return this;
}
// Start easeValueTask
this.easeValueTask.restart({
key: 'value',
from: 0,
to: 1,
duration: this.duration,
ease: this.ease,
repeat: -1,
// -1: infinity
delay: this.delay,
repeatDelay: this.repeatDelay
});
this.setDirty();
return this;
};
var Stop = function Stop() {
if (!this.easeValueTask) {
return this;
}
this.easeValueTask.stop();
this.setDirty();
return this;
};
var Pause = function Pause() {
if (!this.easeValueTask) {
return this;
}
this.easeValueTask.pause();
this.setDirty();
return this;
};
var Resume = function Resume() {
if (!this.easeValueTask) {
return this;
}
this.easeValueTask.pause();
this.setDirty();
return this;
};
var EaseValueMethods = {
start: Start,
stop: Stop,
pause: Pause,
resume: Resume
};
var GetValue$1 = Phaser.Utils.Objects.GetValue;
var Base = /*#__PURE__*/function (_BaseShapes) {
_inherits(Base, _BaseShapes);
var _super = _createSuper(Base);
function Base(scene, config) {
var _this;
_classCallCheck(this, Base);
var x = GetValue$1(config, 'x', 0);
var y = GetValue$1(config, 'y', 0);
var width = GetValue$1(config, 'width', 64);
var height = GetValue$1(config, 'height', 64);
_this = _super.call(this, scene, x, y, width, height);
_this.setDuration(GetValue$1(config, 'duration', 1000));
_this.setEase(GetValue$1(config, 'ease', 'Linear'));
_this.setDelay(GetValue$1(config, 'delay', 0));
_this.setRepeatDelay(GetValue$1(config, 'repeatDelay', 0));
var color = GetValue$1(config, 'color', 0xffffff);
var start = GetValue$1(config, 'start', true);
_this.buildShapes(config);
_this.setColor(color);
_this.setValue(0);
if (start) {
_this.start();
}
return _this;
}
_createClass(Base, [{
key: "buildShapes",
value: function buildShapes() {}
}, {
key: "centerX",
get: function get() {
return this.width / 2;
}
}, {
key: "centerY",
get: function get() {
return this.height / 2;
}
}, {
key: "radius",
get: function get() {
return Math.min(this.centerX, this.centerY);
}
}, {
key: "color",
get: function get() {
return this._color;
},
set: function set(value) {
this.isColorChanged = this.isColorChanged || this._color !== value;
this.dirty = this.dirty || this.isColorChanged;
this._color = value;
this.setShapesColor(value);
}
}, {
key: "setColor",
value: function setColor(color) {
this.color = color;
return this;
}
}, {
key: "setShapesColor",
value: function setShapesColor(color) {}
}, {
key: "value",
get: function get() {
return this._value;
},
set: function set(value) {
value = Phaser.Math.Clamp(value, 0, 1);
this.dirty = this.dirty || this._value != value;
this._value = value;
}
}, {
key: "setValue",
value: function setValue(value) {
this.value = value;
return this;
}
}, {
key: "setDuration",
value: function setDuration(duration) {
this.duration = duration;
return this;
}
}, {
key: "setDelay",
value: function setDelay(delay) {
this.delay = delay;
return this;
}
}, {
key: "setRepeatDelay",
value: function setRepeatDelay(repeatDelay) {
this.repeatDelay = repeatDelay;
return this;
}
}, {
key: "setEase",
value: function setEase(ease) {
this.ease = ease;
return this;
}
}, {
key: "isRunning",
get: function get() {
return this.tweenTask ? this.tweenTask.isRunning : false;
}
}]);
return Base;
}(BaseShapes);
Object.assign(Base.prototype, EaseValueMethods);
var FillStyle = function FillStyle(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 LineStyle(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
};
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
// Source object
// The key as a string, or an array of keys, i.e. 'banner', or 'banner.hideBanner'
// The default value to use if the key doesn't exist
/**
* Retrieves a value from an object.
*
* @function Phaser.Utils.Objects.GetValue
* @since 3.0.0
*
* @param {object} source - The object to retrieve the value from.
* @param {string} key - The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (`.`) - `banner.hideBanner` would return the value of the `hideBanner` property from the object stored in the `banner` property of the `source` object.
* @param {*} defaultValue - The value to return if the `key` isn't found in the `source` object.
*
* @return {*} The value of the requested key.
*/
var GetValue = function GetValue(source, key, defaultValue) {
if (!source || typeof source === 'number') {
return defaultValue;
} else if (source.hasOwnProperty(key)) {
return source[key];
} else if (key.indexOf('.') !== -1) {
var keys = key.split('.');
var parent = source;
var value = defaultValue;
// Use for loop here so we can break early
for (var i = 0; i < keys.length; i++) {
if (parent.hasOwnProperty(keys[i])) {
// Yes it has a key property, let's carry on down
value = parent[keys[i]];
parent = parent[keys[i]];
} else {
// Can't go any further, so reset to default
value = defaultValue;
break;
}
}
return value;
} else {
return defaultValue;
}
};
var DataMethods = {
enableData: function enableData() {
if (this.data === undefined) {
this.data = {};
}
return this;
},
setData: function 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: function getData(key, defaultValue) {
this.enableData();
return key === undefined ? this.data : GetValue(this.data, key, defaultValue);
},
incData: function incData(key, inc, defaultValue) {
if (defaultValue === undefined) {
defaultValue = 0;
}
this.enableData();
this.setData(key, this.getData(key, defaultValue) + inc);
return this;
},
mulData: function mulData(key, mul, defaultValue) {
if (defaultValue === undefined) {
defaultValue = 0;
}
this.enableData();
this.setData(key, this.getData(key, defaultValue) * mul);
return this;
},
clearData: function clearData() {
if (this.data) {
Clear(this.data);
}
return this;
}
};
var BaseGeom = /*#__PURE__*/function () {
function BaseGeom() {
_classCallCheck(this, BaseGeom);
this.name = undefined;
this.dirty = 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;
}
_createClass(BaseGeom, [{
key: "setName",
value: function setName(name) {
this.name = name;
return this;
}
}, {
key: "reset",
value: function reset() {
this.fillStyle().lineStyle();
return this;
}
}, {
key: "webglRender",
value: function webglRender(pipeline, calcMatrix, alpha, dx, dy) {}
}, {
key: "canvasRender",
value: function canvasRender(ctx, dx, dy) {}
}, {
key: "updateData",
value: function updateData() {
this.dirty = false;
}
}]);
return BaseGeom;
}();
Object.assign(BaseGeom.prototype, StyleMethods, DataMethods);
/*
src: {
fillColor,
fillAlpha,
pathData,
pathIndexes // Earcut(pathData)
}
*/
var Utils$1 = Phaser.Renderer.WebGL.Utils;
var FillPathWebGL = function FillPathWebGL(pipeline, calcMatrix, src, alpha, dx, dy) {
var fillTintColor = Utils$1.getTintAppendFloatAlpha(src.fillColor, src.fillAlpha * alpha);
var path = src.pathData;
var pathIndexes = src.pathIndexes;
for (var i = 0; i < pathIndexes.length; i += 3) {
var p0 = pathIndexes[i] * 2;
var p1 = pathIndexes[i + 1] * 2;
var p2 = pathIndexes[i + 2] * 2;
var x0 = path[p0 + 0] - dx;
var y0 = path[p0 + 1] - dy;
var x1 = path[p1 + 0] - dx;
var y1 = path[p1 + 1] - dy;
var x2 = path[p2 + 0] - dx;
var y2 = path[p2 + 1] - dy;
var tx0 = calcMatrix.getX(x0, y0);
var ty0 = calcMatrix.getY(x0, y0);
var tx1 = calcMatrix.getX(x1, y1);
var ty1 = calcMatrix.getY(x1, y1);
var tx2 = calcMatrix.getX(x2, y2);
var ty2 = calcMatrix.getY(x2, y2);
pipeline.batchTri(src, tx0, ty0, tx1, ty1, tx2, ty2, 0, 0, 1, 1, fillTintColor, fillTintColor, fillTintColo