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

  var _reporterNs, _cclegacy, _decorator, Component, Node, Prefab, instantiate, Camera, ServerListItem, OTWGameManager, OTWGameTouchController, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _temp, _crd, ccclass, property, OTWSceneManager;

  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 _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }

  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }

  function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }

  function _reportPossibleCrUseOfGateClient(extras) {
    _reporterNs.report("GateClient", "../../shared/gateClient/gateClient", _context.meta, extras);
  }

  function _reportPossibleCrUseOfGameClient(extras) {
    _reporterNs.report("GameClient", "../../shared/gameClient/gameClient", _context.meta, extras);
  }

  function _reportPossibleCrUseOfIGameServerInfo(extras) {
    _reporterNs.report("IGameServerInfo", "../../shared/gateClient/GameServer", _context.meta, extras);
  }

  function _reportPossibleCrUseOfServerListItem(extras) {
    _reporterNs.report("ServerListItem", "../ui/ServerListItem", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWGameManager(extras) {
    _reporterNs.report("OTWGameManager", "./OTWGameManager", _context.meta, extras);
  }

  function _reportPossibleCrUseOfOTWGameTouchController(extras) {
    _reporterNs.report("OTWGameTouchController", "./OTWGameTouchController", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      _decorator = _cc._decorator;
      Component = _cc.Component;
      Node = _cc.Node;
      Prefab = _cc.Prefab;
      instantiate = _cc.instantiate;
      Camera = _cc.Camera;
    }, function (_unresolved_2) {}, function (_unresolved_3) {
      ServerListItem = _unresolved_3.ServerListItem;
    }, function (_unresolved_4) {
      OTWGameManager = _unresolved_4.OTWGameManager;
    }, function (_unresolved_5) {
      OTWGameTouchController = _unresolved_5.OTWGameTouchController;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "cb085DzihtBFqt7qBr4jGc6", "OTWSceneManager", undefined);

      ({
        ccclass,
        property
      } = _decorator);

      _export("OTWSceneManager", OTWSceneManager = (_dec = ccclass('OTWSceneManager'), _dec2 = property(Prefab), _dec3 = property(Node), _dec4 = property(Node), _dec5 = property(Node), _dec6 = property(Node), _dec7 = property(Camera), _dec8 = property(_crd && OTWGameManager === void 0 ? (_reportPossibleCrUseOfOTWGameManager({
        error: Error()
      }), OTWGameManager) : OTWGameManager), _dec9 = property(_crd && OTWGameTouchController === void 0 ? (_reportPossibleCrUseOfOTWGameTouchController({
        error: Error()
      }), OTWGameTouchController) : OTWGameTouchController), _dec(_class = (_class2 = (_temp = class OTWSceneManager extends Component {
        constructor() {
          super(...arguments);

          _initializerDefineProperty(this, "ServerInfoListItemTpl", _descriptor, this);

          _initializerDefineProperty(this, "ServerListWrap", _descriptor2, this);

          _initializerDefineProperty(this, "ViewServerList", _descriptor3, this);

          _initializerDefineProperty(this, "ViewGameUI", _descriptor4, this);

          _initializerDefineProperty(this, "ViewGame3D", _descriptor5, this);

          _initializerDefineProperty(this, "MainCamera", _descriptor6, this);

          _initializerDefineProperty(this, "GameMgr", _descriptor7, this);

          _initializerDefineProperty(this, "TouchCtrl", _descriptor8, this);

          _defineProperty(this, "gateClient", void 0);

          _defineProperty(this, "gameClient", void 0);
        }

        onLoad() {
          this.GameMgr.sceneMgr = this;
          this.TouchCtrl.sceneMgr = this;
        }

        start() {
          this.gateClient = globalThis.getGateClient("http://127.0.0.1:7100");
          this.refreshList();
          this.stopGame();
        }

        refreshList() {
          var _this = this;

          return _asyncToGenerator(function* () {
            if (!_this.ServerInfoListItemTpl || !_this.ServerListWrap) return;
            var serverListRet = yield _this.gateClient.getGameServers();

            if (!serverListRet.isSucc) {
              var _client$logger;

              (_client$logger = _this.gateClient.client.logger) === null || _client$logger === void 0 ? void 0 : _client$logger.error("获取游戏服务器列表失败:" + serverListRet.err);
              return;
            }

            _this.ServerListWrap.removeAllChildren();

            serverListRet.res.GameServerList.forEach(serverInfo => {
              var itemNode = instantiate(_this.ServerInfoListItemTpl);
              var siComp = itemNode.getComponent(_crd && ServerListItem === void 0 ? (_reportPossibleCrUseOfServerListItem({
                error: Error()
              }), ServerListItem) : ServerListItem);

              if (siComp) {
                var _this$ServerListWrap;

                siComp.serverInfo = serverInfo;

                siComp.onClick = sv => _this.onServerItemClick(sv);

                (_this$ServerListWrap = _this.ServerListWrap) === null || _this$ServerListWrap === void 0 ? void 0 : _this$ServerListWrap.addChild(itemNode);
              }
            });
          })();
        }

        onServerItemClick(sv) {
          var _this2 = this;

          return _asyncToGenerator(function* () {
            if (!_this2.gateClient) return; //从入口服务器获取登录token,这是模拟登录的实现(正常需要输入用户名或密码,或者第三方授权,在入口服务器获得登录token)

            var ret = yield _this2.gateClient.loginByCustomUserName(sv, "testUser");

            if (!ret.succ) {
              var _this2$gateClient$cli;

              return (_this2$gateClient$cli = _this2.gateClient.client.logger) === null || _this2$gateClient$cli === void 0 ? void 0 : _this2$gateClient$cli.error(ret.err);
            } //登录到游戏服务器


            _this2.gameClient = globalThis.getGameClient(sv.serverWSUrl);

            _this2.gameClient.disconnectHandler = () => {
              return true;
            };

            _this2.gameClient.onReconnectResult = (succ, err) => {
              if (!succ) {
                _this2.stopGame();
              }

              return;
            };

            var err = yield _this2.gameClient.login(ret.data);

            if (err) {
              var _this2$gateClient$cli2;

              //登录失败, 简单抛个错误
              return (_this2$gateClient$cli2 = _this2.gateClient.client.logger) === null || _this2$gateClient$cli2 === void 0 ? void 0 : _this2$gateClient$cli2.error(err);
            }

            if (_this2.ViewServerList) _this2.ViewServerList.active = false;
            if (_this2.ViewGameUI) _this2.ViewGameUI.active = true;
            if (_this2.ViewGame3D) _this2.ViewGame3D.active = true;

            _this2.startGame();
          })();
        }

        onExitGameClick() {
          var _this3 = this;

          return _asyncToGenerator(function* () {
            _this3.stopGame();
          })();
        }

        stopGame() {
          if (this.ViewServerList) this.ViewServerList.active = true;
          if (this.ViewGameUI) this.ViewGameUI.active = false;
          if (this.ViewGame3D) this.ViewGame3D.active = false;
          this.GameMgr.exitGame();
        }

        startGame() {
          this.GameMgr.enterGame();
        }

        update(dt) {}

        lateUpdate() {}

      }, _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "ServerInfoListItemTpl", [_dec2], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "ServerListWrap", [_dec3], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "ViewServerList", [_dec4], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "ViewGameUI", [_dec5], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "ViewGame3D", [_dec6], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "MainCamera", [_dec7], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "GameMgr", [_dec8], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "TouchCtrl", [_dec9], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      })), _class2)) || _class));

      _cclegacy._RF.pop();

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