phaser3-rex-plugins
Version:
1,519 lines (1,467 loc) • 153 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.rexperspectiveimageplugin = 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);
}
var Mesh = Phaser.GameObjects.Mesh;
var MeshBase = /*#__PURE__*/function (_Mesh) {
_inherits(MeshBase, _Mesh);
var _super = _createSuper(MeshBase);
function MeshBase() {
_classCallCheck(this, MeshBase);
return _super.apply(this, arguments);
}
_createClass(MeshBase, [{
key: "tint",
get: function get() {
if (this.vertices.length === 0) {
return 0xffffff;
} else {
return this.vertices[0].color;
}
}
}, {
key: "setInteractive",
value: function setInteractive() {
var hitAreaCallback = function (area, x, y) {
var faces = this.faces;
for (var i = 0; i < faces.length; i++) {
var face = faces[i];
// Don't pass a calcMatrix, as the x/y are already transformed
if (face.contains(x, y)) {
return true;
}
}
return false;
}.bind(this);
this.scene.sys.input.enable(this, hitAreaCallback);
return this;
}
}, {
key: "forceUpdate",
value: function forceUpdate() {
this.dirtyCache[10] = 1;
return this;
}
}]);
return MeshBase;
}(Mesh);
var Vector3 = Phaser.Math.Vector3;
var Matrix4 = Phaser.Math.Matrix4;
var tempPosition = new Vector3();
var tempRotation = new Vector3();
var tempMatrix = new Matrix4();
var TransformVerts = function TransformVerts(mesh, x, y, z, rotateX, rotateY, rotateZ) {
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (z === undefined) {
z = 0;
}
if (rotateX === undefined) {
rotateX = 0;
}
if (rotateY === undefined) {
rotateY = 0;
}
if (rotateZ === undefined) {
rotateZ = 0;
}
tempPosition.set(x, y, z);
tempRotation.set(rotateX, rotateY, rotateZ);
tempMatrix.fromRotationXYTranslation(tempRotation, tempPosition, true);
for (var i = 0, cnt = mesh.vertices.length; i < cnt; i++) {
mesh.vertices[i].transformMat4(tempMatrix);
}
};
var IsPlainObject$6 = Phaser.Utils.Objects.IsPlainObject;
var GetValue$h = Phaser.Utils.Objects.GetValue;
var GenerateGridVerts = Phaser.Geom.Mesh.GenerateGridVerts;
var RadToDeg$4 = Phaser.Math.RadToDeg;
var DegToRad$6 = Phaser.Math.DegToRad;
var FOV = 45;
var PanZ = 1 + 1 / Math.sin(DegToRad$6(FOV));
var Image = /*#__PURE__*/function (_MeshBase) {
_inherits(Image, _MeshBase);
var _super = _createSuper(Image);
function Image(scene, x, y, key, frame, config) {
var _this;
_classCallCheck(this, Image);
if (IsPlainObject$6(x)) {
config = x;
x = GetValue$h(config, 'x', 0);
y = GetValue$h(config, 'y', 0);
key = GetValue$h(config, 'key', null);
frame = GetValue$h(config, 'frame', null);
}
_this = _super.call(this, scene, x, y, key, frame);
_this.type = 'rexPerspectiveImage';
_this.setSizeToFrame();
_this.resetPerspective();
_this.panZ(PanZ);
_this.hideCCW = GetValue$h(config, 'hideCCW', true);
var gridWidth = GetValue$h(config, 'gridWidth', 0);
var gridHeight = GetValue$h(config, 'gridHeight', gridWidth);
_this.resetVerts(gridWidth, gridHeight);
_this.prevFrame = _this.frame;
return _this;
}
_createClass(Image, [{
key: "preUpdate",
value: function preUpdate(time, delta) {
// Reset size and vertex if frame is changed
if (this.prevFrame !== this.frame) {
this.prevFrame = this.frame;
this.syncSize();
}
_get(_getPrototypeOf(Image.prototype), "preUpdate", this).call(this, time, delta);
}
}, {
key: "originX",
get: function get() {
return 0.5;
}
}, {
key: "originY",
get: function get() {
return 0.5;
}
}, {
key: "resetPerspective",
value: function resetPerspective() {
this.setPerspective(this.width, this.height, FOV);
return this;
}
}, {
key: "resetVerts",
value: function resetVerts(gridWidth, gridHeight) {
if (gridWidth !== undefined) {
this.gridWidth = gridWidth;
}
if (gridHeight !== undefined) {
this.gridHeight = gridHeight;
}
// Clear faces and vertices
this.clear();
this.dirtyCache[9] = -1;
if (this.width === 0 || this.height === 0) {
return this;
}
// Generate faces and vertices
var frameWidth = this.frame.cutWidth,
frameHeight = this.frame.cutHeight;
var gridWidth, gridHeight;
if (this.gridWidth === 0) {
gridWidth = Math.max(frameWidth / 8, 32);
} else {
gridHeight = this.gridWidth;
}
if (this.gridHeight === 0) {
gridHeight = Math.max(frameHeight / 8, 32);
} else {
gridHeight = this.gridHeight;
}
GenerateGridVerts({
mesh: this,
width: frameWidth / this.height,
height: frameHeight / this.height,
widthSegments: Math.ceil(frameWidth / gridWidth),
heightSegments: Math.ceil(frameHeight / gridHeight)
});
// Recover vertices transform
var transformInfo = this.transformInfo;
if (transformInfo) {
this.transformVerts(transformInfo.x, transformInfo.y, transformInfo.z, transformInfo.rotateX, transformInfo.rotateY, transformInfo.rotateZ);
}
return this;
}
}, {
key: "syncSize",
value: function syncSize() {
this.setSizeToFrame(); // Reset size
this.resetPerspective(); // Reset perspective
this.resetVerts(); // Reset verts
return this;
}
}, {
key: "rotationX",
get: function get() {
return this.modelRotation.x;
},
set: function set(value) {
this.modelRotation.x = value;
}
}, {
key: "angleX",
get: function get() {
return RadToDeg$4(this.rotationX);
},
set: function set(value) {
this.rotationX = DegToRad$6(value);
}
}, {
key: "rotationY",
get: function get() {
return this.modelRotation.y;
},
set: function set(value) {
this.modelRotation.y = value;
}
}, {
key: "angleY",
get: function get() {
return RadToDeg$4(this.rotationY);
},
set: function set(value) {
this.rotationY = DegToRad$6(value);
}
}, {
key: "rotationZ",
get: function get() {
return this.modelRotation.z;
},
set: function set(value) {
this.modelRotation.z = value;
}
}, {
key: "angleZ",
get: function get() {
return RadToDeg$4(this.rotationZ);
},
set: function set(value) {
this.rotationZ = DegToRad$6(value);
}
}, {
key: "transformVerts",
value: function transformVerts(x, y, z, rotateX, rotateY, rotateZ) {
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (z === undefined) {
z = 0;
}
if (rotateX === undefined) {
rotateX = 0;
}
if (rotateY === undefined) {
rotateY = 0;
}
if (rotateZ === undefined) {
rotateZ = 0;
}
if (!this.transformInfo) {
this.transformInfo = {};
}
this.transformInfo.x = x;
this.transformInfo.y = y;
this.transformInfo.rotateX = rotateX;
this.transformInfo.rotateY = rotateY;
this.transformInfo.rotateZ = rotateZ;
TransformVerts(this, x, y, z, rotateX, rotateY, rotateZ);
return this;
}
}]);
return Image;
}(MeshBase);
function PerspectiveImageFactory (x, y, texture, frame, config) {
var gameObject = new Image(this.scene, x, y, texture, frame, config);
this.scene.add.existing(gameObject);
return gameObject;
}
var GetAdvancedValue$3 = Phaser.Utils.Objects.GetAdvancedValue;
var BuildGameObject$5 = Phaser.GameObjects.BuildGameObject;
function PerspectiveImageCreator (config, addToScene) {
if (config === undefined) {
config = {};
}
if (addToScene !== undefined) {
config.add = addToScene;
}
var key = GetAdvancedValue$3(config, 'key', null);
var frame = GetAdvancedValue$3(config, 'frame', null);
var gameObject = new Image(this.scene, 0, 0, key, frame, config);
BuildGameObject$5(this.scene, gameObject, config);
return gameObject;
}
var DynamicTexture$1 = Phaser.Textures.DynamicTexture;
var CreateDynamicTexture = function CreateDynamicTexture(scene, width, height) {
if (width === undefined) {
width = 2;
}
if (height === undefined) {
height = 2;
}
var dt = new DynamicTexture$1(scene.sys.textures, null, width, height);
return dt;
};
var GetDisplayWidth = function GetDisplayWidth(gameObject) {
if (gameObject.displayWidth !== undefined) {
return gameObject.displayWidth;
} else {
return gameObject.width;
}
};
var GetDisplayHeight = function GetDisplayHeight(gameObject) {
if (gameObject.displayHeight !== undefined) {
return gameObject.displayHeight;
} else {
return gameObject.height;
}
};
var Rectangle$1 = Phaser.Geom.Rectangle;
var Vector2 = Phaser.Math.Vector2;
var RotateAround$2 = Phaser.Math.RotateAround;
var GetBounds = function GetBounds(gameObject, output) {
if (output === undefined) {
output = new Rectangle$1();
} else if (output === true) {
if (GlobRect$1 === undefined) {
GlobRect$1 = new Rectangle$1();
}
output = GlobRect$1;
}
if (gameObject.getBounds) {
return gameObject.getBounds(output);
}
// We can use the output object to temporarily store the x/y coords in:
var TLx, TLy, TRx, TRy, BLx, BLy, BRx, BRy;
// Instead of doing a check if parent container is
// defined per corner we only do it once.
if (gameObject.parentContainer) {
var parentMatrix = gameObject.parentContainer.getBoundsTransformMatrix();
GetTopLeft(gameObject, output);
parentMatrix.transformPoint(output.x, output.y, output);
TLx = output.x;
TLy = output.y;
GetTopRight(gameObject, output);
parentMatrix.transformPoint(output.x, output.y, output);
TRx = output.x;
TRy = output.y;
GetBottomLeft(gameObject, output);
parentMatrix.transformPoint(output.x, output.y, output);
BLx = output.x;
BLy = output.y;
GetBottomRight(gameObject, output);
parentMatrix.transformPoint(output.x, output.y, output);
BRx = output.x;
BRy = output.y;
} else {
GetTopLeft(gameObject, output);
TLx = output.x;
TLy = output.y;
GetTopRight(gameObject, output);
TRx = output.x;
TRy = output.y;
GetBottomLeft(gameObject, output);
BLx = output.x;
BLy = output.y;
GetBottomRight(gameObject, output);
BRx = output.x;
BRy = output.y;
}
output.x = Math.min(TLx, TRx, BLx, BRx);
output.y = Math.min(TLy, TRy, BLy, BRy);
output.width = Math.max(TLx, TRx, BLx, BRx) - output.x;
output.height = Math.max(TLy, TRy, BLy, BRy) - output.y;
return output;
};
var GlobRect$1 = undefined;
var GetTopLeft = function GetTopLeft(gameObject, output, includeParent) {
if (output === undefined) {
output = new Vector2();
} else if (output === true) {
if (GlobVector === undefined) {
GlobVector = new Vector2();
}
output = GlobVector;
}
if (gameObject.getTopLeft) {
return gameObject.getTopLeft(output);
}
output.x = gameObject.x - GetDisplayWidth(gameObject) * gameObject.originX;
output.y = gameObject.y - GetDisplayHeight(gameObject) * gameObject.originY;
return PrepareBoundsOutput(gameObject, output, includeParent);
};
var GetTopRight = function GetTopRight(gameObject, output, includeParent) {
if (output === undefined) {
output = new Vector2();
} else if (output === true) {
if (GlobVector === undefined) {
GlobVector = new Vector2();
}
output = GlobVector;
}
if (gameObject.getTopRight) {
return gameObject.getTopRight(output);
}
output.x = gameObject.x - GetDisplayWidth(gameObject) * gameObject.originX + GetDisplayWidth(gameObject);
output.y = gameObject.y - GetDisplayHeight(gameObject) * gameObject.originY;
return PrepareBoundsOutput(gameObject, output, includeParent);
};
var GetBottomLeft = function GetBottomLeft(gameObject, output, includeParent) {
if (output === undefined) {
output = new Vector2();
} else if (output === true) {
if (GlobVector === undefined) {
GlobVector = new Vector2();
}
output = GlobVector;
}
if (gameObject.getBottomLeft) {
return gameObject.getBottomLeft(output);
}
output.x = gameObject.x - GetDisplayWidth(gameObject) * gameObject.originX;
output.y = gameObject.y - GetDisplayHeight(gameObject) * gameObject.originY + GetDisplayHeight(gameObject);
return PrepareBoundsOutput(gameObject, output, includeParent);
};
var GetBottomRight = function GetBottomRight(gameObject, output, includeParent) {
if (output === undefined) {
output = new Vector2();
} else if (output === true) {
if (GlobVector === undefined) {
GlobVector = new Vector2();
}
output = GlobVector;
}
if (gameObject.getBottomRight) {
return gameObject.getBottomRight(output);
}
output.x = gameObject.x - GetDisplayWidth(gameObject) * gameObject.originX + GetDisplayWidth(gameObject);
output.y = gameObject.y - GetDisplayHeight(gameObject) * gameObject.originY + GetDisplayHeight(gameObject);
return PrepareBoundsOutput(gameObject, output, includeParent);
};
var GlobVector = undefined;
var PrepareBoundsOutput = function PrepareBoundsOutput(gameObject, output, includeParent) {
if (includeParent === undefined) {
includeParent = false;
}
if (gameObject.rotation !== 0) {
RotateAround$2(output, gameObject.x, gameObject.y, gameObject.rotation);
}
if (includeParent && gameObject.parentContainer) {
var parentMatrix = gameObject.parentContainer.getBoundsTransformMatrix();
parentMatrix.transformPoint(output.x, output.y, output);
}
return output;
};
var Rectangle = Phaser.Geom.Rectangle;
var Union = Phaser.Geom.Rectangle.Union;
var GetBoundsOfGameObjects = function GetBoundsOfGameObjects(gameObjects, out) {
if (out === undefined) {
out = new Rectangle();
} else if (out === true) {
if (GlobRect === undefined) {
GlobRect = new Rectangle();
}
out = GlobRect;
}
out.setTo(0, 0, 0, 0);
var gameObject;
var firstClone = true;
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
gameObject = gameObjects[i];
if (!gameObject.getBounds) {
continue;
}
var boundsRect = GetBounds(gameObject, true);
if (firstClone) {
out.setTo(boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height);
firstClone = false;
} else {
Union(boundsRect, out, out);
}
}
return out;
};
var GlobRect;
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;
};
/**
* Shallow Object Clone. Will not out nested objects.
* @param {object} obj JSON object
* @param {object} ret JSON object to return, set null to return a new object
* @returns {object} this object
*/
var Clone = function Clone(obj, out) {
var objIsArray = Array.isArray(obj);
if (out === undefined) {
out = objIsArray ? [] : {};
} else {
Clear(out);
}
if (objIsArray) {
out.length = obj.length;
for (var i = 0, cnt = obj.length; i < cnt; i++) {
out[i] = obj[i];
}
} else {
for (var key in obj) {
out[key] = obj[key];
}
}
return out;
};
var SortGameObjectsByDepth = function SortGameObjectsByDepth(gameObjects, descending) {
if (gameObjects.length <= 1) {
return gameObjects;
}
if (descending === undefined) {
descending = false;
}
var itemList;
var gameObject = gameObjects[0];
if (gameObject.displayList) {
// Inside a scene or a layer
itemList = gameObject.displayList; // displayList
} else if (gameObject.parentContainer) {
// Inside a container
itemList = gameObject.parentContainer.list; // array
} else {
itemList = gameObject.scene.sys.displayList; // displayList
// ??
}
if (itemList.depthSort) {
// Is a displayList object
itemList.depthSort();
itemList = itemList.list;
// itemList is an array now
}
// itemList is an array
if (descending) {
gameObjects.sort(function (childA, childB) {
return itemList.indexOf(childB) - itemList.indexOf(childA);
});
} else {
gameObjects.sort(function (childA, childB) {
return itemList.indexOf(childA) - itemList.indexOf(childB);
});
}
return gameObjects;
};
var GameObjectClass = Phaser.GameObjects.GameObject;
var IsGameObject = function IsGameObject(object) {
return object instanceof GameObjectClass;
};
var GetValue$g = Phaser.Utils.Objects.GetValue;
var DynamicTexture = Phaser.Textures.DynamicTexture;
var UUID = Phaser.Utils.String.UUID;
var Snapshot = function Snapshot(config) {
if (!config) {
return;
}
var gameObjects = config.gameObjects;
var renderTexture = config.renderTexture; // renderTexture, or dynamicTexture
var x = GetValue$g(config, 'x', undefined);
var y = GetValue$g(config, 'y', undefined);
var width = GetValue$g(config, 'width', undefined);
var height = GetValue$g(config, 'height', undefined);
var originX = GetValue$g(config, 'originX', 0);
var originY = GetValue$g(config, 'originY', 0);
var padding = GetValue$g(config, 'padding', 0);
var scrollX, scrollY;
if (width === undefined || height === undefined || x === undefined || y === undefined) {
// Union bounds of gameObjects
var bounds = GetBoundsOfGameObjects(gameObjects, true);
var isCenterOrigin = x !== undefined && y !== undefined;
if (isCenterOrigin) {
width = Math.max(x - bounds.left, bounds.right - x) * 2;
height = Math.max(y - bounds.top, bounds.bottom - y) * 2;
originX = 0.5;
originY = 0.5;
} else {
x = bounds.x;
y = bounds.y;
width = bounds.width;
height = bounds.height;
originX = 0;
originY = 0;
}
scrollX = bounds.x;
scrollY = bounds.y;
} else {
scrollX = x + (0 - originX) * width;
scrollY = y + (0 - originY) * height;
}
scrollX -= padding;
scrollY -= padding;
width += padding * 2;
height += padding * 2;
var scene = gameObjects[0].scene;
// Snapshot on dynamicTexture directly
if (saveTexture && !renderTexture) {
renderTexture = new DynamicTexture(scene.sys.textures, UUID(), width, height);
}
// Return a renderTexture
if (!renderTexture) {
renderTexture = scene.add.renderTexture(0, 0, width, height);
}
if (renderTexture.setPosition) {
renderTexture.setPosition(x, y);
}
if (renderTexture.width !== width || renderTexture.height !== height) {
renderTexture.setSize(width, height);
}
if (renderTexture.setOrigin) {
renderTexture.setOrigin(originX, originY);
}
renderTexture.camera.setScroll(scrollX, scrollY);
// Draw gameObjects
gameObjects = SortGameObjectsByDepth(Clone(gameObjects));
renderTexture.draw(gameObjects);
// Save render result to texture
var saveTexture = config.saveTexture;
if (saveTexture) {
if (IsGameObject(renderTexture)) {
renderTexture.saveTexture(saveTexture);
} else {
var dynamicTexture = renderTexture;
var textureManager = dynamicTexture.manager;
if (textureManager.exists(dynamicTexture.key)) {
// Rename texture
textureManager.renameTexture(dynamicTexture.key, key);
} else {
// Add texture to texture manager
dynamicTexture.key = key;
textureManager.list[key] = dynamicTexture;
textureManager.emit('addtexture', key, dynamicTexture);
textureManager.emit("addtexture-".concat(key), dynamicTexture);
}
}
}
return renderTexture;
};
var IsPlainObject$5 = Phaser.Utils.Objects.IsPlainObject;
var GetValue$f = Phaser.Utils.Objects.GetValue;
var RenderTexture$1 = /*#__PURE__*/function (_Image) {
_inherits(RenderTexture, _Image);
var _super = _createSuper(RenderTexture);
function RenderTexture(scene, x, y, width, height, config) {
var _this;
_classCallCheck(this, RenderTexture);
if (IsPlainObject$5(x)) {
config = x;
x = GetValue$f(config, 'x', 0);
y = GetValue$f(config, 'y', 0);
width = GetValue$f(config, 'width', 32);
height = GetValue$f(config, 'height', 32);
}
// dynamic-texture -> quad-image
var texture = CreateDynamicTexture(scene, width, height);
_this = _super.call(this, scene, x, y, texture, null, config);
_this.type = 'rexPerspectiveRenderTexture';
_this.rt = _this.texture;
return _this;
}
_createClass(RenderTexture, [{
key: "destroy",
value: function destroy(fromScene) {
// This Game Object has already been destroyed
if (!this.scene || this.ignoreDestroy) {
return;
}
_get(_getPrototypeOf(RenderTexture.prototype), "destroy", this).call(this, fromScene);
this.rt.destroy();
this.rt = null;
}
}, {
key: "snapshot",
value: function snapshot(gameObjects, config) {
if (config === undefined) {
config = {};
}
config.gameObjects = gameObjects;
config.renderTexture = this.rt;
Snapshot(config);
if (this.width !== this.frame.realWidth || this.height !== this.frame.realHeight) {
this.syncSize();
}
return this;
}
}]);
return RenderTexture;
}(Image);
function PerspectiveRenderTextureFactory (x, y, width, height, config) {
var gameObject = new RenderTexture$1(this.scene, x, y, width, height, config);
this.scene.add.existing(gameObject);
return gameObject;
}
var GetAdvancedValue$2 = Phaser.Utils.Objects.GetAdvancedValue;
var BuildGameObject$4 = Phaser.GameObjects.BuildGameObject;
function PerspectiveRenderTextureCreator (config, addToScene) {
if (config === undefined) {
config = {};
}
if (addToScene !== undefined) {
config.add = addToScene;
}
var x = GetAdvancedValue$2(config, 'x', 0);
var y = GetAdvancedValue$2(config, 'y', 0);
var width = GetAdvancedValue$2(config, 'width', 32);
var height = GetAdvancedValue$2(config, 'height', 32);
var gameObject = new RenderTexture$1(this.scene, x, y, width, height, config);
BuildGameObject$4(this.scene, gameObject, config);
return gameObject;
}
var AnimationState = Phaser.Animations.AnimationState;
var IsPlainObject$4 = Phaser.Utils.Objects.IsPlainObject;
var GetValue$e = Phaser.Utils.Objects.GetValue;
var Sprite = /*#__PURE__*/function (_PerspectiveImage) {
_inherits(Sprite, _PerspectiveImage);
var _super = _createSuper(Sprite);
function Sprite(scene, x, y, key, frame, config) {
var _this;
_classCallCheck(this, Sprite);
if (IsPlainObject$4(x)) {
config = x;
x = GetValue$e(config, 'x', 0);
y = GetValue$e(config, 'y', 0);
key = GetValue$e(config, 'key', null);
frame = GetValue$e(config, 'frame', null);
}
_this = _super.call(this, scene, x, y, key, frame, config);
_this.type = 'rexPerspectiveSprite';
_this.anims = new AnimationState(_assertThisInitialized(_this));
return _this;
}
_createClass(Sprite, [{
key: "preDestroy",
value: function preDestroy() {
_get(_getPrototypeOf(Sprite.prototype), "preDestroy", this).call(this);
this.anims.destroy();
this.anims = undefined;
}
}, {
key: "preUpdate",
value: function preUpdate(time, delta) {
this.anims.update(time, delta);
_get(_getPrototypeOf(Sprite.prototype), "preUpdate", this).call(this, time, delta);
}
}, {
key: "play",
value: function play(key, ignoreIfPlaying, startFrame) {
return this.anims.play(key, ignoreIfPlaying, startFrame);
}
}, {
key: "playReverse",
value: function playReverse(key, ignoreIfPlaying) {
return this.anims.playReverse(key, ignoreIfPlaying);
}
}, {
key: "playAfterDelay",
value: function playAfterDelay(key, delay) {
return this.anims.playAfterDelay(key, delay);
}
}, {
key: "playAfterRepeat",
value: function playAfterRepeat(key, repeatCount) {
return this.anims.playAfterRepeat(key, repeatCount);
}
}, {
key: "chain",
value: function chain(key) {
return this.anims.chain(key);
}
}, {
key: "stop",
value: function stop() {
return this.anims.stop();
}
}, {
key: "stopAfterDelay",
value: function stopAfterDelay(delay) {
return this.anims.stopAfterDelay(delay);
}
}, {
key: "stopAfterRepeat",
value: function stopAfterRepeat(repeatCount) {
return this.anims.stopAfterRepeat(repeatCount);
}
}, {
key: "stopOnFrame",
value: function stopOnFrame(frame) {
return this.anims.stopOnFrame(frame);
}
}]);
return Sprite;
}(Image);
function PerspectiveSpriteFactory (x, y, texture, frame, config) {
var gameObject = new Sprite(this.scene, x, y, texture, frame, config);
this.scene.add.existing(gameObject);
return gameObject;
}
var GetAdvancedValue$1 = Phaser.Utils.Objects.GetAdvancedValue;
var BuildGameObject$3 = Phaser.GameObjects.BuildGameObject;
function PerspectiveSpriteCreator (config, addToScene) {
if (config === undefined) {
config = {};
}
if (addToScene !== undefined) {
config.add = addToScene;
}
var key = GetAdvancedValue$1(config, 'key', null);
var frame = GetAdvancedValue$1(config, 'frame', null);
var gameObject = new Sprite(this.scene, 0, 0, key, frame, config);
BuildGameObject$3(this.scene, gameObject, config);
return gameObject;
}
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 Zone = Phaser.GameObjects.Zone;
var AddItem = Phaser.Utils.Array.Add;
var RemoveItem = Phaser.Utils.Array.Remove;
var Base = /*#__PURE__*/function (_Zone) {
_inherits(Base, _Zone);
var _super = _createSuper(Base);
function Base(scene, x, y, width, height) {
var _this;
_classCallCheck(this, Base);
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, x, y, width, height);
_this.children = [];
return _this;
}
_createClass(Base, [{
key: "destroy",
value: function destroy(fromScene) {
// This Game Object has already been destroyed
if (!this.scene || this.ignoreDestroy) {
return;
}
if (fromScene) {
// Stop scene
var child;
for (var i = this.children.length - 1; i >= 0; i--) {
child = this.children[i];
if (!child.parentContainer &&
// Not in container
!child.displayList // Not in scene, neither in layer
) {
// Destroy child which is not in scene, container, or layer manually
child.destroy(fromScene);
}
}
}
// Destroy/remove children
this.clear(!fromScene);
_get(_getPrototypeOf(Base.prototype), "destroy", this).call(this, fromScene);
}
}, {
key: "contains",
value: function contains(gameObject) {
return this.children.indexOf(gameObject) !== -1;
}
}, {
key: "add",
value: function add(gameObjects) {
var parent = this;
AddItem(this.children, gameObjects, 0,
// Callback of item added
function (gameObject) {
gameObject.once('destroy', parent.onChildDestroy, parent);
}, this);
return this;
}
}, {
key: "remove",
value: function remove(gameObjects, destroyChild) {
var parent = this;
RemoveItem(this.children, gameObjects,
// Callback of item removed
function (gameObject) {
gameObject.off('destroy', parent.onChildDestroy, parent);
if (destroyChild) {
gameObject.destroy();
}
});
return this;
}
}, {
key: "onChildDestroy",
value: function onChildDestroy(child, fromScene) {
// Only remove reference
this.remove(child, false);
}
}, {
key: "clear",
value: function clear(destroyChild) {
var parent = this;
var gameObject;
for (var i = 0, cnt = this.children.length; i < cnt; i++) {
gameObject = this.children[i];
gameObject.off('destroy', parent.onChildDestroy, parent);
if (destroyChild) {
gameObject.destroy();
}
}
this.children.length = 0;
return this;
}
}]);
return Base;
}(Zone);
var Components = Phaser.GameObjects.Components;
Phaser.Class.mixin(Base, [Components.Alpha, Components.Flip]);
var GetParent = function GetParent(gameObject, name) {
var parent;
if (name === undefined) {
if (gameObject.hasOwnProperty('rexContainer')) {
parent = gameObject.rexContainer.parent;
}
} else {
parent = GetParent(gameObject);
while (parent) {
if (parent.name === name) {
break;
}
parent = GetParent(parent);
}
}
return parent;
};
var GetTopmostParent = function GetTopmostParent(gameObject) {
var parent = GetParent(gameObject);
while (parent) {
gameObject = parent;
parent = GetParent(parent);
}
return gameObject;
};
var DegToRad$5 = Phaser.Math.DegToRad;
var RadToDeg$3 = Phaser.Math.RadToDeg;
var GetLocalState = function GetLocalState(gameObject) {
if (!gameObject.hasOwnProperty('rexContainer')) {
var rexContainer = {
parent: null,
self: null,
layer: null,
x: 0,
y: 0,
syncPosition: true,
rotation: 0,
syncRotation: true,
scaleX: 0,
scaleY: 0,
syncScale: true,
alpha: 0,
syncAlpha: true,
visible: true,
active: true
};
Object.defineProperty(rexContainer, 'angle', {
get: function get() {
return RadToDeg$3(this.rotation);
},
set: function set(value) {
this.rotation = DegToRad$5(value);
}
});
Object.defineProperty(rexContainer, 'displayWidth', {
get: function get() {
return gameObject.width * this.scaleX;
},
set: function set(width) {
this.scaleX = width / gameObject.width;
}
});
Object.defineProperty(rexContainer, 'displayHeight', {
get: function get() {
return gameObject.height * this.scaleY;
},
set: function set(height) {
this.scaleY = height / gameObject.height;
}
});
gameObject.rexContainer = rexContainer;
}
return gameObject.rexContainer;
};
var Parent = {
setParent: function setParent(gameObject, parent) {
if (parent === undefined) {
parent = this;
}
var localState = GetLocalState(gameObject);
if (parent) {
// Add to parent
localState.parent = parent;
localState.self = gameObject;
} else {
// Remove from parent
localState.parent = null;
localState.self = null;
}
return this;
},
getParent: function getParent(gameObject, name) {
if (typeof gameObject === 'string') {
name = gameObject;
gameObject = undefined;
}
if (gameObject === undefined) {
gameObject = this;
}
return GetParent(gameObject, name);
},
getTopmostParent: function getTopmostParent(gameObject) {
if (gameObject === undefined) {
gameObject = this;
}
return GetTopmostParent(gameObject);
}
};
var GetValue$d = Phaser.Utils.Objects.GetValue;
var BaseAdd = Base.prototype.add;
var Add = function Add(gameObject, config) {
this.setParent(gameObject);
var state = GetLocalState(gameObject);
SetupSyncFlags(state, config);
this.resetChildState(gameObject) // Reset local state of child
.updateChildVisible(gameObject) // Apply parent's visible to child
.updateChildActive(gameObject) // Apply parent's active to child
.updateChildScrollFactor(gameObject) // Apply parent's scroll factor to child
.updateChildMask(gameObject); // Apply parent's mask to child
BaseAdd.call(this, gameObject);
this.addToParentContainer(gameObject);
this.addToRenderLayer(gameObject);
return this;
};
var AddLocal = function AddLocal(gameObject, config) {
this.setParent(gameObject);
// Set local state from child directly
var state = GetLocalState(gameObject);
SetupSyncFlags(state, config);
// Position
state.x = gameObject.x;
state.y = gameObject.y;
state.rotation = gameObject.rotation;
state.scaleX = gameObject.scaleX;
state.scaleY = gameObject.scaleY;
// Alpha
state.alpha = gameObject.alpha;
// Visible
state.visible = gameObject.visible;
// Active
state.active = gameObject.active;
this.updateChildPosition(gameObject).updateChildAlpha(gameObject).updateChildVisible(gameObject) // Apply parent's visible to child
.updateChildActive(gameObject) // Apply parent's active to child
.updateChildScrollFactor(gameObject) // Apply parent's scroll factor to child
.updateChildMask(gameObject); // Apply parent's mask to child
BaseAdd.call(this, gameObject);
this.addToRenderLayer(gameObject);
return this;
};
var SetupSyncFlags = function SetupSyncFlags(state, config) {
if (config === undefined) {
config = true;
}
if (typeof config === 'boolean') {
state.syncPosition = config;
state.syncRotation = config;
state.syncScale = config;
state.syncAlpha = config;
state.syncScrollFactor = config;
} else {
state.syncPosition = GetValue$d(config, 'syncPosition', true);
state.syncRotation = GetValue$d(config, 'syncRotation', true);
state.syncScale = GetValue$d(config, 'syncScale', true);
state.syncAlpha = GetValue$d(config, 'syncAlpha', true);
state.syncScrollFactor = GetValue$d(config, 'syncScrollFactor', true);
}
};
var AddChild = {
// Can override this method
add: function add(gameObject) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject);
} else {
Add.call(this, gameObject);
}
return this;
},
// Don't override this method
pin: function pin(gameObject, config) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject, config);
} else {
Add.call(this, gameObject, config);
}
return this;
},
addMultiple: function addMultiple(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
Add.call(this, gameObjects[i]);
}
return this;
},
addLocal: function addLocal(gameObject) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject);
} else {
AddLocal.call(this, gameObject);
}
return this;
},
// Don't override this method
pinLocal: function pinLocal(gameObject, config) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject, config);
} else {
AddLocal.call(this, gameObject, config);
}
return this;
},
addLocalMultiple: function addLocalMultiple(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
AddLocal.call(this, gameObjects[i]);
}
return this;
}
};
var BaseRemove = Base.prototype.remove;
var BaseClear = Base.prototype.clear;
var RemoveChild = {
// Can override this method
remove: function remove(gameObject, destroyChild) {
if (GetParent(gameObject) !== this) {
return this;
}
this.setParent(gameObject, null);
if (!destroyChild) {
this.removeFromRenderLayer(gameObject);
}
BaseRemove.call(this, gameObject, destroyChild);
return this;
},
// Don't override this method
unpin: function unpin(gameObject, destroyChild) {
if (GetParent(gameObject) !== this) {
return this;
}
this.setParent(gameObject, null);
if (!destroyChild) {
this.removeFromRenderLayer(gameObject);
}
BaseRemove.call(this, gameObject, destroyChild);
return this;
},
clear: function clear(destroyChild) {
var children = this.children;
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
this.setParent(child, null);
if (!destroyChild) {
this.removeFromRenderLayer(child);
}
}
BaseClear.call(this, destroyChild);
return this;
}
};
var ChildState = {
getLocalState: function getLocalState(gameObject) {
return GetLocalState(gameObject);
},
resetChildState: function resetChildState(gameObject) {
this.resetChildPositionState(gameObject).resetChildVisibleState(gameObject).resetChildAlphaState(gameObject).resetChildActiveState(gameObject);
return this;
},
resetChildrenState: function resetChildrenState(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
this.resetChildState(gameObjects[i]);
}
return this;
},
syncProperties: function syncProperties() {
this.syncPosition().syncVisible().syncAlpha().syncActive().syncScrollFactor().syncMask();
return this;
}
};
var RotateAround$1 = Phaser.Math.RotateAround;
var Transform = {
worldToLocal: function worldToLocal(point) {
// Transform
point.x -= this.x;
point.y -= this.y;
// Rotate
RotateAround$1(point, 0, 0, -this.rotation);
// Scale
point.x /= this.scaleX;
point.y /= this.scaleY;
return point;
},
localToWorld: function localToWorld(point) {
// Scale
point.x *= this.scaleX;
point.y *= this.scaleY;
// Rotate
RotateAround$1(point, 0, 0, this.rotation);
// Transform
point.x += this.x;
point.y += this.y;
return point;
}
};
var GetScale = function GetScale(a, b) {
if (a === b) {
return 1;
} else {
return a / b;
}
};
var Position = {
updateChildPosition: function updateChildPosition(child) {
if (child.isRexContainerLite) {