@mai3/phaser-sdk
Version:
A UI component library based on the Phaser game engine
98 lines (97 loc) • 4.31 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 __());
};
})();
import Phaser from "phaser";
import ResizableComponentManager from "../utils/ResizableComponentManager";
import UIComponentFactory from "../utils/UIComponentFactory";
var BaseScene = /** @class */ (function (_super) {
__extends(BaseScene, _super);
function BaseScene(key, width, height) {
var _this = _super.call(this, { key: key }) || this;
_this.isDebugPrint = true;
_this.width = width;
_this.height = height;
_this.resizableManager = new ResizableComponentManager(_this);
return _this;
}
BaseScene.prototype.create = function () { };
BaseScene.prototype.preload = function () {
if (this.isDebugPrint) {
this.setupDebugEnvironment();
}
};
BaseScene.prototype.setupDebugEnvironment = function () {
var _this = this;
var bg = this.add
.rectangle(0, 0, this.width || this.scale.width, this.height || this.scale.height, 0x434349)
.setOrigin(0, 0)
.setInteractive()
.setDepth(-1);
["pointerdown", "pointerup", "pointermove"].forEach(function (event) {
bg.on(event, _this.printPointer, _this);
});
this.printer = this.add.text(1, 1, "pointer: 0, 0", {
fontSize: "18px",
color: "#ffffff",
});
};
BaseScene.prototype.printPointer = function (pointer) {
var _a;
(_a = this.printer) === null || _a === void 0 ? void 0 : _a.setText("pointer: ".concat(pointer.x.toFixed(2), ", ").concat(pointer.y.toFixed(2)));
};
BaseScene.prototype.indexOfComponent = function (component) {
return this.resizableManager.components.indexOf(component);
};
BaseScene.prototype.reDrawDragResizeComponent = function (component) {
var _a;
var index = this.indexOfComponent(component);
(_a = this.resizableManager) === null || _a === void 0 ? void 0 : _a.updateResizeHandles(index);
};
BaseScene.prototype.switchDragResizeComponent = function (component) {
var _a, _b;
(_a = this.resizableManager) === null || _a === void 0 ? void 0 : _a.clear();
(_b = this.resizableManager) === null || _b === void 0 ? void 0 : _b.addComponent(component);
};
BaseScene.prototype.addDragResizeComponent = function (component) {
var _a;
(_a = this.resizableManager) === null || _a === void 0 ? void 0 : _a.addComponent(component);
};
BaseScene.prototype.addDragResizeComponents = function (components) {
var _this = this;
components.forEach(function (item) {
var _a;
(_a = _this.resizableManager) === null || _a === void 0 ? void 0 : _a.addComponent(item);
});
};
BaseScene.prototype.clearDragResizeComponents = function () {
var _a;
(_a = this.resizableManager) === null || _a === void 0 ? void 0 : _a.clear();
};
BaseScene.prototype.setChildren = function (parent, childConfigs) {
if (!parent || !childConfigs)
return;
for (var _i = 0, childConfigs_1 = childConfigs; _i < childConfigs_1.length; _i++) {
var config = childConfigs_1[_i];
var child = UIComponentFactory.createChildFromConfig(this, config);
parent.addChild(child);
}
};
BaseScene.prototype.getChild = function (childConfig) {
var child = UIComponentFactory.createChildFromConfig(this, childConfig);
return child;
};
return BaseScene;
}(Phaser.Scene));
export default BaseScene;