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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Asset, assetManager, Node, sp, tween, Layers, find, v2, v3, Utils, _crd;

  function _reportPossibleCrUseOfITEM_TYPE(extras) {
    _reporterNs.report("ITEM_TYPE", "../common/GameConst", _context.meta, extras);
  }

  _export("default", void 0);

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      Asset = _cc.Asset;
      assetManager = _cc.assetManager;
      Node = _cc.Node;
      sp = _cc.sp;
      tween = _cc.tween;
      Layers = _cc.Layers;
      find = _cc.find;
      v2 = _cc.v2;
      v3 = _cc.v3;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "d0788kA+CpAb7fGbF4Gj2lV", "Utils", undefined);

      __checkObsolete__(['log', 'Asset', 'assetManager', 'error', 'Node', 'Vec3', 'sp', 'tween', 'Layers', 'find', 'Camera', 'v2', 'UITransform', 'v3', 'isValid', 'CCObject', 'AssetManager']);

      _export("default", Utils = class Utils {
        constructor() {
          this._bundles = new Map();
        }

        //检查是否同一天
        static checkIsToDay(time) {
          var date = new Date(time);
          var dateNow = new Date();
          let bSameDay = false;

          if (date.getFullYear() == dateNow.getFullYear() && date.getMonth() == dateNow.getMonth() && date.getDate() == dateNow.getDate()) {
            bSameDay = true;
          }

          return bSameDay;
        }

        static getRandom(lower, upper) {
          return Math.random() * (upper - lower) + lower;
        }

        static getRandomInt(lower, upper) {
          return Math.floor(Math.random() * (upper - lower)) + lower;
        }

        static seedRandom() {
          return Utils.getRandom(0, 1); // this.seed = (this.seed * 9301 + 49297) % 233280;
          // return this.seed / 233280.0;
        }

        static seedRandomInt(lower, upper) {
          return Utils.getRandomInt(lower, upper); // return Math.floor(Utils.seedRandom() * (upper - lower)) + lower;
        } // public static formatNumber(num: number, afterdot: number = 1) {
        //     num = Math.floor(num);
        //     return BigNumber.getLargeString(num);
        // };


        static getPowNum(p) {
          return Math.pow(10, p);
        }

        // static showTip(value: string) {
        //     if (sys.platform == sys.WECHAT_GAME) {
        //         wx.showToast({ title: value, icon: 'none', duration: 1500 })
        //     }
        // }
        static formatDate(t) {
          var date = new Date(t);
          var YY = date.getFullYear() + '-';
          var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
          var DD = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
          var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
          var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
          var ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
          return YY + MM + DD + " " + hh + mm + ss;
        }

        static cloneObj(obj) {
          obj = JSON.stringify(obj);
          obj = JSON.parse(obj);
          return obj;
        }

        static getTimeStrByS(second) {
          second = Math.floor(second);
          if (second < 0) second = 0;
          var d = Math.floor(second / 3600 / 24);
          second -= d * 3600 * 24;
          var h = Math.floor(second / 3600);
          second -= h * 3600;
          var m = Math.floor(second / 60);
          second -= m * 60;
          var front = "00";

          if (h > 9) {
            front = "" + h;
          } else {
            front = "0" + h;
          }

          var mid = "00";

          if (m > 9) {
            mid = "" + m;
          } else {
            mid = "0" + m;
          }

          var back = "00";

          if (second > 9) {
            back = "" + second;
          } else {
            back = "0" + second;
          }

          if (d > 0) {
            return d + "天" + h + "时" + m + "分";
          } else {
            var longTime = h > 0;

            if (longTime) {
              return front + ":" + mid;
            } else {
              return mid + ":" + back; //+ '秒';
            }
          }
        }

        static getClockStrByS(second, showsecond = true, showhour = true) {
          second = Math.floor(second);
          if (second < 0) second = 0;
          var h = Math.floor(second / 3600);
          second -= h * 3600;
          var m = Math.floor(second / 60);
          second -= m * 60;
          var front = "00";

          if (h > 9) {
            front = "" + h;
          } else {
            front = "0" + h;
          }

          var mid = "00";

          if (m > 9) {
            mid = "" + m;
          } else {
            mid = "0" + m;
          }

          let str = "";

          if (showhour) {
            str += front;
            str += ":";
          }

          str += mid;
          if (showsecond) str += ":" + (second < 10 ? "0" : "") + second;
          return str;
        }

        static checkObjEmpty(obj) {
          if (obj) {
            for (var i in obj) {
              return false;
            }

            return true;
          } else {
            return true;
          }
        }

        static checkOrderOver(orderTime) {
          var date = new Date(orderTime);
          var dateNow = new Date();

          if (date.getFullYear() == dateNow.getFullYear() && date.getMonth() == dateNow.getMonth() && date.getDate() == dateNow.getDate()) {
            return false;
          } else {
            return true;
          }
        }

        static loadBundler(name) {
          return new Promise((resolve, reject) => {
            assetManager.loadBundle(name, (err, ret) => {
              console.log(ret);
              resolve(null);
            });
          });
        }
        /**
         * 加载指定bundle中的所有资源并缓存
         * @param bundleName bundle名称
         * @param callback 回调函数(可选)
         */


        static async loadAllResInBundle(bundleName, callback) {
          return new Promise(async (resolve, reject) => {
            try {
              //获取bundle
              const bundle = assetManager.getBundle(bundleName);

              if (!bundle) {
                const err = new Error(`Bundle ${bundleName} not found`);
                if (callback) callback(err);
                reject(err);
                return;
              } //2. 获取bundle中的所有资源路径


              const paths = await this._getBundleAssets(bundle);

              if (!paths || paths.length === 0) {
                const msg = `Bundle ${bundleName} 中没有找到任何资源`;
                console.log(msg);
                if (callback) callback(null, []);
                resolve([]);
                return;
              } //3. 逐个加载资源并缓存


              const assets = [];

              for (const path of paths) {
                try {
                  //先检查缓存
                  if (this.loadedAssets.has(path)) {
                    assets.push(this.loadedAssets.get(path));
                    continue;
                  } //加载资源


                  const asset = await this.loadRes(path, bundleName, Asset);

                  if (asset) {
                    this.loadedAssets.set(path, asset);
                    assets.push(asset);
                  }
                } catch (err) {
                  console.warn(`加载资源 ${path} 失败:`, err); // 单个资源加载失败不影响其他资源
                }
              }

              console.log(`Bundle ${bundleName} 加载完成，共加载 ${assets.length}/${paths.length} 个资源`);
              if (callback) callback(null, assets);
              resolve(assets);
            } catch (err) {
              console.error(`加载Bundle ${bundleName} 失败:`, err);
              if (callback) callback(err);
              reject(err);
            }
          });
        }
        /**
         * 从缓存中获取资源，如果不存在则加载
         * @param path 资源路径
         * @param bundleName bundle名称
         * @param type 资源类型(可选)
         * @param callback 回调函数(可选)
         */


        static async getOrLoadAsset(path, bundleName, type, callback) {
          return new Promise(async (resolve, reject) => {
            try {
              // 1. 先尝试从缓存获取
              if (this.loadedAssets.has(path)) {
                const cachedAsset = this.loadedAssets.get(path);
                if (callback) callback(null, cachedAsset);
                resolve(cachedAsset);
                return;
              } // 2. 缓存中没有则加载


              const asset = await this.loadRes(path, bundleName, type || Asset);

              if (asset) {
                // 加载成功后加入缓存
                this.loadedAssets.set(path, asset);
                if (callback) callback(null, asset);
                resolve(asset);
              } else {
                const err = new Error(`资源 ${path} 加载失败`);
                if (callback) callback(err);
                reject(err);
              }
            } catch (err) {
              console.error(`获取/加载资源 ${path} 失败:`, err);
              if (callback) callback(err);
              reject(err);
            }
          });
        }
        /**
         * 获取Bundle内资源路径列表
         */


        static async _getBundleAssets(bundle) {
          try {
            var _bundle$config, _bundle$config$paths;

            let paths = []; //方法1：直接从配置的paths._map中获取所有键（路径）

            if ((_bundle$config = bundle['config']) != null && (_bundle$config$paths = _bundle$config.paths) != null && _bundle$config$paths._map) {
              //直接从配置的paths._map中获取所有键（路径）
              paths = Array.from(Object.keys(bundle['config'].paths._map));
            } else if (bundle['_assetMap']) {
              //方法2：兼容旧的_assetMap方式
              paths = Array.from(bundle['_assetMap'].keys());
            } else {
              //方法3：回退方案
              paths = bundle.getDirWithPath('').map(item => item.path);
            }

            return paths;
          } catch (error) {
            console.error(`获取Bundle资源路径失败:`, error);
            throw error;
          }
        }
        /**
         * 获取已加载的Bundle实例
         * @param bundleName Bundle名称
         * @returns Bundle实例或null
         */


        async getBundle(bundleName) {
          //先从缓存中查找
          const cachedBundle = this._bundles.get(bundleName);

          if (cachedBundle) {
            return cachedBundle;
          }

          try {
            //如果缓存中没有，则加载bundle
            const bundle = await new Promise((resolve, reject) => {
              assetManager.loadBundle(bundleName, (err, bundle) => {
                err ? reject(err) : resolve(bundle);
              });
            });
            return bundle;
          } catch (error) {
            console.error(`加载Bundle ${bundleName} 失败:`, error);
            return null;
          }
        }

        static loadRes(path, bundle, type, callback = null) {
          return new Promise((resolve, reject) => {
            if (!assetManager.getBundle(bundle)) {
              console.log(bundle);
            }

            let ret = assetManager.getBundle(bundle).get(path, type);

            if (ret) {
              if (callback) callback(null, ret);
              resolve(ret);
              return;
            }

            assetManager.getBundle(bundle).load(path, type, (err, ret) => {
              if (err) {
                console.warn("加载错误：", path, err);
                if (callback) callback(err, null);
                reject(null);
              } else {
                if (callback) callback(null, ret);
                resolve(ret);
              }
            });
          });
        }

        static weight(v) {
          var mTotalWeight = 0;

          for (var i = 0; i < v.length; ++i) {
            mTotalWeight += v[i];
          }

          if (mTotalWeight <= 0) return -1;
          var randnum = Math.round(Math.random() * Number.MAX_VALUE) % mTotalWeight;

          for (var i = 0; i < v.length; ++i) {
            if (randnum < v[i]) {
              return i;
            } else {
              randnum -= v[i];
            }
          }

          return -1;
        }

        static shuffle(arr) {
          for (let i = arr.length - 1; i >= 0; i--) {
            let rIndex = Math.floor(Math.random() * (i + 1));
            let temp = arr[rIndex];
            arr[rIndex] = arr[i];
            arr[i] = temp;
          }

          return arr;
        }

        static getDate(time) {
          var now = new Date(time),
              y = now.getFullYear(),
              m = now.getMonth() + 1,
              d = now.getDate();
          return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
        } //货币进位


        static goldCrarryBit(gold) {
          var array = [[100000000, 'N'], [10000000, 'T'], [1000000, 'G'], [100000, 'M'], [10000, 'K'], [1000, 'B']];

          for (var i = 0; i < array.length; i++) {
            var value = gold / array[i][0];

            if (value > 1) {
              return '' + value.toFixed(1) + array[i][1];
            }
          }

          return gold.toString();
        } //定点数


        static fixFloat(val, count = 2) {
          var a = Math.pow(10, count);
          return Math.floor(val * a) / a;
        }

        static flyAnim(type, starNode, targetNode, count, radius, callback) {
          let getPoint = (r, ox, oy, count) => {
            var point = []; //结果

            var radians = Math.PI / 180 * Math.round(360 / count),
                //弧度
            i = 0;

            for (; i < count; i++) {
              var x = ox + r * Math.sin(radians * i),
                  y = oy + r * Math.cos(radians * i);
              point.unshift(v2(x, y)); //为保持数据顺时针
            }

            return point;
          };

          let start = starNode.worldPosition;
          var array = getPoint(radius, start.x, start.y, count);
          var nodeArray = new Array();

          for (var i = 0; i < array.length; i++) {
            var gold = window['PoolMgr'].Instance().get(type);
            gold.setWorldScale(v3(0.7, 0.7, 0.7)); // gold.zIndex = GameConst.WIN_LAYER.TIP;

            gold.parent = find("Canvas");
            var randPos = v3(array[i].x + Utils.getRandomInt(0, 50), array[i].y + Utils.getRandomInt(0, 50), 1);
            gold.setWorldPosition(start);
            nodeArray.push({
              gold,
              randPos
            });
          }

          var notPlay = false;
          let dstPos = targetNode.worldPosition;

          for (let i = 0; i < nodeArray.length; i++) {
            let pos = nodeArray[i].randPos;
            let node = nodeArray[i].gold;
            nodeArray[i].gold.id = i;
            tween(node).to(0.2, {
              worldPosition: pos
            }).delay(i * 0.03).to(0.7, {
              worldPosition: v3(dstPos.x, dstPos.y, 1)
            }).call(() => {
              if (!notPlay) {
                notPlay = true;
                tween(targetNode).to(0.1, {
                  scale: v3(2, 2, 2)
                }).to(0.1, {
                  scale: v3(1, 1, 1)
                }).call(() => {
                  notPlay = false;
                }).start();
              }

              callback(node.id == nodeArray.length - 1);
              window['PoolMgr'].Instance().put(node.name, node);
            }).start();
          }
        }

        static formatString(s, ...arg) {
          for (var i = 0; i < arg.length; i++) {
            var reg = new RegExp("\\{" + i + "\\}", "gm");
            s = s.replace(reg, arg[i]);
          }

          return s;
        } // static convetOtherNodeSpaceAR(sourceNode:Node, targetNode:Node)
        // {
        //     var worldP:Vec2=sourceNode.convertToWorldSpaceAR(v2(0,0))        
        //     return targetNode.convertToNodeSpaceAR(worldP)
        // }


        static count(obj) {
          if (!obj) return 0;
          var num = 0;

          for (var k in obj) {
            num++;
          }

          return num;
        }

        static copy(obj) {
          var newObj = Object.create(obj);
          Object.assign(newObj, obj);
          return newObj;
        } // static setGray(icon:Sprite, isGray:boolean) {
        //     if (isGray) {
        //         icon.setMaterial(0, Material.getBuiltinMaterial('2d-gray-sprite'));
        //     } else {
        //         icon.setMaterial(0, Material.getBuiltinMaterial('2d-sprite'));
        //     }
        // }


        static async playSkAni(file, name, parent, pos, removetime = -1) {
          var node = new Node();
          node.parent = parent;
          node.position = pos;
          node.layer = Layers.BitMask.UI_2D; // let uit = node.addComponent(UITransform);
          // uit.width = 200;
          // uit.height = 130;

          var skd = node.addComponent(sp.Skeleton);
          var data = await Utils.loadRes(file, "spine", sp.SkeletonData);
          skd.skeletonData = data;
          skd.setAnimation(0, name, false);

          if (removetime != -1) {
            tween(node).delay(removetime).call(() => {
              node.removeFromParent();
              node.destroy();
            }).start();
          }

          return node;
        }

      });

      Utils.loadedAssets = new Map();
      Utils.seed = 5;
      ;

      _cclegacy._RF.pop();

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