@mai3/phaser-sdk
Version:
A UI component library based on the Phaser game engine
108 lines (107 loc) • 4.16 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { Container } from "../../ui/Container";
/**
* Base container class that extends Phaser Container and implements ReDrawProtocol
* Provides basic container functionality with config management
*/
var BaseContainer = /** @class */ (function (_super) {
__extends(BaseContainer, _super);
function BaseContainer() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Updates the container configuration
* @param config - New configuration to apply
*/
BaseContainer.prototype.updateConfig = function (config) {
this._config = config;
};
BaseContainer.prototype.setPosition = function (x, y, z, w) {
_super.prototype.setPosition.call(this, x, y, z, w);
this.config.x = x;
this.config.y = y;
return this;
};
Object.defineProperty(BaseContainer.prototype, "config", {
/**
* Gets the current container config
* @returns The current config or empty object if none set
*/
get: function () {
var _a;
return (_a = this._config) !== null && _a !== void 0 ? _a : {};
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "content", {
get: function () {
return this._content;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseContainer.prototype, "realChildConfigs", {
/**
* Gets the real child configurations by recursively traversing the container tree
* @returns Array of BaseConfig objects representing the current container hierarchy
*/
get: function () {
var buildConfigTree = function (container) {
if (!(container instanceof Container)) {
return [];
}
var children = container.getAll();
return children.reduce(function (acc, child) {
var config = child.config;
if (!config) {
return acc;
}
var childConfig = __assign({}, config);
var subConfigs = buildConfigTree(child);
if (subConfigs.length > 0) {
childConfig.childConfigs = subConfigs;
}
acc.push(childConfig);
return acc;
}, []);
};
return this._content ? buildConfigTree(this._content) : [];
},
enumerable: false,
configurable: true
});
BaseContainer.prototype.destroy = function (fromScene) {
var _a;
_super.prototype.destroy.call(this, fromScene);
(_a = this._content) === null || _a === void 0 ? void 0 : _a.destroy(fromScene);
this._content = undefined;
};
return BaseContainer;
}(Phaser.GameObjects.Container));
export { BaseContainer };