UNPKG

@mai3/phaser-sdk

Version:

A UI component library based on the Phaser game engine

87 lines (86 loc) 4.05 kB
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 { Container } from "./Container"; import Utils from "../utils"; var BaseButton = /** @class */ (function (_super) { __extends(BaseButton, _super); function BaseButton(scene, baseConfig, type) { var _this = _super.call(this, scene, baseConfig, type) || this; _this._baseConfig = baseConfig; return _this; } BaseButton.prototype.initializeEvents = function () { _super.prototype.initializeEvents.call(this); this.setEventInteractive(); this.setupEventListeners(); }; BaseButton.prototype.setupEventListeners = function () { this.off("pointerover", this.handleOver, this); this.off("pointerout", this.handleOut, this); this.off("pointerdown", this.handleDown, this); this.off("pointerup", this.handleUp, this); this.off("pointerupoutside", this.handleUp, this); this.on("pointerover", this.handleOver, this); this.on("pointerout", this.handleOut, this); this.on("pointerdown", this.handleDown, this); this.on("pointerup", this.handleUp, this); this.on("pointerupoutside", this.handleUp, this); }; BaseButton.prototype.handleOver = function () { var _a, _b; this.handleEvent((_a = this._baseConfig) === null || _a === void 0 ? void 0 : _a.handleHover); if ((_b = this._baseConfig) === null || _b === void 0 ? void 0 : _b.enableSmoothScaleAnim) { Utils.smoothScale(this.scene.tweens, this, 1.02, 125); } }; BaseButton.prototype.handleOut = function () { var _a, _b; this.handleEvent((_a = this._baseConfig) === null || _a === void 0 ? void 0 : _a.handleOut); this.lastAlpha && (this.alpha = this.lastAlpha) && (this.lastAlpha = undefined); if ((_b = this._baseConfig) === null || _b === void 0 ? void 0 : _b.enableSmoothScaleAnim) { Utils.smoothScale(this.scene.tweens, this, 1, 125); } }; BaseButton.prototype.handleDown = function () { var _a, _b; this.handleEvent((_a = this._baseConfig) === null || _a === void 0 ? void 0 : _a.handleDown); this.lastAlpha = this.alpha; this.alpha = 0.5; if ((_b = this._baseConfig) === null || _b === void 0 ? void 0 : _b.enableSmoothScaleAnim) { Utils.smoothScale(this.scene.tweens, this, 0.95, 125); } }; BaseButton.prototype.handleUp = function () { var _a, _b; this.handleEvent((_a = this._baseConfig) === null || _a === void 0 ? void 0 : _a.handleUp); this.lastAlpha && (this.alpha = this.lastAlpha) && (this.lastAlpha = undefined); if ((_b = this._baseConfig) === null || _b === void 0 ? void 0 : _b.enableSmoothScaleAnim) { Utils.smoothScale(this.scene.tweens, this, 1, 125); } }; BaseButton.prototype.handleEvent = function (handle) { if (handle === null || handle === void 0 ? void 0 : handle.audio) { this.scene.sound.play(handle.audio); } if (handle === null || handle === void 0 ? void 0 : handle.handleFn) { handle.handleFn(); } this.blendMode = Phaser.BlendModes.NORMAL; }; return BaseButton; }(Container)); export { BaseButton };