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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, _cc, StringUtil, _dec, _class, _crd, cc, ccclass, property, Test;

  function _reportPossibleCrUseOfStringUtil(extras) {
    _reporterNs.report("StringUtil", "./StringUtil", _context.meta, extras);
  }

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

      _cclegacy._RF.push({}, "cd903DWWcFKz6DzsBG/Qvuo", "Test", undefined);

      __checkObsolete__(['_decorator', 'Button', 'Component', 'Label', 'Sprite', 'SpriteFrame', 'Node']);

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

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

        start() {
          let spineNode = this.node.getChildByName("spineNode");
          let spine = this.spine = spineNode.addComponent(cc.sp.Skeleton);
          this.scheduleOnce(() => {
            this.dirName = "girl_front";
            this.loadSpine(this.dirName);
          }, 10);
          cc.profiler.showStats();
        }

        loadSpine(dirName, dir = 1, success) {
          let skeleton = this.spine;
          let root = 'http://172.17.196.11:800/fairy/';
          let url = root + "test/" + "testdemo/" + dirName; // let url = 'https://cdn-applet.flash8f.com/pandaHomeLand/app/web_cn/test_file/' + "testdemo/" + dirName

          let image = url + ".png";
          let ske = url + ".json";
          let atlas = url + ".atlas";
          cc.assetManager.loadAny([{
            url: atlas,
            ext: '.txt'
          }, {
            url: ske,
            ext: '.txt'
          }], (error, assets) => {
            if (error || dirName != this.dirName) return;
            cc.assetManager.loadRemote(image, (error, img) => {
              if (error || dirName != this.dirName) return;
              let texture = new cc.Texture2D();
              texture.image = img;
              let asset = new cc.sp.SkeletonData();
              asset.skeletonJson = assets[1];
              asset.atlasText = assets[0];
              asset.textures = [texture];
              asset.textureNames = ['stand'];
              asset.textureNames = [dirName + ".png"];
              asset._uuid = ske; // 可以传入任意字符串，但不能为空
              // skeleton.destroy();
              // skeleton = this.spine = this.addComponent(cc.sp.Skeleton);
              // egretUtil.validateNow();

              this.clearTexture();
              skeleton.skeletonData = asset;
              skeleton.setSkin("skin_yellow"); // skeleton.setSkin("shoe_1");

              this.initSkin(dirName);
              let ani = skeleton.setAnimation(0, 'run', true); // let ani = skeleton.setAnimation(0, this._curAction, true);
              // var offest = this._offest_dirs.indexOf(dir) == -1 ? 1 : -1
              // this.setScale(this.base_value * offest*this.base_value2, this.base_value*this.base_value2, 1)

              success && success();
            });
          });
        }

        clearTexture() {
          let list = ["f_shoeR1", "f_shoeL1", "h_shoeR1", "h_shoeL1", "b_shoeR1", "b_shoeL1"];
          list.map(item => {
            // this.clearSlot(item, item);
            // this.setSlotTexture(item, "alpha");
            let slot = this.spine.findSlot(item); // || ani.findSlot(attachment.name);

            if (slot) {
              // slot.color.a = 0;
              slot.setAttachment(null);
              console.log('清空插槽：', item);
            }
          });
        }

        initSkin(dirName) {
          // ["shoe_L_1", "shoe_L1_1", "shoe_R_1", "shoe_R1_1"]
          // this.changeSkinSlot(this.spine, "shoe_2", null);
          // this.changeSkinSlot(this.spine, "eye_red", null);
          // this.changeSkinSlot(this.spine, "shoe_1", null);
          // this.changeSkinSlot(this.spine, "hair_1", null);
          // this.changeSkinSlot(this.spine, "clothes_1", null);
          // this.changeSkinSlot(this.spine, "skin_yellow", null);
          console.log("start chagne skin", dirName); // this.loadSkin(dirName);

          this.scheduleOnce(() => {
            this.loadSkin(dirName);
          }, 2);
        }

        loadSkin(path) {
          let root = 'http://172.17.196.11:800/fairy/';
          let url = root + "test/" + "testdemo/shoe/" + path;
          let imgName = path + ".png";
          let image = url + ".png";
          let ske = url + ".json";
          let atlas = url + ".atlas";
          let dirName = this.dirName;
          cc.assetManager.loadAny([{
            url: atlas,
            ext: '.txt'
          }, {
            url: ske,
            ext: '.txt'
          }], (error, assets) => {
            if (error || dirName != this.dirName) return;
            cc.assetManager.loadRemote(image, (error, img) => {
              if (error || dirName != this.dirName) return;
              var node = new cc.Node();
              let skeleton = node.addComponent(cc.sp.Skeleton);
              let texture = new cc.Texture2D();
              texture.image = img;
              let asset = new cc.sp.SkeletonData();
              asset.skeletonJson = assets[1];
              asset.atlasText = assets[0];
              asset.textures = [texture];
              asset.textureNames = [imgName]; //必须设置正确的图片文件名，否则app里面会崩溃

              asset._uuid = ske; // 可以传入任意字符串，但不能为空

              skeleton.skeletonData = asset;
              let atlasText = assets[0].split("\n");
              atlasText = atlasText.splice(6);
              let dic = {};

              for (var i = 0; i < atlasText.length; i++) {
                var item = atlasText[i];
                if (!item) continue;
                let one = dic[item] = {};
                let len = 6;

                while (len-- > 0) {
                  i++; //rotate: true  xy: 221, 245  size: 52, 76  orig: 54, 80  offset: 2, 4  index: -1

                  let arr = (_crd && StringUtil === void 0 ? (_reportPossibleCrUseOfStringUtil({
                    error: Error()
                  }), StringUtil) : StringUtil).trim(atlasText[i], 'g').split(":");

                  if (String(arr[1]).indexOf(",") >= 0) {
                    arr[1] = (_crd && StringUtil === void 0 ? (_reportPossibleCrUseOfStringUtil({
                      error: Error()
                    }), StringUtil) : StringUtil).stringToIntArray(arr[1]);
                  }

                  one[arr[0]] = arr[1];
                }

                let rect = new cc.Rect(one.xy[0], one.xy[1], one.orig[0], one.orig[1]);
                let newTexture = new cc.Texture2D();
                newTexture.reset({
                  width: rect.width,
                  height: rect.height
                });
                let buff = (_crd && StringUtil === void 0 ? (_reportPossibleCrUseOfStringUtil({
                  error: Error()
                }), StringUtil) : StringUtil).readTexturePixels(texture, rect);
                newTexture.uploadData(buff);
                dic[item] = newTexture;
              }

              this.changeSkinSlot(this.spine, "shoe_2", null, skeleton, dic);
            });
          });
        }

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

        changeSkinSlot(ani, skinName, slots, target, dic) {
          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 (skinName == "shoe_2") {
            console.log("-----", this.dirName);
          }

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

          if (skin.attachments) {
            skin.attachments.forEach((value, index) => {
              let name = '';
              let attachment = null;
              console.log("====");
              console.log("====", value, value == null ? void 0 : value.name, skinName, value.attachment);

              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 (dic && dic[name]) {// ani.setSlotTexture(name, dic[name], true);
              }
            }); // ani.invalidAnimationCache();
          }
        }

      }) || _class));

      _cclegacy._RF.pop();

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