猫史档案馆


gui小小介绍

用户:烟魂烟魂查看:2 回复:4 评论:2 创建时间:2023-08-13T09:56:06



回复

上一页1 页 / 共 1下一页
烟魂烟魂

"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 (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 __());
    };
})();
exports.__esModule = true;
//@ts-nocheck
/* ********************************************
 * Box3EasyGUI.js Version 1.1.0 by 编码喵
* ********************************************/
//require("./api");
var Box3EasyGUI = /** @class */ (function () {
    function Box3EasyGUI(name, entity) {
        this.name = name;
        this.entity = entity;
        this.document = new GUIDocument(this);
        this.rendered = false;
    }
    Box3EasyGUI.prototype.render = function () {
        var _a;
        this.rendered = true;
        gui.init(this.entity, (_a = {},
            _a[this.name] = {
                bindings: this.document.getBindings(),
                display: true,
                data: this.document.toString()
            },
            _a));
    };
    Box3EasyGUI.prototype.reload = function () {
        if (this.document.childrens.length < 1)
            return;
        for (var _i = 0, _a = this.document.childrens; _i < _a.length; _i++) {
            var i = _a[_i];
            gui.remove(this.entity, i.selector);
        }
        this.render();
    };
    return Box3EasyGUI;
}());
module.exports = { Box3EasyGUI: Box3EasyGUI, GUINode: GUINode, NodeEventListener: NodeEventListener, GUIDocument: GUIDocument };
function key(node) {
    if (!node.parent)
        throw new Error("this element have not been append to other elements.So,please append to other elements and then make a key for this elements!");
    var length = 16;
    var k = "";
    var a = [[48, 57], [65, 90], [97, 122]];
    for (var i = 0; i < length; i++) {
        var r = a[Math.floor(Math.random() * 3)];
        k += String.fromCharCode(Math.floor(Math.random() * (r[1] - r[0])) + r[0]);
    }
    if (node.gui && node.gui.document.getElementByKey(k) != null)
        return key(node);
    else
        return k;
}
var GUINode = /** @class */ (function () {
    function GUINode(name, attributes) {
        this.name = name;
        this.attributes = attributes;
        this.childrens = [];
        this.listeners = [];
        this.getSelector = function () {
            return this.name + "[guiKey=\"" + this.attributes.guiKey + "\"]";
        };
    }
    GUINode.prototype.toString = function () {
        var a = "", c = "";
        for (var i in this.attributes)
            a += " " + i + "=" + "\"" + this.attributes[i] + "\"";
        for (var _i = 0, _a = this.childrens; _i < _a.length; _i++) {
            var i = _a[_i];
            c += i.toString();
        }
        return "<" + this.name + a + ">\r\n" + c + "</" + this.name + ">\r\n";
    };
    GUINode.prototype.getEventListeners = function () {
        var b = this.listeners;
        for (var _i = 0, _a = this.childrens; _i < _a.length; _i++) {
            var i = _a[_i];
            b = b.concat(i.getEventListeners());
        }
        return b;
    };
    GUINode.prototype.appendChild = function (node) {
        if (node.selector)
            throw new Error("this element has been appended to another element.");
        this.childrens.push(node);
        node.parent = this;
        node.gui = this.gui;
        function setGUI(node, a) {
            for (var _i = 0, _a = node.childrens; _i < _a.length; _i++) {
                var i = _a[_i];
                i.gui = a, setGUI(i, a);
            }
        }
        if (this.gui)
            setGUI(node, this.gui);
        node.attributes.guiKey = key(node);
        node.selector = node.getSelector();
        return this;
    };
    GUINode.prototype.remove = function () {
        var pos = this.parent.childrens.indexOf(this);
        if (pos == -1)
            throw new Error("can not find this element in " + this.parent.selector + ".Please check have you ever appended this element.");
        this.parent.childrens.splice(pos, 1);
        if (this.gui && this.gui.rendered)
            gui.remove(this.gui.entity, this.selector);
        delete this;
    };
    GUINode.prototype.addEventListener = function (e, listener) {
        var _this = this;
        this.listeners.push(new NodeEventListener(e, listener, this));
        gui.onMessage(function (data) {
            if (data.name == _this.getSelector())
                listener(data);
        });
    };
    GUINode.prototype.setAttribute = function (a, b) {
        this.attributes[a] = String(b);
        if (this.gui && this.gui.rendered)
            gui.setAttribute(this.gui.entity, this.selector, a, b);
    };
    GUINode.prototype.removeAttribute = function (a) {
        this.attributes[a] && function (b) {
            if (b.gui && b.gui.rendered)
                gui.setAttribute(b.gui.entity, b.selector, a, "");
            delete this.attributes[a];
        }(this);
    };
    GUINode.prototype.show = function () {
        this.setAttribute("display", "block");
        this.setAttribute("height", this.attributes.height0);
        this.setAttribute("width", this.attributes.width0);
        this.setAttribute("height0", "");
        this.setAttribute("width0", "");
    };
    GUINode.prototype.hide = function () {
        this.setAttribute("display", "none");
        this.setAttribute("height0", this.attributes.height);
        this.setAttribute("width0", this.attributes.width);
        this.setAttribute("height", "0");
        this.setAttribute("width", "0");
    };
    return GUINode;
}());
var NodeEventListener = /** @class */ (function () {
    function NodeEventListener(e, listener, node) {
        this.event = e;
        this.listener = listener;
        this.node = node;
    }
    return NodeEventListener;
}());
var GUIDocument = /** @class */ (function (_super) {
    __extends(GUIDocument, _super);
    function GUIDocument(gui) {
        var _this = _super.call(this, "document", {}) || this;
        _this.selector = "document";
        _this.gui = gui;
        _this.getSelector = undefined;
        return _this;
    }
    GUIDocument.prototype.toString = function () {
        var c = "";
        for (var _i = 0, _a = this.childrens; _i < _a.length; _i++) {
            var i = _a[_i];
            c += i.toString();
        }
        return c;
    };
    GUIDocument.prototype.createXml = function (name, attributes) {
        return new GUINode(name, attributes);
    };
    GUIDocument.prototype.getBindings = function () {
        var e = this.getEventListeners(), b = new Array();
        for (var _i = 0, e_1 = e; _i < e_1.length; _i++) {
            var i = e_1[_i];
            var s = i.node.getSelector();
            b.push({ action: "sendMessage", event: i.event, messageName: s, selector: s });
        }
        return b;
    };
    GUIDocument.prototype.remove = function () {
        throw new Error("can not remove document!");
    };
    GUIDocument.prototype.getElementById = function (id) {
        var e = null;
        function find(node, id) {
            for (var _i = 0, _a = node.childrens; _i < _a.length; _i++) {
                var i = _a[_i];
                if (i.attributes.id == id)
                    return e = i;
                find(i, id);
            }
        }
        find(this, id);
        return e;
    };
    GUIDocument.prototype.getElementByKey = function (key) {
        var e = null;
        function find(node, key) {
            for (var _i = 0, _a = node.childrens; _i < _a.length; _i++) {
                var i = _a[_i];
                if (i.attributes.key == key)
                    return e = i;
                find(i, key);
            }
        }
        find(this, key);
        return e;
    };
    GUIDocument.prototype.getElementsByName = function (name) {
        var e = [];
        function find(node, name) {
            for (var _i = 0, _a = node.childrens; _i < _a.length; _i++) {
                var i = _a[_i];
                if (i.attributes.name == name)
                    return e.push(node);
                find(i, name);
            }
        }
        find(this, name);
        return e;
    };
    return GUIDocument;
}(GUINode));

点赞0


评论


烟魂烟魂

编码喵

点赞0


评论


145a145a

有我(喜)

点赞0


评论


神奇代码岛func王清林神奇代码岛func王清林

66

点赞0


评论