phaser3-rex-plugins
Version:
1,656 lines (1,606 loc) • 144 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.rexdynamictext = 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 _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
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 set(target, property, value, receiver) {
if (typeof Reflect !== "undefined" && Reflect.set) {
set = Reflect.set;
} else {
set = function set(target, property, value, receiver) {
var base = _superPropBase(target, property);
var desc;
if (base) {
desc = Object.getOwnPropertyDescriptor(base, property);
if (desc.set) {
desc.set.call(receiver, value);
return true;
} else if (!desc.writable) {
return false;
}
}
desc = Object.getOwnPropertyDescriptor(receiver, property);
if (desc) {
if (!desc.writable) {
return false;
}
desc.value = value;
Object.defineProperty(receiver, property, desc);
} else {
_defineProperty(receiver, property, value);
}
return true;
};
}
return set(target, property, value, receiver);
}
function _set(target, property, value, receiver, isStrict) {
var s = set(target, property, value, receiver || target);
if (!s && isStrict) {
throw new TypeError('failed to set property');
}
return value;
}
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);
}
// copy from Phaser.GameObjects.Text
var Utils = Phaser.Renderer.WebGL.Utils;
var WebGLRenderer = function WebGLRenderer(renderer, src, camera, parentMatrix) {
if (src.dirty) {
src.updateTexture();
src.dirty = false;
}
if (src.width === 0 || src.height === 0) {
return;
}
camera.addToRenderList(src);
var frame = src.frame;
var width = frame.width;
var height = frame.height;
var getTint = Utils.getTintAppendFloatAlpha;
var pipeline = renderer.pipelines.set(src.pipeline, src);
var textureUnit = pipeline.setTexture2D(frame.glTexture, src);
renderer.pipelines.preBatch(src);
pipeline.batchTexture(src, frame.glTexture, width, height, src.x, src.y, width / src.resolution, height / src.resolution, src.scaleX, src.scaleY, src.rotation, src.flipX, src.flipY, src.scrollFactorX, src.scrollFactorY, src.displayOriginX, src.displayOriginY, 0, 0, width, height, getTint(src.tintTopLeft, camera.alpha * src._alphaTL), getTint(src.tintTopRight, camera.alpha * src._alphaTR), getTint(src.tintBottomLeft, camera.alpha * src._alphaBL), getTint(src.tintBottomRight, camera.alpha * src._alphaBR), src.tintFill, 0, 0, camera, parentMatrix, false, textureUnit);
renderer.pipelines.postBatch(src);
};
// copy from Phaser.GameObjects.Text
var CanvasRenderer = function CanvasRenderer(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
};
var Color = Phaser.Display.Color;
var CanvasMethods = {
clear: function clear() {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.dirty = true;
return this;
},
fill: function fill(color) {
this.context.fillStyle = color;
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.dirty = true;
return this;
},
drawFrame: function 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: function getDataURL(type, encoderOptions) {
return this.canvas.toDataURL(type, encoderOptions);
},
getPixel: function 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: function 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 CopyCanvasToTexture(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: function updateTexture(callback, scope) {
if (callback) {
if (scope) {
callback.call(scope, this.canvas, this.context);
} else {
callback(this.canvas, this.context);
}
}
if (this.canvas.width !== this.frame.width || this.canvas.height !== this.frame.height) {
this.frame.setSize(this.canvas.width, this.canvas.height);
}
if (this.renderer && this.renderer.gl) {
this.frame.source.glTexture = this.renderer.canvasToTexture(this.canvas, this.frame.source.glTexture, true);
this.frame.glTexture = this.frame.source.glTexture;
}
this.dirty = false;
var input = this.input;
if (input && !input.customHitArea) {
input.hitArea.width = this.width;
input.hitArea.height = this.height;
}
return this;
},
generateTexture: function 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: function 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;
}
};
var MinVersion = 60;
var IsChecked = false;
var CheckP3Version = function CheckP3Version(minVersion) {
if (IsChecked) {
return;
}
if (minVersion === undefined) {
minVersion = MinVersion;
}
var currentVersion = parseInt(Phaser.VERSION.match(/\.(\d+)\./)[1]);
if (currentVersion < minVersion) {
console.error("Minimum supported version : 3.".concat(minVersion));
}
IsChecked = true;
};
CheckP3Version();
var CanvasPool = Phaser.Display.Canvas.CanvasPool;
var GameObject$1 = Phaser.GameObjects.GameObject;
var Canvas = /*#__PURE__*/function (_GameObject) {
_inherits(Canvas, _GameObject);
var _super = _createSuper(Canvas);
function Canvas(scene, x, y, width, height) {
var _this;
_classCallCheck(this, Canvas);
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (width === undefined) {
width = 1;
}
if (height === undefined) {
height = 1;
}
_this = _super.call(this, scene, 'rexCanvas');
_this.renderer = scene.sys.game.renderer;
_this.resolution = 1;
_this._width = width;
_this._height = height;
width = Math.max(Math.ceil(width * _this.resolution), 1);
height = Math.max(Math.ceil(height * _this.resolution), 1);
_this.canvas = CanvasPool.create(_assertThisInitialized(_this), width, height);
_this.context = _this.canvas.getContext('2d', {
willReadFrequently: true
});
_this.dirty = false;
_this.setPosition(x, y);
_this.setOrigin(0.5, 0.5);
_this.initPipeline();
_this.initPostPipeline(true);
_this._crop = _this.resetCropObject();
// Create a Texture for this Text object
_this.texture = scene.sys.textures.addCanvas(null, _this.canvas, true);
// 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;
return _this;
}
_createClass(Canvas, [{
key: "preDestroy",
value: function preDestroy() {
CanvasPool.remove(this.canvas);
this.texture.destroy();
this.canvas = null;
this.context = null;
}
}, {
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: "setCanvasSize",
value: function 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.dirty = true;
return this;
}
// setSize might be override
}, {
key: "setSize",
value: function setSize(width, height) {
this.setCanvasSize(width, height);
return this;
}
}, {
key: "displayWidth",
get: function get() {
return this.scaleX * this._width;
},
set: function set(value) {
this.scaleX = value / this._width;
}
}, {
key: "displayHeight",
get: function get() {
return this.scaleY * this._height;
},
set: function set(value) {
this.scaleY = value / this._height;
}
}, {
key: "setDisplaySize",
value: function setDisplaySize(width, height) {
this.displayWidth = width;
this.displayHeight = height;
return this;
}
}, {
key: "getCanvas",
value: function getCanvas(readOnly) {
if (!readOnly) {
this.dirty = true;
}
return this.canvas;
}
}, {
key: "getContext",
value: function getContext(readOnly) {
if (!readOnly) {
this.dirty = true;
}
return this.context;
}
}, {
key: "needRedraw",
value: function needRedraw() {
this.dirty = true;
return this;
}
}, {
key: "resize",
value: function resize(width, height) {
this.setSize(width, height);
return this;
}
}]);
return Canvas;
}(GameObject$1);
var Components = Phaser.GameObjects.Components;
Phaser.Class.mixin(Canvas, [Components.Alpha, Components.BlendMode, Components.Crop, Components.Depth, Components.Flip, Components.GetBounds, Components.Mask, Components.Origin, Components.Pipeline, Components.PostPipeline, Components.ScrollFactor, Components.Tint, Components.Transform, Components.Visible, Render, CanvasMethods, TextureMethods]);
var GetValue$a = Phaser.Utils.Objects.GetValue;
var GetPadding$1 = function GetPadding(padding, key) {
if (key === undefined) {
return padding;
}
return padding[key];
};
var SetPadding$1 = function SetPadding(padding, key, value) {
if (padding === undefined) {
padding = {};
}
if (key === undefined) {
key = 0;
}
var keyType = _typeof(key);
if (keyType === 'string') {
padding[key] = value;
} else if (keyType === 'number') {
padding.left = key;
padding.right = key;
padding.top = key;
padding.bottom = key;
} else {
padding.left = GetValue$a(key, 'left', 0);
padding.right = GetValue$a(key, 'right', 0);
padding.top = GetValue$a(key, 'top', 0);
padding.bottom = GetValue$a(key, 'bottom', 0);
}
return padding;
};
/**
* @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$9 = 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 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 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$9(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 Base = /*#__PURE__*/function () {
function Base(parent, type) {
_classCallCheck(this, Base);
this.setParent(parent);
this.type = type;
this.renderable = false;
this.reset().setActive();
}
_createClass(Base, [{
key: "destroy",
value: function destroy() {
this.parent.removeChild(this);
}
}, {
key: "setParent",
value: function setParent(parent) {
this.parent = parent;
return this;
}
}, {
key: "scene",
get: function get() {
return this.parent.scene;
}
}, {
key: "canvas",
get: function get() {
return this.parent ? this.parent.canvas : null;
}
}, {
key: "context",
get: function get() {
return this.parent ? this.parent.context : null;
}
}, {
key: "setDirty",
value: function setDirty(dirty) {
if (dirty && this.parent) {
this.parent.dirty = true;
}
return this;
}
}, {
key: "active",
get: function get() {
return this._active;
},
set: function set(value) {
this.setDirty(this._active != value);
this._active = value;
}
}, {
key: "setActive",
value: function setActive(active) {
if (active === undefined) {
active = true;
}
this.active = active;
return this;
}
}, {
key: "modifyPorperties",
value: function modifyPorperties(o) {
return this;
}
// Override
}, {
key: "onFree",
value: function onFree() {
this.reset().setParent();
}
// Override
}, {
key: "reset",
value: function reset() {
return this;
}
// Override
}, {
key: "render",
value: function render() {}
// Override
}, {
key: "contains",
value: function contains(x, y) {
return false;
}
}]);
return Base;
}();
Object.assign(Base.prototype, DataMethods);
var RenderMethods = {
// Override
renderContent: function renderContent() {},
// Override
render: function render() {
if (!this.willRender) {
return this;
}
var context = this.context;
context.save();
context.globalAlpha = this.alpha;
if (this.toLocalPosition) {
var x = this.drawX,
y = this.drawY;
if (this.autoRound) {
x = Math.round(x);
y = Math.round(y);
}
context.translate(x, y);
context.scale(this.scaleX, this.scaleY);
context.rotate(this.rotation);
}
if (this.drawBelowCallback) {
this.drawBelowCallback(this);
}
this.renderContent();
if (this.drawAboveCallback) {
this.drawAboveCallback(this);
}
context.restore();
return this;
}
};
var RotateAround$1 = Phaser.Math.RotateAround;
var CanvasPositionToBobPosition = function CanvasPositionToBobPosition(canvasX, canvasY, bob, out) {
if (out === undefined) {
out = {};
} else if (out === true) {
if (globPoint$1 === undefined) {
globPoint$1 = {};
}
out = globPoint$1;
}
out.x = (canvasX - bob.drawX) / bob.scaleX;
out.y = (canvasY - bob.drawY) / bob.scaleY;
if (bob.rotation !== 0) {
RotateAround$1(out, 0, 0, -bob.rotation);
}
return out;
};
var globPoint$1;
var Rectangle = Phaser.Geom.Rectangle;
var Contains = function Contains(canvasX, canvasY) {
if (this.width === 0 || this.height === 0) {
return false;
}
var bobPosition = CanvasPositionToBobPosition(canvasX, canvasY, this, true);
return GetBobBounds(this).contains(bobPosition.x, bobPosition.y);
};
var GetBobBounds = function GetBobBounds(bob) {
if (bobBounds === undefined) {
bobBounds = new Rectangle();
}
var x = bob.drawTLX,
y = bob.drawTLY;
bobBounds.setTo(x, y, bob.drawTRX - x, bob.drawBLY - y);
return bobBounds;
};
var bobBounds;
var RotateAround = Phaser.Math.RotateAround;
var BobPositionToCanvasPosition = function BobPositionToCanvasPosition(bob, bobX, bobY, out) {
if (out === undefined) {
out = {};
} else if (out === true) {
if (globPoint === undefined) {
globPoint = {};
}
out = globPoint;
}
out.x = bobX;
out.y = bobY;
if (bob.rotation !== 0) {
RotateAround(out, 0, 0, bob.rotation);
}
out.x = out.x * bob.scaleX + bob.drawX;
out.y = out.y * bob.scaleY + bob.drawY;
return out;
};
var globPoint;
var TransformMatrix = Phaser.GameObjects.Components.TransformMatrix;
var GameObjectLocalXYToWorldXY = function GameObjectLocalXYToWorldXY(gameObject, localX, localY, out) {
if (out === undefined) {
out = {};
} else if (out === true) {
out = globOut;
}
var px = localX - gameObject.width * gameObject.originX;
var py = localY - gameObject.height * gameObject.originY;
if (tempMatrix === undefined) {
tempMatrix = new TransformMatrix();
parentMatrix = new TransformMatrix();
}
if (gameObject.parentContainer) {
gameObject.getWorldTransformMatrix(tempMatrix, parentMatrix);
} else {
tempMatrix.applyITRS(gameObject.x, gameObject.y, gameObject.rotation, gameObject.scaleX, gameObject.scaleY);
}
tempMatrix.transformPoint(px, py, out);
return out;
};
var tempMatrix, parentMatrix;
var globOut = {};
var BobPositionToWorldPosition = function BobPositionToWorldPosition(dynamicText, bob, bobX, bobY, out) {
var localXY = BobPositionToCanvasPosition(bob, bobX, bobY, true);
var worldXY = GameObjectLocalXYToWorldXY(dynamicText, localXY.x, localXY.y, out);
return worldXY;
};
var GetBobWorldPosition = function GetBobWorldPosition(dynamicText, bob, offsetX, offsetY, out) {
if (typeof offsetX !== 'number') {
out = offsetX;
offsetX = 0;
offsetY = 0;
}
var bobX = bob.drawCenterX + offsetX;
var bobY = bob.drawCenterY + offsetY;
return BobPositionToWorldPosition(dynamicText, bob, bobX, bobY, out);
};
var GetWorldPosition = function GetWorldPosition(offsetX, offsetY, out) {
return GetBobWorldPosition(this.parent, this, offsetX, offsetY, out);
};
var Methods$1 = {
contains: Contains,
getWorldPosition: GetWorldPosition
};
Object.assign(Methods$1, RenderMethods);
var DegToRad$1 = Phaser.Math.DegToRad;
var RadToDeg = Phaser.Math.RadToDeg;
var GetValue$8 = Phaser.Utils.Objects.GetValue;
var RenderBase = /*#__PURE__*/function (_Base) {
_inherits(RenderBase, _Base);
var _super = _createSuper(RenderBase);
function RenderBase(parent, type) {
var _this;
_classCallCheck(this, RenderBase);
_this = _super.call(this, parent, type);
_this.renderable = true;
_this.scrollFactorX = 1;
_this.scrollFactorY = 1;
_this.toLocalPosition = true;
_this.originX = 0;
_this.offsetX = 0; // Override
_this.offsetY = 0; // Override
return _this;
}
_createClass(RenderBase, [{
key: "visible",
get: function get() {
return this._visible;
},
set: function set(value) {
this.setDirty(this._visible != value);
this._visible = value;
}
}, {
key: "setVisible",
value: function setVisible(visible) {
if (visible === undefined) {
visible = true;
}
this.visible = visible;
return this;
}
}, {
key: "alpha",
get: function get() {
return this._alpha;
},
set: function set(value) {
this.setDirty(this._alpha != value);
this._alpha = value;
}
}, {
key: "setAlpha",
value: function setAlpha(alpha) {
this.alpha = alpha;
return this;
}
}, {
key: "x",
get: function get() {
return this._x;
},
set: function set(value) {
this.setDirty(this._x != value);
this._x = value;
}
}, {
key: "setX",
value: function setX(x) {
this.x = x;
return this;
}
}, {
key: "y",
get: function get() {
return this._y;
},
set: function set(value) {
this.setDirty(this._y != value);
this._y = value;
}
}, {
key: "setY",
value: function setY(y) {
this.y = y;
return this;
}
}, {
key: "setPosition",
value: function setPosition(x, y) {
this.x = x;
this.y = y;
return this;
}
}, {
key: "setInitialPosition",
value: function setInitialPosition(x, y) {
this.x0 = x;
this.y0 = y;
return this;
}
}, {
key: "setScrollFactorX",
value: function setScrollFactorX(x) {
this.scrollFactorX = x;
return this;
}
}, {
key: "setScrollFactorY",
value: function setScrollFactorY(y) {
this.scrollFactorY = y;
return this;
}
}, {
key: "setScrollFactor",
value: function setScrollFactor(x, y) {
if (y === undefined) {
y = x;
}
this.scrollFactorX = x;
this.scrollFactorY = y;
return this;
}
}, {
key: "rotation",
get: function get() {
return this._rotation;
},
set: function set(value) {
this.setDirty(this._rotation != value);
this._rotation = value;
}
}, {
key: "setRotation",
value: function setRotation(rotation) {
this.rotation = rotation;
return this;
}
}, {
key: "angle",
get: function get() {
return RadToDeg(this._rotation);
},
set: function set(value) {
this.rotation = DegToRad$1(value);
}
}, {
key: "setAngle",
value: function setAngle(angle) {
this.angle = angle;
return this;
}
}, {
key: "scaleX",
get: function get() {
return this._scaleX;
},
set: function set(value) {
this.setDirty(this._scaleX !== value);
this._scaleX = value;
}
}, {
key: "setScaleX",
value: function setScaleX(scaleX) {
this.scaleX = scaleX;
return this;
}
// Override
}, {
key: "width",
get: function get() {
return 0;
}
// Override
,
set: function set(value) {}
}, {
key: "setWidth",
value: function setWidth(width, keepAspectRatio) {
if (keepAspectRatio === undefined) {
keepAspectRatio = false;
}
this.width = width;
if (keepAspectRatio) {
this.scaleY = this.scaleX;
}
return this;
}
}, {
key: "leftSpace",
get: function get() {
return this._leftSpace;
},
set: function set(value) {
this.setDirty(this._leftSpace !== value);
this._leftSpace = value;
}
}, {
key: "setLeftSpace",
value: function setLeftSpace(value) {
this.leftSpace = value;
return this;
}
}, {
key: "rightSpace",
get: function get() {
return this._rightSpace;
},
set: function set(value) {
this.setDirty(this._rightSpace !== value);
this._rightSpace = value;
}
}, {
key: "setRightSpace",
value: function setRightSpace(value) {
this.rightSpace = value;
return this;
}
}, {
key: "outerWidth",
get: function get() {
return this.width + this.leftSpace + this.rightSpace;
}
}, {
key: "scaleY",
get: function get() {
return this._scaleY;
},
set: function set(value) {
this.setDirty(this._scaleY !== value);
this._scaleY = value;
}
}, {
key: "setScaleY",
value: function setScaleY(scaleY) {
this.scaleY = scaleY;
return this;
}
// Override
}, {
key: "height",
get: function get() {
return 0;
}
// Override
,
set: function set(value) {}
}, {
key: "setHeight",
value: function setHeight(height, keepAspectRatio) {
if (keepAspectRatio === undefined) {
keepAspectRatio = false;
}
this.height = height;
if (keepAspectRatio) {
this.scaleX = this.scaleY;
}
return this;
}
}, {
key: "setScale",
value: function setScale(scaleX, scaleY) {
if (scaleY === undefined) {
scaleY = scaleX;
}
this.scaleX = scaleX;
this.scaleY = scaleY;
return this;
}
}, {
key: "setOrigin",
value: function setOrigin(x) {
this.originX = x;
return this;
}
}, {
key: "setAlign",
value: function setAlign(align) {
this.align = align;
return this;
}
}, {
key: "modifyPorperties",
value: function modifyPorperties(o) {
if (!o) {
return this;
}
if (o.hasOwnProperty('x')) {
this.setX(o.x);
}
if (o.hasOwnProperty('y')) {
this.setY(o.y);
}
if (o.hasOwnProperty('rotation')) {
this.setRotation(o.rotation);
} else if (o.hasOwnProperty('angle')) {
this.setAngle(o.angle);
}
if (o.hasOwnProperty('alpha')) {
this.setAlpha(o.alpha);
}
// ScaleX, ScaleY
var width = GetValue$8(o, 'width', undefined);
var height = GetValue$8(o, 'height', undefined);
var scaleX = GetValue$8(o, 'scaleX', undefined);
var scaleY = GetValue$8(o, 'scaleY', undefined);
if (width !== undefined) {
if (height === undefined && scaleY === undefined) {
this.setWidth(width, true);
} else {
this.setWidth(width);
}
} else if (scaleX !== undefined) {
this.setScaleX(scaleX);
}
if (height !== undefined) {
if (width === undefined && scaleX === undefined) {
this.setHeight(height, true);
} else {
this.setHeight(height);
}
} else if (scaleY !== undefined) {
this.setScaleY(scaleY);
}
if (o.hasOwnProperty('leftSpace')) {
this.setLeftSpace(o.leftSpace);
}
if (o.hasOwnProperty('rightSpace')) {
this.setRightSpace(o.rightSpace);
}
if (o.hasOwnProperty('align')) {
this.setAlign(o.align);
}
return this;
}
}, {
key: "setDrawBelowCallback",
value: function setDrawBelowCallback(callback) {
this.drawBelowCallback = callback;
return this;
}
}, {
key: "setDrawAboveCallback",
value: function setDrawAboveCallback(callback) {
this.drawAboveCallback = callback;
return this;
}
}, {
key: "reset",
value: function reset() {
this.setVisible().setAlpha(1).setPosition(0, 0).setRotation(0).setScale(1, 1).setLeftSpace(0).setRightSpace(0).setOrigin(0).setAlign().setDrawBelowCallback().setDrawAboveCallback();
return this;
}
// Override
}, {
key: "willRender",
get: function get() {
return this.visible && this.alpha > 0;
}
}, {
key: "drawX",
get: function get() {
var x = this.x + this.leftSpace + this.offsetX - this.originX * this.width;
return this.parent._textOX * this.scrollFactorX + x;
}
}, {
key: "drawY",
get: function get() {
var y = this.y + this.offsetY;
return this.parent._textOY * this.scrollFactorY + y;
}
// Override
}, {
key: "drawTLX",
get: function get() {
return 0;
}
}, {
key: "drawTLY",
get: function get() {
return 0;
}
}, {
key: "drawBLX",
get: function get() {
return 0;
}
}, {
key: "drawBLY",
get: function get() {
return 0;
}
}, {
key: "drawTRX",
get: function get() {
return 0;
}
}, {
key: "drawTRY",
get: function get() {
return 0;
}
}, {
key: "drawBRX",
get: function get() {
return 0;
}
}, {
key: "drawBRY",
get: function get() {
return 0;
}
}, {
key: "drawCenterX",
get: function get() {
return (this.drawTRX + this.drawTLX) / 2;
}
}, {
key: "drawCenterY",
get: function get() {
return (this.drawBLY + this.drawTLY) / 2;
}
}]);
return RenderBase;
}(Base);
Object.assign(RenderBase.prototype, Methods$1);
var Pad = Phaser.Utils.String.Pad;
var GetStyle = function GetStyle(style, canvas, context) {
if (style == null) {
return style;
}
switch (_typeof(style)) {
case 'string':
return style;
case 'number':
return "#".concat(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(".concat(style.r, ",").concat(style.g, ",").concat(style.b, ",").concat(style.a, ")");
} else {
// rgb
return "rgb(".concat(style.r, ",").concat(style.g, ",").concat(style.b, ")");
}
} else if (style.hasOwnProperty('h')) {
if (style.hasOwnProperty('a')) {
// hsla
return "hsla(".concat(style.h, ",").concat(style.s, ",").concat(style.l, ",").concat(style.a, ")");
} else {
// hsl
return "hsl(".concat(style.h, ",").concat(style.s, ",").concat(style.l, ")");
}
} else {
return style; // Not a valid input
}
default:
return style;
}
};
var GetProperty = function GetProperty(name, config, defaultConfig) {
if (config.hasOwnProperty(name)) {
return config[name];
} else {
return defaultConfig[name];
}
};
var GetValue$7 = Phaser.Utils.Objects.GetValue;
var RoundRectangle = /*#__PURE__*/function () {
function RoundRectangle(x, y, width, height, radiusConfig) {
_classCallCheck(this, RoundRectangle);
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = x;
}
if (width === undefined) {
width = 0;
}
if (height === undefined) {
height = 0;
}
if (radiusConfig === undefined) {
radiusConfig = 0;
}
this.cornerRadius = {};
this._width = 0;
this._height = 0;
this.setTo(x, y, width, height, radiusConfig);
}
_createClass(RoundRectangle, [{
key: "setTo",
value: function setTo(x, y, width, height, radiusConfig) {
this.setPosition(x, y);
this.setRadius(radiusConfig);
this.setSize(width, height);
return this;
}
}, {
key: "setPosition",
value: function setPosition(x, y) {
this.x = x;
this.y = y;
return this;
}
}, {
key: "setRadius",
value: function setRadius(value) {
if (value === undefined) {
value = 0;
}
this.radius = value;
return this;
}
}, {
key: "setSize",
value: function setSize(width, height) {
this.width = width;
this.height = height;
return this;
}
}, {
key: "minWidth",
get: function get() {
var radius = this.cornerRadius;
return Math.max(radius.tl.x + radius.tr.x, radius.bl.x + radius.br.x);
}
}, {
key: "minHeight",
get: function get() {
var radius = this.cornerRadius;
return Math.max(radius.tl.y + radius.bl.y, radius.tr.y + radius.br.y);
}
}, {
key: "width",
get: function get() {
return this._width;
},
set: function set(value) {
if (value == null) {
value = 0;
}
this._width = Math.max(value, this.minWidth);
}
}, {
key: "height",
get: function get() {
return this._height;
},
set: function set(value) {
if (value == null) {
value = 0;
}
this._height = Math.max(value, this.minHeight);
}
}, {
key: "radius",
get: function get() {
var radius = this.cornerRadius;
return Math.max(radius.tl.x, radius.tl.y, radius.tr.x, radius.tr.y, radius.bl.x, radius.bl.y, radius.br.x, radius.br.y);
},
set: function set(value) {
var defaultRadiusX, defaultRadiusY;
if (typeof value === 'number') {
defaultRadiusX = value;
defaultRadiusY = value;
} else {
defaultRadiusX = GetValue$7(value, 'x', 0);
defaultRadiusY = GetValue$7(value, 'y', 0);
}
var radius = this.cornerRadius;
radius.tl = GetRadius(GetValue$7(value, 'tl', undefined), defaultRadiusX, defaultRadiusY);
radius.tr = GetRadius(GetValue$7(value, 'tr', undefined), defaultRadiusX, defaultRadiusY);
radius.bl = GetRadius(GetValue$7(value, 'bl', undefined), defaultRadiusX, defaultRadiusY);
radius.br = GetRadius(GetValue$7(value, 'br', undefined), defaultRadiusX, defaultRadiusY);
}
}, {
key: "radiusTL",
get: function get() {
var radius = this.cornerRadius.tl;
return Math.max(radius.x, radius.y);
},
set: function set(value) {
SetRadius(this.cornerRadius.tl, value);
}
}, {
key: "radiusTR",
get: function get() {
var radius = this.cornerRadius.tr;
return Math.max(radius.x, radius.y);
},
set: function set(value) {
SetRadius(this.cornerRadius.tr, value);
}
}, {
key: "radiusBL",
get: function get() {
var radius = this.cornerRadius.bl;
return Math.max(radius.x, radius.y);
},
set: function set(value) {
SetRadius(this.cornerRadius.bl, value);
}
}, {
key: "radiusBR",
get: function get() {
var radius = this.cornerRadius.br;
return Math.max(radius.x, radius.y);
},
set: function set(value) {
SetRadius(this.cornerRadius.br, value);
}
}]);
return RoundRectangle;
}();
var GetRadius = function GetRadius(radius, defaultRadiusX, defaultRadiusY) {
if (radius === undefined) {
radius = {
x: defaultRadiusX,
y: defaultRadiusY
};
} else if (typeof radius === 'number') {
radius = {
x: radius,
y: radius
};
}
SetConvex(radius);
return radius;
};
var SetRadius = function SetRadius(radius, value) {
if (typeof value === 'number') {
radius.x = value;
radius.y = value;
} else {
radius.x = GetValue$7(value, 'x', 0);
radius.y = GetValue$7(value, 'y', 0);
}
SetConvex(radius);
};
var SetConvex = function SetConvex(radius) {
radius.convex = radius.x >= 0 || radius.y >= 0;
radius.x = Math.abs(radius.x);
radius.y = Math.abs(radius.y);
};
var DegToRad = Phaser.Math.DegToRad;
var AddRoundRectanglePath = function AddRoundRectanglePath(context, x, y, width, hei