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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

  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();
          var 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, showhour) {
          if (showsecond === void 0) {
            showsecond = true;
          }

          if (showhour === void 0) {
            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;
          }

          var 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 loadAllResInBundle(bundleName, callback) {
          var _this = this;

          return _asyncToGenerator(function* () {
            return new Promise( /*#__PURE__*/_asyncToGenerator(function* (resolve, reject) {
              try {
                //获取bundle
                var bundle = assetManager.getBundle(bundleName);

                if (!bundle) {
                  var _err = new Error("Bundle " + bundleName + " not found");

                  if (callback) callback(_err);
                  reject(_err);
                  return;
                } //2. 获取bundle中的所有资源路径


                var paths = yield _this._getBundleAssets(bundle);

                if (!paths || paths.length === 0) {
                  var msg = "Bundle " + bundleName + " \u4E2D\u6CA1\u6709\u627E\u5230\u4EFB\u4F55\u8D44\u6E90";
                  console.log(msg);
                  if (callback) callback(null, []);
                  resolve([]);
                  return;
                } //3. 逐个加载资源并缓存


                var _assets = [];

                for (var path of paths) {
                  try {
                    //先检查缓存
                    if (_this.loadedAssets.has(path)) {
                      _assets.push(_this.loadedAssets.get(path));

                      continue;
                    } //加载资源


                    var _asset = yield _this.loadRes(path, bundleName, Asset);

                    if (_asset) {
                      _this.loadedAssets.set(path, _asset);

                      _assets.push(_asset);
                    }
                  } catch (err) {
                    console.warn("\u52A0\u8F7D\u8D44\u6E90 " + path + " \u5931\u8D25:", err); // 单个资源加载失败不影响其他资源
                  }
                }

                console.log("Bundle " + bundleName + " \u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171\u52A0\u8F7D " + _assets.length + "/" + paths.length + " \u4E2A\u8D44\u6E90");
                if (callback) callback(null, _assets);
                resolve(_assets);
              } catch (err) {
                console.error("\u52A0\u8F7DBundle " + bundleName + " \u5931\u8D25:", err);
                if (callback) callback(err);
                reject(err);
              }
            }));
          })();
        }
        /**
         * 从缓存中获取资源，如果不存在则加载
         * @param path 资源路径
         * @param bundleName bundle名称
         * @param type 资源类型(可选)
         * @param callback 回调函数(可选)
         */


        static getOrLoadAsset(path, bundleName, type, callback) {
          var _this2 = this;

          return _asyncToGenerator(function* () {
            return new Promise( /*#__PURE__*/_asyncToGenerator(function* (resolve, reject) {
              try {
                // 1. 先尝试从缓存获取
                if (_this2.loadedAssets.has(path)) {
                  var cachedAsset = _this2.loadedAssets.get(path);

                  if (callback) callback(null, cachedAsset);
                  resolve(cachedAsset);
                  return;
                } // 2. 缓存中没有则加载


                var _asset2 = yield _this2.loadRes(path, bundleName, type || Asset);

                if (_asset2) {
                  // 加载成功后加入缓存
                  _this2.loadedAssets.set(path, _asset2);

                  if (callback) callback(null, _asset2);
                  resolve(_asset2);
                } else {
                  var _err2 = new Error("\u8D44\u6E90 " + path + " \u52A0\u8F7D\u5931\u8D25");

                  if (callback) callback(_err2);
                  reject(_err2);
                }
              } catch (err) {
                console.error("\u83B7\u53D6/\u52A0\u8F7D\u8D44\u6E90 " + path + " \u5931\u8D25:", err);
                if (callback) callback(err);
                reject(err);
              }
            }));
          })();
        }
        /**
         * 获取Bundle内资源路径列表
         */


        static _getBundleAssets(bundle) {
          return _asyncToGenerator(function* () {
            try {
              var _bundle$config, _bundle$config$paths;

              var 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("\u83B7\u53D6Bundle\u8D44\u6E90\u8DEF\u5F84\u5931\u8D25:", error);
              throw error;
            }
          })();
        }
        /**
         * 获取已加载的Bundle实例
         * @param bundleName Bundle名称
         * @returns Bundle实例或null
         */


        getBundle(bundleName) {
          var _this3 = this;

          return _asyncToGenerator(function* () {
            //先从缓存中查找
            var cachedBundle = _this3._bundles.get(bundleName);

            if (cachedBundle) {
              return cachedBundle;
            }

            try {
              //如果缓存中没有，则加载bundle
              var bundle = yield new Promise((resolve, reject) => {
                assetManager.loadBundle(bundleName, (err, bundle) => {
                  err ? reject(err) : resolve(bundle);
                });
              });
              return bundle;
            } catch (error) {
              console.error("\u52A0\u8F7DBundle " + bundleName + " \u5931\u8D25:", error);
              return null;
            }
          })();
        }

        static loadRes(path, bundle, type, callback) {
          if (callback === void 0) {
            callback = null;
          }

          return new Promise((resolve, reject) => {
            if (!assetManager.getBundle(bundle)) {
              console.log(bundle);
            }

            var 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 (var i = arr.length - 1; i >= 0; i--) {
            var rIndex = Math.floor(Math.random() * (i + 1));
            var 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) {
          if (count === void 0) {
            count = 2;
          }

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

        static flyAnim(type, starNode, targetNode, count, radius, callback) {
          var 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;
          };

          var 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;
          var dstPos = targetNode.worldPosition;

          var _loop = function _loop() {
            var pos = nodeArray[_i].randPos;
            var 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();
          };

          for (var _i = 0; _i < nodeArray.length; _i++) {
            _loop();
          }
        }

        static formatString(s) {
          for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
            var reg = new RegExp("\\{" + i + "\\}", "gm");
            s = s.replace(reg, i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]);
          }

          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 playSkAni(file, name, parent, pos, removetime) {
          return _asyncToGenerator(function* () {
            if (removetime === void 0) {
              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 = yield 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=712300d29caabf9b29168a47d76140a5ac734c46.js.map