var t = require; var e = module; var i = exports; var s = (this && this.__decorate) || function (t, e, i, s) { var o, a = arguments.length, n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s); else for (var r = t.length - 1; 0 <= r; r--) (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n); return 3 < a && n && Object.defineProperty(e, i, n), n; }; Object.defineProperty(i, "__esModule", {value: !0}); e = t("NodeStateData"); function o(t, e, i) { cc.Class.Attr.setClassAttr(t, e, "type", "Enum"), cc.Class.Attr.setClassAttr(t, e, "enumList", cc.Enum.getList(i)); } let a = cc.Enum({"": 0}); const {ccclass: n, property: r, executeInEditMode: l, menu: h} = cc._decorator, c = ["x", "y", "scaleX", "scaleY", "height", "width", "active", "angle", "opacity"]; t = class extends cc.Component { constructor() { super(...arguments), (this._states = []), (this._curState = ""), (this.frames = []), (this._addState = ""), (this._removeState = ""), (this._tempSaveStr = ""), (this._saveStr = ""), (this.nodeStateCache = {}), (this.nodeStateCache1 = {}), (this.realNodeList = []), (this._nodeList = []); } set curState(t) { this._states[t] !== this._curState && ((this._curState = this._states[t]), this.switchState(this._curState)); } get curState() { return 0 == this._states.length ? 0 : this._states.indexOf(this._curState); } setState(t, e = 0) { t !== this._curState && ((this._curState = t), this.switchState(t)); } set addState(t) { -1 < t.indexOf("@") ? ((t = t.replace("@", "")), (this._addState = ""), t && -1 === this._states.indexOf(t) && (this._states.push(t), 1 == this._states.length && (this.curState = 0), this._updateAnimEnum())) : (this._addState = t); } get addState() { return this._addState; } set removeState(t) { var e; -1 < t.indexOf("@") ? "default" != (t = t.replace("@", "")) && ((this._removeState = ""), -1 < (e = this._states.indexOf(t)) && (this._states.splice(e, 1), this._updateAnimEnum(), delete this.nodeStateCache[t], delete this.nodeStateCache1[e], t == this._curState && (this.curState = 0))) : (this._removeState = t); } onRemoveState(t, e) {} get removeState() { return this._removeState; } __preload() {} getFrameId(t) { var e = t._uuid, i = this.frames.length; for (let t = 0; t < i; t++) if (this.frames[t]._uuid == e) return e; return this.frames.push(t), e; } _updateAnimEnum() { if (this._states.length) { let t = {}, e = 0; for (const i of this._states) t[i] = e++; o(this, "curState", cc.Enum(t)); } else o(this, "curState", a); Editor.Utils.refreshSelectedInspector("node", this.node.uuid); } switchState(i) { const s = this.nodeStateCache1[i]; if (s) { const o = this.realNodeList; let t = o.length; for (let e = 0; e < t; e++) { const i = s[e]; if (i) for (const s in i) if (c.includes(s)) o[e][s] = i[s]; else switch (s) { case "frame": const t = o[e].getComponent(cc.Sprite); if (t) for (const s of this.frames) s._uuid == i.frame && (t.spriteFrame = s); break; case "lab_o_c": const a = o[e].getComponent(cc.LabelOutline); a && (a.color = cc.color(i.lab_o_c)); break; case "color": o[e].color = cc.color(i.color); break; case "str": const n = o[e].getComponent(cc.Label); n && (n.string = i.str); } } } } set nodeList(e) { if (this._tempNodeList) { var i = this._tempNodeList.length; for (let t = 0; t < i; t++) { var s = this._tempNodeList[t]; s && -1 === e.indexOf(s) && s.node && this.removeNode(s.node); } } for (const t of e) t.nodeState = this; this._tempNodeList = e.concat(); } get nodeList() { return this._nodeList; } save() { if (0 != this._states.length) { this.realNodeList.length = 0; const t = (this.nodeStateCache[this._curState] = {}); for (const e of this._nodeList) e && e.node && (this.realNodeList.push(e.node), (t[e.node.uuid] = this.getSaveData(e))); this.createReleaseData(); } else cc.error("请先添加状态"); } createReleaseData() { const e = this.realNodeList, i = new Set(); let s = e.length; const o = (this.nodeStateCache1 = {}); for (const a in this.nodeStateCache) { o[a] = []; for (let t = 0; t < s; t++) { const s = this.nodeStateCache[a][e[t].uuid]; (o[a][t] = s) && s.frame && i.add(s.frame); } } for (let t = this.frames.length - 1; -1 < t; t--) (this.frames[t] && i.has(this.frames[t]._uuid)) || this.frames.splice(t, 1); (this._tempSaveStr = JSON.stringify(this.nodeStateCache)), (this._saveStr = JSON.stringify(o)); } getSaveData(t) { const e = t.node, i = {}; for (const s of c) t[s] && (i[s] = e[s]); if (t.str) { const t = e.getComponent(cc.Label); t && (i.str = t.string); } if (t.lab_o_c) { const t = e.getComponent(cc.LabelOutline); t && (i.lab_o_c = t.color.toHEX("rrggbb")); } if ((t.color && (i.color = e.color.toHEX("rrggbb")), t.frame)) { const t = e.getComponent(cc.Sprite); t && t.spriteFrame && (i.frame = this.getFrameId(t.spriteFrame)); } return i; } removeNodeData(t) { var e = this._nodeList.indexOf(t); -1 !== e && (this._nodeList.splice(e, 1), t.node && this.removeNode(t.node)); } removeNode(t) { var e = t.uuid; for (const i in this.nodeStateCache) delete this.nodeStateCache[i][e]; } addNode(t) {} onLoad() { this._saveStr && (this.nodeStateCache1 = JSON.parse(this._saveStr)); } }; s([r({type: [cc.String], editorOnly: !0})], t.prototype, "_states", void 0), s([r({type: a, editorOnly: !0})], t.prototype, "_curState", void 0), s([r({type: a})], t.prototype, "curState", null), s([r({type: cc.SpriteFrame, visible: !1})], t.prototype, "frames", void 0), s([r({editorOnly: !0})], t.prototype, "_addState", void 0), s([r()], t.prototype, "addState", null), s([r({editorOnly: !0})], t.prototype, "_removeState", void 0), s([r()], t.prototype, "removeState", null), s([r({editorOnly: !0})], t.prototype, "_tempSaveStr", void 0), s([r], t.prototype, "_saveStr", void 0), s([r({type: cc.Node, visible: !1})], t.prototype, "realNodeList", void 0), s([r({type: e.default, editorOnly: !0})], t.prototype, "_nodeList", void 0), s([r({type: e.default})], t.prototype, "nodeList", null), (t = s([n, l, h("UI/NodeState")], t)), (i.default = t);