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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Singleton, _dec, _class, _crd, ccclass, property, EventEmitter, eventEmitter;

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

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

      _cclegacy._RF.push({}, "eef30aCO4hI0ZvvAJvZaGOD", "EventEmitter", undefined);

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

      ({
        ccclass,
        property
      } = _decorator);
      /*
      //注册事件
      EventEmitter.instance.register(this, "PLAYER_DEAD", (reason: string) => {
          console.log("～～:", reason);
      });
      //派发事件
      EventEmitter.instance.dispatch("PLAYER_DEAD", "被怪物击杀");
      //注销事件
      EventEmitter.instance.unregister(this, "PLAYER_DEAD");*/

      /**事件数据接口*/

      /**事件哈希表接口*/

      EventEmitter = (_dec = ccclass('EventEmitter'), _dec(_class = class EventEmitter extends (_crd && Singleton === void 0 ? (_reportPossibleCrUseOfSingleton({
        error: Error()
      }), Singleton) : Singleton) {
        constructor() {
          super(...arguments);
          this.eventHash = {};
        }

        /**
         * 清空所有事件监听
         */
        clearAll() {
          console.log("清空所有事件监听");
          this.eventHash = {};
        }
        /**
         * 注册事件监听
         * @param target 监听对象 (用于取消监听时识别)
         * @param type 事件类型
         * @param callback 回调函数
         */


        register(target, type, callback) {
          if (!this.eventHash[type]) {
            this.eventHash[type] = [];
          } //检查是否已注册相同监听


          var exists = this.eventHash[type].some(event => event.func === callback && event.target === target);

          if (!exists) {
            this.eventHash[type].push({
              func: callback,
              target: target
            });
          }
        }
        /**
         * 注销事件监听
         * @param target 监听对象
         * @param type 事件类型
         */


        unregister(target, type) {
          var events = this.eventHash[type];

          if (events && events.length > 0) {
            for (var i = events.length - 1; i >= 0; i--) {
              if (events[i].target === target) {
                events.splice(i, 1);
              }
            }
          }
        }
        /**
         * 派发事件
         * @param type 事件类型
         * @param data 事件数据 (可变参数)
         */


        dispatch(type) {
          for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
            data[_key - 1] = arguments[_key];
          }

          var events = this.eventHash[type];

          if (events && events.length > 0) {
            // 使用slice创建副本，防止在回调中修改数组影响遍历
            events.slice().forEach(event => {
              try {
                event.func.apply(event.target, data);
              } catch (error) {
                console.error("\u4E8B\u4EF6[" + type + "]\u5904\u7406\u9519\u8BEF:", error);
              }
            });
          }
        }

      }) || _class); //单例

      _export("eventEmitter", eventEmitter = EventEmitter.ins());

      _cclegacy._RF.pop();

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