declare type Maybe<T> = T | null;
declare type Builder<T> = (...args: any[]) => T;
declare class Window_Draggable {
dragableRect: Rectangle;
updateDrag(): void;
}
const setNullDefault = <T extends any>(value: Maybe<T>, defaultValue: T) => (value === null ? defaultValue : value);
const extendsDraggableWindowClass = (WindowClass: typeof Window_Base): typeof Window_Base =>
class Window_Draggable extends WindowClass implements Window_Draggable {
static draggingWin: Maybe<Window_Draggable> = null;
private _dragX: Maybe<number> = null;
private _dragY: Maybe<number> = null;
private _dragging: boolean = false;
get dragableRect() {
return new Rectangle(this.x, this.y, this.width, this.height);
}
constructor(...args: any[]) {
super(...args);
}
update() {
super.update();
this.updateDrag();
}
updateDrag() {
const isInside = this.dragableRect.contains(TouchInput.x, TouchInput.y);
const isTriggered = TouchInput.isTriggered();
const isReleased = TouchInput.isReleased();
const isPressed = TouchInput.isPressed();
const draggingWin = Window_Draggable.draggingWin;
if (isTriggered && isInside) {
this._dragX = this.canvasToLocalX(TouchInput.x);
this._dragY = this.canvasToLocalY(TouchInput.y);
this._dragging = true;
const list = SceneManager._scene._windowLayer.children;
list.sort((a, b) => Number(a === this) - Number(b === this));
Window_Draggable.draggingWin = this;
} else if (isPressed && this._dragging && draggingWin === this) {
this.x = TouchInput.x - setNullDefault(this._dragX, 0);
this.y = TouchInput.y - setNullDefault(this._dragY, 0);
} else if (isReleased) {
this._dragging = false;
}
}
};
"use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var setNullDefault = function (value, defaultValue) { return (value === null ? defaultValue : value); }; var extendsDraggableWindowClass = function (WindowClass) { var _a; return _a = (function (_super) { __extends(Window_Draggable, _super); function Window_Draggable() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var _this = _super.apply(this, args) || this; _this._dragX = null; _this._dragY = null; _this._dragging = false; return _this; } Object.defineProperty(Window_Draggable.prototype, "dragableRect", { get: function () { return new Rectangle(this.x, this.y, this.width, this.height); }, enumerable: false, configurable: true }); Window_Draggable.prototype.update = function () { _super.prototype.update.call(this); this.updateDrag(); }; Window_Draggable.prototype.updateDrag = function () { var _this = this; var isInside = this.dragableRect.contains(TouchInput.x, TouchInput.y); var isTriggered = TouchInput.isTriggered(); var isReleased = TouchInput.isReleased(); var isPressed = TouchInput.isPressed(); var draggingWin = Window_Draggable.draggingWin; if (isTriggered && isInside) { this._dragX = this.canvasToLocalX(TouchInput.x); this._dragY = this.canvasToLocalY(TouchInput.y); this._dragging = true; var list = SceneManager._scene._windowLayer.children; list.sort(function (a, b) { return Number(a === _this) - Number(b === _this); }); Window_Draggable.draggingWin = this; } else if (isPressed && this._dragging && draggingWin === this) { this.x = TouchInput.x - setNullDefault(this._dragX, 0); this.y = TouchInput.y - setNullDefault(this._dragY, 0); } else if (isReleased) { this._dragging = false; } }; return Window_Draggable; }(WindowClass)), _a.draggingWin = null, _a; };
js │ main.js │ plugins.js │ rpg_core.js │ rpg_managers.js │ rpg_objects.js │ rpg_scenes.js │ rpg_sprites.js │ rpg_windows.js │ ├─libs │ fpsmeter.js │ iphone-inline-video.browser.js │ lodash.min.js │ lz-string.js │ pixi-picture.js │ pixi-tilemap.js │ pixi.js │ ├─notes │ index.txt │ ├─plugins │ CleanWindow.js │ └─src CleanWindow.ts rpg_core.d.ts rpg_managers.d.ts rpg_windows.d.ts
walf_man 发表于 2020-6-9 17:12
大佬不愧是大佬,不过还是感觉js代码看起来好看一些呀,这ts完全就看不懂了
不禁感叹,为何要发明 ...
zths 发表于 2020-6-9 17:19
所以就是 所谓的 封装 封装 再 封装。
语言语言套语言。
最后写个 hello world 都要 1GB ...(过分了 ...
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |