phaser4-rex-plugins
Version:
1,597 lines (1,355 loc) • 386 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.rexbadgelabel = factory());
})(this, (function () { 'use strict';
const MainVersionNumber = 4;
const SubVersionNumber = 0;
var IsChecked = false;
var CheckP3Version = function (minVersion) {
if (IsChecked) {
return;
}
if (minVersion === undefined) {
minVersion = SubVersionNumber;
}
var version = Phaser.VERSION.split('.');
var mainVersion = parseInt(version[0]);
if (mainVersion === MainVersionNumber) {
var subVersion = parseInt(version[1]);
if (subVersion < minVersion) {
console.error(`Minimum supported version : ${mainVersion}.${subVersion}`);
}
} else {
console.error(`Can't supported version : ${mainVersion}`);
}
IsChecked = true;
};
CheckP3Version();
const Zone = Phaser.GameObjects.Zone;
const AddItem = Phaser.Utils.Array.Add;
const RemoveItem$3 = Phaser.Utils.Array.Remove;
let Base$1 = class Base extends Zone {
constructor(scene, x, y, width, height) {
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (width === undefined) {
width = 1;
}
if (height === undefined) {
height = 1;
}
super(scene, x, y, width, height);
this.children = [];
}
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);
super.destroy(fromScene);
}
contains(gameObject) {
return (this.children.indexOf(gameObject) !== -1);
}
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;
}
remove(gameObjects, destroyChild) {
var parent = this;
RemoveItem$3(this.children, gameObjects,
// Callback of item removed
function (gameObject) {
gameObject.off('destroy', parent.onChildDestroy, parent);
if (destroyChild) {
gameObject.destroy();
}
}
);
return this;
}
onChildDestroy(child, fromScene) {
// Only remove reference
this.remove(child, false);
}
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;
}
};
const Components = Phaser.GameObjects.Components;
Phaser.Class.mixin(Base$1,
[
Components.Alpha,
Components.Flip
]
);
var GetParent$1 = function (gameObject, name) {
var parent;
if (name === undefined) {
if (gameObject.hasOwnProperty('rexContainer')) {
parent = gameObject.rexContainer.parent;
}
} else {
parent = GetParent$1(gameObject);
while (parent) {
if (parent.name === name) {
break;
}
parent = GetParent$1(parent);
}
}
return parent;
};
var GetTopmostParent$1 = function (gameObject) {
var parent = GetParent$1(gameObject);
while (parent) {
gameObject = parent;
parent = GetParent$1(parent);
}
return gameObject;
};
const DegToRad$2 = Phaser.Math.DegToRad;
const RadToDeg$2 = Phaser.Math.RadToDeg;
var GetLocalState = function (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,
syncScrollFactor: true,
syncCameraFilter: true,
syncDisplayList: true,
visible: true,
active: true,
};
Object.defineProperty(rexContainer, 'angle', {
get: function () {
return RadToDeg$2(this.rotation);
},
set: function (value) {
this.rotation = DegToRad$2(value);
}
});
Object.defineProperty(rexContainer, 'displayWidth', {
get: function () {
return gameObject.width * this.scaleX;
},
set: function (width) {
this.scaleX = width / gameObject.width;
}
});
Object.defineProperty(rexContainer, 'displayHeight', {
get: function () {
return gameObject.height * this.scaleY;
},
set: function (height) {
this.scaleY = height / gameObject.height;
}
});
gameObject.rexContainer = rexContainer;
}
return gameObject.rexContainer;
};
var Parent = {
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(gameObject, name) {
if (typeof (gameObject) === 'string') {
name = gameObject;
gameObject = undefined;
}
if (gameObject === undefined) {
gameObject = this;
}
return GetParent$1(gameObject, name);
},
getTopmostParent(gameObject) {
if (gameObject === undefined) {
gameObject = this;
}
return GetTopmostParent$1(gameObject);
}
};
const GetValue$H = Phaser.Utils.Objects.GetValue;
const BaseAdd = Base$1.prototype.add;
var Add$1 = function (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
.updateCameraFilter(gameObject); // Apply parent's cameraFilter to child
BaseAdd.call(this, gameObject);
SyncDisplayList.call(this, gameObject, state);
return this;
};
var AddLocal = function (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);
SyncDisplayList.call(this, gameObject, state);
return this;
};
var SetupSyncFlags = function (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;
state.syncCameraFilter = config;
state.syncDisplayList = config;
} else {
state.syncPosition = GetValue$H(config, 'syncPosition', true);
state.syncRotation = GetValue$H(config, 'syncRotation', true);
state.syncScale = GetValue$H(config, 'syncScale', true);
state.syncAlpha = GetValue$H(config, 'syncAlpha', true);
state.syncScrollFactor = GetValue$H(config, 'syncScrollFactor', true);
state.syncCameraFilter = GetValue$H(config, 'syncCameraFilter', true);
state.syncDisplayList = GetValue$H(config, 'syncDisplayList', true);
}
};
var SyncDisplayList = function (gameObject, state) {
this.addToParentContainer(gameObject); // Sync parent's container to child
if (state.syncDisplayList) {
this.addToPatentLayer(gameObject); // Sync parent's layer to child
}
this.addToRenderLayer(gameObject); // Sync parent's render-layer
};
var AddChild$1 = {
// Can override this method
add(gameObject) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject);
} else {
Add$1.call(this, gameObject);
}
return this;
},
// Don't override this method
pin(gameObject, config) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject, config);
} else {
Add$1.call(this, gameObject, config);
}
return this;
},
// Can override this method
addMultiple(gameObjects) {
var args = Array.from(arguments);
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
args[0] = gameObjects[i];
this.add.apply(this, args);
}
return this;
},
addLocal(gameObject) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject);
} else {
AddLocal.call(this, gameObject);
}
return this;
},
// Don't override this method
pinLocal(gameObject, config) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject, config);
} else {
AddLocal.call(this, gameObject, config);
}
return this;
},
addLocalMultiple(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
AddLocal.call(this, gameObjects[i]);
}
return this;
}
};
const BaseRemove = Base$1.prototype.remove;
const BaseClear = Base$1.prototype.clear;
var RemoveChild$1 = {
// Can override this method
remove(gameObject, destroyChild) {
if (GetParent$1(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(gameObject, destroyChild) {
if (GetParent$1(gameObject) !== this) {
return this;
}
this.setParent(gameObject, null);
if (!destroyChild) {
this.removeFromRenderLayer(gameObject);
}
BaseRemove.call(this, gameObject, destroyChild);
return this;
},
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(gameObject) {
return GetLocalState(gameObject);
},
resetChildState(gameObject) {
this
.resetChildPositionState(gameObject)
.resetChildVisibleState(gameObject)
.resetChildAlphaState(gameObject)
.resetChildActiveState(gameObject);
return this;
},
resetChildrenState(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
this.resetChildState(gameObjects[i]);
}
return this;
},
syncProperties() {
this
.syncPosition()
.syncVisible()
.syncAlpha()
.syncActive()
.syncScrollFactor()
.syncMask();
return this;
}
};
var Transform = {
worldToLocal(point) {
// Transform
point.x -= this.x;
point.y -= this.y;
// Rotate
var c = Math.cos(-this.rotation);
var s = Math.sin(-this.rotation);
var tx = point.x;
var ty = point.y;
point.x = tx * c - ty * s;
point.y = tx * s + ty * c;
// Scale
point.x /= this.scaleX;
point.y /= this.scaleY;
return point;
},
localToWorld(point) {
// Scale
point.x *= this.scaleX;
point.y *= this.scaleY;
// Rotate
var c = Math.cos(this.rotation);
var s = Math.sin(this.rotation);
var tx = point.x;
var ty = point.y;
point.x = tx * c - ty * s;
point.y = tx * s + ty * c;
// Transform
point.x += this.x;
point.y += this.y;
return point;
}
};
var GetScale = function (a, b) {
if (a === b) {
return 1;
} else {
return a / b;
}
};
var Position = {
updateChildPosition(child) {
if (child.isRexContainerLite) {
child.syncChildrenEnable = false;
}
var localState = GetLocalState(child);
var parent = localState.parent;
if (localState.syncPosition) {
child.x = localState.x;
child.y = localState.y;
parent.localToWorld(child);
}
if (localState.syncRotation) {
child.rotation = localState.rotation + parent.rotation;
}
if (localState.syncScale) {
child.scaleX = localState.scaleX * parent.scaleX;
child.scaleY = localState.scaleY * parent.scaleY;
}
if (child.isRexContainerLite) {
child.syncChildrenEnable = true;
child.syncPosition();
}
return this;
},
syncPosition() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildPosition, this);
}
return this;
},
resetChildPositionState(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
localState.x = child.x;
localState.y = child.y;
parent.worldToLocal(localState);
localState.scaleX = GetScale(child.scaleX, parent.scaleX);
localState.scaleY = GetScale(child.scaleY, parent.scaleY);
localState.rotation = child.rotation - parent.rotation;
return this;
},
setChildPosition(child, x, y) {
child.x = x;
child.y = y;
this.resetChildPositionState(child);
return this;
},
setChildLocalPosition(child, x, y) {
var localState = GetLocalState(child);
localState.x = x;
localState.y = y;
this.updateChildPosition(child);
return this;
},
resetLocalPositionState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildPositionState(this);
}
return this;
},
getChildLocalX(child) {
var localState = GetLocalState(child);
return localState.x;
},
getChildLocalY(child) {
var localState = GetLocalState(child);
return localState.y;
},
};
const DegToRad$1 = Phaser.Math.DegToRad;
var Rotation = {
updateChildRotation(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
if (localState.syncRotation) {
child.rotation = parent.rotation + localState.rotation;
}
return this;
},
syncRotation() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildRotation, this);
}
return this;
},
resetChildRotationState(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
localState.rotation = child.rotation - parent.rotation;
return this;
},
setChildRotation(child, rotation) {
child.rotation = rotation;
this.resetChildRotationState(child);
return this;
},
setChildAngle(child, angle) {
child.angle = angle;
this.resetChildRotationState(child);
return this;
},
setChildLocalRotation(child, rotation) {
var localState = GetLocalState(child);
localState.rotation = rotation;
this.updateChildRotation(child);
return this;
},
setChildLocalAngle(child, angle) {
var localState = GetLocalState(child);
localState.rotation = DegToRad$1(angle);
this.updateChildRotation(child);
return this;
},
resetLocalRotationState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildRotationState(this);
}
return this;
},
getChildLocalRotation(child) {
var localState = GetLocalState(child);
return localState.rotation;
},
};
var Scale$1 = {
updateChildScale(child) {
var state = GetLocalState(child);
var parent = state.parent;
if (state.syncScale) {
child.scaleX = parent.scaleX * state.scaleX;
child.scaleY = parent.scaleY * state.scaleY;
}
return this;
},
syncScale() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildScale, this);
}
return this;
},
resetChildScaleState(child) {
var state = GetLocalState(child);
var parent = state.parent;
state.scaleX = GetScale(child.scaleX, parent.scaleX);
state.scaleY = GetScale(child.scaleY, parent.scaleY);
return this;
},
setChildScale(child, scaleX, scaleY) {
if (scaleY === undefined) {
scaleY = scaleX;
}
child.scaleX = scaleX;
child.scaleY = scaleY;
this.resetChildScaleState(child);
return this;
},
setChildLocalScale(child, scaleX, scaleY) {
if (scaleY === undefined) {
scaleY = scaleX;
}
var state = GetLocalState(child);
state.scaleX = scaleX;
state.scaleY = scaleY;
this.updateChildScale(child);
return this;
},
setChildDisplaySize(child, width, height) {
child.setDisplaySize(width, height);
this.resetChildScaleState(child);
return this;
},
resetLocalScaleState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildScaleState(this);
}
return this;
},
getChildLocalScaleX(child) {
var localState = GetLocalState(child);
return localState.scaleX;
},
getChildLocalScaleY(child) {
var localState = GetLocalState(child);
return localState.scaleY;
},
};
/*
Visible in localState:
- visible: original visible of child
- maskVisible: invisible by parent mask, see MaskChildren.js
- undefined (not in masking) : Equal to mask visible
- true (mask visible) : Inside, or across parent's visible area
- false (maske invisible) : Out of parent's visible area
Visible result of child = (parent visible) && (child visible) && (mask visible)
*/
var Visible = {
updateChildVisible(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
var maskVisible = (localState.hasOwnProperty('maskVisible')) ? localState.maskVisible : true;
var parentVisible = (parent) ? parent.visible : true;
child.visible = parentVisible && localState.visible && maskVisible;
return this;
},
syncVisible() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildVisible, this);
}
return this;
},
resetChildVisibleState(child) {
var localState = GetLocalState(child);
// Delete maskVisible property
if (localState.hasOwnProperty('maskVisible')) {
delete localState.maskVisible;
}
localState.visible = child.visible;
return this;
},
setChildVisible(child, visible) {
// Visible of child will be affect by parent's visible, and mask visible
this.setChildLocalVisible(child, visible);
return this;
},
// Internal method
setChildLocalVisible(child, visible) {
if (visible === undefined) {
visible = true;
}
var localState = GetLocalState(child);
localState.visible = visible;
this.updateChildVisible(child);
return this;
},
// Internal method
setChildMaskVisible(child, visible) {
if (visible === undefined) {
visible = true;
}
var localState = GetLocalState(child);
localState.maskVisible = visible;
this.updateChildVisible(child);
return this;
},
resetLocalVisibleState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildVisibleState(this);
}
return this;
},
getChildLocalVisible(child) {
var localState = GetLocalState(child);
return localState.visible;
},
};
var Alpha = {
updateChildAlpha(child) {
var state = GetLocalState(child);
var parent = state.parent;
if (state.syncAlpha) {
child.alpha = parent.alpha * state.alpha;
}
return this;
},
syncAlpha() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildAlpha, this);
}
return this;
},
resetChildAlphaState(child) {
var state = GetLocalState(child);
var parent = state.parent;
state.alpha = GetScale(child.alpha, parent.alpha);
return this;
},
setChildAlpha(child, alpha) {
child.alpha = alpha;
this.resetChildAlphaState(child);
return this;
},
setChildLocalAlpha(child, alpha) {
var state = GetLocalState(child);
state.alpha = alpha;
this.updateChildAlpha(child);
return this;
},
resetLocalAlphaState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildAlphaState(this);
}
return this;
},
getChildLocalAlpha(child) {
var localState = GetLocalState(child);
return localState.alpha;
},
};
var Active = {
updateChildActive(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
child.active = parent.active && localState.active;
return this;
},
syncActive() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildActive, this);
}
return this;
},
resetChildActiveState(child) {
var localState = GetLocalState(child);
localState.active = child.active;
return this;
},
setChildActive(child, active) {
child.active = active;
this.resetChildActiveState(child);
return this;
},
setChildLocalActive(child, active) {
if (active === undefined) {
active = true;
}
var localState = GetLocalState(child);
localState.active = active;
this.updateChildActive(child);
return this;
},
resetLocalActiveState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildActiveState(this);
}
return this;
},
getChildLocalActive(child) {
var localState = GetLocalState(child);
return localState.active;
},
};
var ScrollFactor = {
updateChildScrollFactor(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
if (localState.syncScrollFactor) {
child.scrollFactorX = parent.scrollFactorX;
child.scrollFactorY = parent.scrollFactorY;
}
return this;
},
syncScrollFactor() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildScrollFactor, this);
}
return this;
},
};
var CameraFilter = {
updateCameraFilter(child) {
var state = GetLocalState(child);
var parent = state.parent;
if (state.syncCameraFilter) {
child.cameraFilter = parent.cameraFilter;
}
return this;
},
syncCameraFilter() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateCameraFilter, this);
}
return this;
},
};
// canvas mask only
var Mask = {
updateChildMask(child) {
// Don't propagate null mask to clear children's mask
if (this.mask == null) {
return this;
}
var maskGameObject = (this.mask.hasOwnProperty('geometryMask')) ? this.mask.geometryMask : this.mask.bitmapMask;
if (maskGameObject !== child) {
child.mask = this.mask;
}
return this;
},
syncMask() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildMask, this);
}
return this;
},
setMask(mask) {
this.mask = mask;
return this;
},
clearMask(destroyMask) {
if (destroyMask === undefined) {
destroyMask = false;
}
var self = this;
// Clear current mask
this._mask = null;
this.setChildMaskVisible(this);
// Also set maskVisible to `true`
this.children.forEach(function (child) {
// Clear child's mask
if (child.clearMask) {
child.clearMask(false);
}
if (!child.hasOwnProperty('isRexContainerLite')) {
self.setChildMaskVisible(child);
// Set child's maskVisible to `true`
}
});
if (destroyMask && this.mask) {
this.mask.destroy();
}
return this;
},
};
var SortGameObjectsByDepth = function (gameObjects, descending) {
if (gameObjects.length <= 1) {
return gameObjects;
}
if (descending === undefined) {
descending = false;
}
var itemList;
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
var gameObject = gameObjects[i];
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
}
if (itemList) {
break;
}
}
if (!itemList) {
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 FilterDisplayGameObjects = function (gameObjects) {
return gameObjects.filter(function (gameObject) {
if (gameObject.displayList) {
// Inside a scene or a layer
return true;
} else if (gameObject.parentContainer) {
// Inside a container
return true;
}
})
};
var Depth = {
setDepth(value, containerOnly) {
this.depth = value;
if (!containerOnly && this.children) {
var children = this.getAllChildren();
for (var i = 0, cnt = children.length; i < cnt; i++) {
children[i].depth = value;
}
}
return this;
},
swapDepth(containerB) {
var depthA = this.depth;
var depthB = containerB.depth;
this.setDepth(depthB);
containerB.setDepth(depthA);
return this;
},
incDepth(inc) {
this.depth += inc;
if (this.children) {
var children = this.getAllChildren();
for (var i = 0, cnt = children.length; i < cnt; i++) {
children[i].depth += inc;
}
}
return this;
},
bringToTop() {
var displayList = this.displayList;
if (!displayList) {
return this;
}
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, false);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.bringToTop(child);
}
}
return this;
},
bringMeToTop() {
return this.bringToTop();
},
sendToBack() {
var displayList = this.displayList;
if (!displayList) {
return this;
}
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, true);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.sendToBack(child);
}
}
return this;
},
sendMeToBack() {
return this.sendToBack();
},
moveDepthBelow(gameObject) {
var displayList = this.displayList;
if (!displayList) {
return this;
}
if (gameObject.displayList !== displayList) {
// Do nothing if not at the same display list
return this;
}
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, false);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.moveBelow(gameObject, child);
break;
}
}
return this;
},
moveMyDepthBelow(gameObject) {
return this.moveDepthBelow(gameObject);
},
moveDepthAbove(gameObject) {
var displayList = this.displayList;
if (!displayList) {
return this;
}
if (gameObject.displayList !== displayList) {
// Do nothing if not at the same display list
return this;
}
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, true);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.moveAbove(gameObject, child);
break;
}
}
return this;
},
moveMyDepthAbove(gameObject) {
return this.moveDepthAbove(gameObject);
},
bringChildToTop(child) {
var gameObjects;
if ((child !== this) && child.isRexContainerLite) {
gameObjects = child.getAllChildren([child]);
gameObjects = FilterDisplayGameObjects(gameObjects);
gameObjects = SortGameObjectsByDepth(gameObjects, false);
} else {
gameObjects = [child];
}
var children = this.getAllChildren([this]);
children = FilterDisplayGameObjects(children);
children = SortGameObjectsByDepth(children, false);
var topChild = children[children.length - 1];
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
var gameObject = gameObjects[i];
if (topChild === gameObject) {
continue;
}
if ((gameObject !== this) && (topChild.displayList !== gameObject.displayList)) {
continue;
}
topChild.displayList.moveAbove(gameObject, topChild);
topChild = gameObject;
}
return this;
},
sendChildToBack(child) {
var gameObjects;
if ((child !== this) && child.isRexContainerLite) {
gameObjects = child.getAllChildren([child]);
gameObjects = FilterDisplayGameObjects(gameObjects);
gameObjects = SortGameObjectsByDepth(gameObjects, false);
} else {
gameObjects = [child];
}
var children = this.getAllChildren([this]);
children = FilterDisplayGameObjects(children);
children = SortGameObjectsByDepth(children, false);
var bottomChild = children[0];
for (var i = gameObjects.length - 1; i >= 0; i--) {
var gameObject = gameObjects[i];
if (bottomChild === gameObject) {
continue;
}
if ((gameObject !== this) && (bottomChild.displayList !== gameObject.displayList)) {
continue;
}
bottomChild.displayList.moveBelow(gameObject, bottomChild);
bottomChild = gameObject;
}
return this;
},
};
var DepthFirstSearch = function (root, callback) {
var skip = callback(root);
if ((!skip) && root.isRexContainerLite) {
var children = root.children;
for (var i = 0, cnt = children.length; i < cnt; i++) {
DepthFirstSearch(children[i], callback);
}
}
};
var BreadthFirstSearch = function (root, callback) {
var queue = [root];
while (queue.length > 0) {
var current = queue.shift();
var skip = callback(current);
if ((!skip) && current.isRexContainerLite) {
queue.push(...current.children);
}
}
};
const ArrayUtils = Phaser.Utils.Array;
var Children = {
getChildren(out) {
if (!out) {
out = this.children; // Return internal children array
} else {
for (var i = 0, cnt = this.children.length; i < cnt; i++) {
out.push(this.children[i]);
}
// Copy children
}
return out;
},
getAllChildren(out) {
if (out === undefined) {
out = [];
}
var root = this;
BreadthFirstSearch(root, function (child) {
// Don't add root
if (child === root) {
return;
}
out.push(child);
});
return out;
},
getAllVisibleChildren(out) {
if (out === undefined) {
out = [];
}
var root = this;
BreadthFirstSearch(root, function (child) {
// Don't add root
if (child === root) {
return;
}
// Don't add invisible child
if (!child.visible) {
return true;
}
out.push(child);
});
return out;
},
bfs(callback, root) {
if (root === undefined) {
root = this;
}
BreadthFirstSearch(root, callback);
return this;
},
dfs(callback, root) {
if (root === undefined) {
root = this;
}
DepthFirstSearch(root, callback);
return this;
},
contains(gameObject) { // Override Base.contains method
var parent = GetParent$1(gameObject);
if (!parent) {
return false;
} else if (parent === this) {
return true;
} else {
return this.contains(parent);
}
},
getByName(name, recursive) {
if (!recursive) {
return ArrayUtils.GetFirst(this.children, 'name', name); // object, or null if not found
} else { // recursive
// Breadth-first search
var queue = [this];
var parent, child;
while (queue.length) {
parent = queue.shift();
for (var i = 0, cnt = parent.children.length; i < cnt; i++) {
child = parent.children[i];
if (child.name === name) {
return child;
} else if (child.isRexContainerLite) {
queue.push(child);
}
}
}
return null;
}
},
getRandom(startIndex, length) {
return ArrayUtils.GetRandom(this.children, startIndex, length);
},
getFirst(property, value, startIndex, endIndex) {
return ArrayUtils.GetFirstElement(this.children, property, value, startIndex, endIndex);
},
getAll(property, value, startIndex, endIndex) {
return ArrayUtils.GetAll(this.children, property, value, startIndex, endIndex);
},
count(property, value, startIndex, endIndex) {
return ArrayUtils.CountAllMatching(this.children, property, value, startIndex, endIndex);
},
swap(child1, child2) {
ArrayUtils.Swap(this.children, child1, child2);
return this;
},
setAll(property, value, startIndex, endIndex) {
ArrayUtils.SetAll(this.children, property, value, startIndex, endIndex);
return this;
},
};
var GetLocalStates = function (gameObjects) {
var localStates = [];
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
var gameObject = gameObjects[i];
if (!gameObject.hasOwnProperty('rexContainer')) {
continue;
}
localStates.push(gameObject.rexContainer);
}
return localStates;
};
var GetScene = function (gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
var scene = gameObjects[i].scene;
if (scene) {
return scene;
}
}
return null;
};
var UpdateChild = function (tween, key, target) {
if (!target.parent) {
// target object was removed, so remove this tween too
tween.remove();
return;
}
var parent = target.parent;
var child = target.self;
switch (key) {
case 'x':
case 'y':
parent.updateChildPosition(child);
break;
case 'angle':
case 'rotation':
parent.updateChildRotation(child);
break;
case 'scaleX':
case 'scaleY':
case 'displayWidth':
case 'displayHeight':
parent.updateChildScale(child);
break;
case 'alpha':
parent.updateChildAlpha(child);
break;
default:
parent.updateChildPosition(child);
parent.updateChildRotation(child);
parent.updateChildScale(child);
parent.updateChildAlpha(child);
break;
}
};
var Tween = {
tweenChild(tweenConfig) {
var targets = tweenConfig.targets;
if (!Array.isArray(targets)) {
targets = [targets];
}
var scene = this.scene || GetScene(targets);
if (!scene) {
return;
}
// Map child game objects to local states
tweenConfig.targets = GetLocalStates(targets);
var tween = scene.tweens.add(tweenConfig);
// Update child game object in 'update' event
tween.on('update', UpdateChild);
return tween;
},
tweenSelf(tweenConfig) {
tweenConfig.targets = [this];
return this.tweenChild(tweenConfig);
},
createTweenChildConfig(tweenConfig) {
var targets = tweenConfig.targets;
if (targets) {
if (!Array.isArray(targets)) {
targets = [targets];
}
// Map child game objects to local states
tweenConfig.targets = GetLocalStates(targets);
}
var onUpdate = tweenConfig.onUpdate;
tweenConfig.onUpdate = function (tween, target) {
if (onUpdate) {
onUpdate(tween, target);
}
UpdateChild(tween, undefined, target);
};
return tweenConfig;
},
tween(tweenConfig) {
var scene = this.scene;
if (!tweenConfig.targets) {
tweenConfig.targets = this;
}
return scene.tweens.add(tweenConfig);
},
};
const ContainerClass = Phaser.GameObjects.Container;
var IsContainerGameObject = function (gameObject) {
return (gameObject instanceof ContainerClass);
};
const LayerClass$1 = Phaser.GameObjects.Layer;
var IsLayerGameObject = function (gameObject) {
return (gameObject instanceof LayerClass$1);
};
var GetValidChildren = function (parent) {
var children = parent.getAllChildren([parent]);
children = children.filter(function (gameObject) {
return !!gameObject.displayList || // At scene's displayList or at a layer
!!gameObject.parentContainer; // At a container
});
return children;
};
var AddToContainer = function (p3Container) {
var gameObjects = GetValidChildren(this);
// This containerLite parent should be considered.
if (gameObjects.indexOf(this) === -1) {
gameObjects.push(this);