System.register(["cc"], function (_export, _context) {
  "use strict";

  var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, _cc, _dec, _class, _crd, cc, ccclass, property, Spine;

  return {
    setters: [function (_cc2) {
      _cclegacy = _cc2.cclegacy;
      __checkObsolete__ = _cc2.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc2.__checkObsoleteInNamespace__;
      _decorator = _cc2._decorator;
      Component = _cc2.Component;
      _cc = _cc2;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "9d229ElKyZMprjy65qt9Ehe", "Spine", undefined);

      __checkObsolete__(['_decorator', 'Component', 'Node']);

      cc = __checkObsoleteInNamespace__(_cc);
      ({
        ccclass,
        property
      } = _decorator);

      _export("Spine", Spine = (_dec = ccclass('Spine'), _dec(_class = class Spine extends Component {
        constructor(...args) {
          super(...args);
          this.spine = void 0;
          this.spine_skin = void 0;
          this.spine2 = void 0;
          this.spine_skin2 = void 0;
        }

        start() {
          window["spineC"] = this;
          let snode = this.node.getChildByName("spine");
          let spine = snode.getComponent(cc.sp.Skeleton);
          this.spine = spine;
          let spine2 = this.node.getChildByName("spine2").getComponent(cc.sp.Skeleton);
          this.spine2 = spine2;
          let spine_skin = this.node.getChildByName("spine_skin").getComponent(cc.sp.Skeleton);
          this.spine_skin = spine_skin;
          let spine_skin2 = this.node.getChildByName("spine_skin2").getComponent(cc.sp.Skeleton);
          this.spine_skin2 = spine_skin2;
          let Button = cc.find("Canvas/Button");
          Button.on(cc.Node.EventType.TOUCH_END, () => {
            // let list:string[] = ["shoe/images/shoe_L_1", "shoe/images/shoe_L1_1", "shoe/images/shoe_R_1", "shoe/images/shoe_R1_1",
            let list = ["shoe2/images/shoe_L_1", "shoe2/images/shoe_L1_1", "shoe2/images/shoe_R_1", "shoe2/images/shoe_R1_1", "hair/images/hair_b_1", "hair/images/hair_f_1", "clothes/images/clothes_1", "clothes/images/clothes_f_1", "clothes/images/sleeve_L_1", "clothes/images/sleeve_R_1"];
            list.map(item => {
              let name = item.substring(item.lastIndexOf("/") + 1);
              this.setSlotTexture(name, item);
            });
          }, this);
          let mcs = ["half_run", "half_run5", "half_stand", "half_walk", "sit", "sit_2"];
          let mcIndex = -1;
          let Button2 = cc.find("Canvas/Button2");
          Button2.on(cc.Node.EventType.TOUCH_END, () => {
            mcIndex = (mcIndex + 1) % mcs.length;
            spine.setAnimation(0, "half/" + mcs[mcIndex], true);
            spine2.setAnimation(0, "half/" + mcs[mcIndex], true);
          }, this);
          let Button3 = cc.find("Canvas/Button3");
          Button3.on(cc.Node.EventType.TOUCH_END, () => {
            let list = ["shoe_L_1", "shoe_L1_1", "shoe_R_1", "shoe_R1_1", "shoe_L_2", "shoe_R_2", "shoe_L_4", "shoe_R_4"];
            list.map(item => {
              // this.clearSlot(item, item);
              // this.setSlotTexture(item, "alpha");
              let slot = spine.findSlot(item); // || ani.findSlot(attachment.name);

              if (slot) {
                // slot.color.a = 0;
                slot.setAttachment(null);
              }

              slot = spine2.findSlot(item); // || ani.findSlot(attachment.name);

              if (slot) {
                // slot.color.a = 0;
                slot.setAttachment(null);
              }
            }); // ["shoe_L_1", "shoe_L1_1", "shoe_R_1", "shoe_R1_1"]

            this.changeSkinSlot(spine, "shoe_2", null, spine);
            this.changeSkinSlot(spine2, "shoe_1", null, spine2);
          }, this);
          Button.active = Button2.active = false;
          cc.assetManager.loadBundle("others", (err, data) => {
            data.loadDir("", () => {
              cc.log("load complete", data.getDirWithPath(''));
              Button.active = Button2.active = true;
            });
          });
        }

        setSlotTexture(name, path, _spine) {
          let texture = cc.assetManager.getBundle("others").get(path + "/texture", cc.Texture2D);
          if (!texture) return;
          _spine = _spine || this.spine;

          _spine.setSlotTexture(name, texture); // this.spine.setAttachment(name, texture);


          cc.log(_spine.getAttachment(name, name));
        }

        clearSlot(lotName, attachmentName) {
          let empty = new cc.Texture2D();
          this.spine.setSlotTexture(lotName, empty);
        }

        changeSkinSlot(ani, skinName, slots, target = null) {
          let skeletonData = null;
          let skin = null;

          if (target) {
            skeletonData = target.skeletonData.getRuntimeData();
            skin = skeletonData.findSkin(skinName);
          } else {
            skeletonData = ani.skeletonData.getRuntimeData();
            skin = skeletonData.findSkin(skinName);
          }

          if (skin == null) {
            return console.log("skin 为空", skinName);
          }

          if (skin.attachments) {
            skin.attachments.forEach((value, index) => {
              let name = '';
              let attachment = null;
              console.log(value);

              if (value.attachment) {
                name = value.name;
                attachment = value.attachment;
              } else {
                name = Object.keys(value)[0];
                attachment = value[name];
              }

              let slot = ani.findSlot(name); // || ani.findSlot(attachment.name);

              slot && slot.setAttachment(attachment);

              if (skinName == "shoe_1") {
                this.setSlotTexture(name, "shoe1_1104/images/" + attachment.path, this.spine2);
                return;
              }

              this.setSlotTexture(name, "shoe2_1104/images/" + attachment.path);
            });
            ani.invalidAnimationCache();
          }
        }

      }) || _class));

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=d64b0314499af2d69c07bd0798f824e2fac62b2d.js.map