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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, error, instantiate, log, NodePool, Prefab, Utils, Singleton, PoolMgr, _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 _reportPossibleCrUseOfUtils(extras) {
    _reporterNs.report("Utils", "../utils/Utils", _context.meta, extras);
  }

  function _reportPossibleCrUseOfSingleton(extras) {
    _reporterNs.report("Singleton", "./Singleton", _context.meta, extras);
  }

  _export("default", void 0);

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      error = _cc.error;
      instantiate = _cc.instantiate;
      log = _cc.log;
      NodePool = _cc.NodePool;
      Prefab = _cc.Prefab;
    }, function (_unresolved_2) {
      Utils = _unresolved_2.default;
    }, function (_unresolved_3) {
      Singleton = _unresolved_3.default;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "0a458ZK0HlOqLID6d1WmPwY", "PoolMgr", undefined);

      __checkObsolete__(['Node', 'error', 'instantiate', 'log', 'NodePool', 'Prefab', 'v3']);

      _export("default", PoolMgr = class PoolMgr extends (_crd && Singleton === void 0 ? (_reportPossibleCrUseOfSingleton({
        error: Error()
      }), Singleton) : Singleton) {
        constructor() {
          super(...arguments);
          this.pools = {};
          this.prefabs = {};
          this.getputcount = {};
        }

        loadPrefabs() {
          var _this = this;

          return _asyncToGenerator(function* () {
            var list = [{
              path: "items/Coin",
              bundle: "prefabs",
              key: "Coin",
              cn: 3
            }, {
              path: "items/Life",
              bundle: "prefabs",
              key: "Life",
              cn: 3
            }, {
              path: "items/Star",
              bundle: "prefabs",
              key: "Star",
              cn: 3
            }];

            try {
              for (var i = 0; i < list.length; ++i) {
                var a = list[i];
                var ret = yield (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
                  error: Error()
                }), Utils) : Utils).loadRes(a.path, a.bundle, Prefab);

                _this.initPool(a.key, ret, a.cn);
              }
            } catch (error) {
              console.error(error);
            }
          })();
        }

        initPool(key, prefab, count) {
          // console.log("initPool:",key,count);
          this.prefabs[key] = prefab;
          this.pools[key] = new NodePool();

          for (var i = 0; i < count; ++i) {
            this.pools[key].put(instantiate(prefab));
          }
        }

        get(key) {
          if (this.pools[key] == null) {
            error("没有" + key);
            return null;
          }

          if (!this.getputcount[key]) this.getputcount[key] = 0;
          this.getputcount[key]++;
          if (this.pools[key].size() > 0) return this.pools[key].get();else return instantiate(this.prefabs[key]);
        }

        put(key, node) {
          if (!this.getputcount[key]) this.getputcount[key] = 0;
          this.getputcount[key]--;

          if (!this.pools[key]) {
            console.error(key);
          }

          this.pools[key].put(node);
        }

        trace() {
          for (var key in this.pools) {
            log(key, this.pools[key].size());
          }
        }

      });

      window['PoolMgr'] = PoolMgr;

      _cclegacy._RF.pop();

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