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

  var _cclegacy, Component, EventMouse, Input, input, KeyCode, Vec3, _decorator, _dec, _class, _class2, _descriptor, _descriptor2, _descriptor3, _crd, ccclass, property, INPUT, CameraCtrl;

  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 _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.'); }

  return {
    setters: [function (_cc) {
      _cclegacy = _cc.cclegacy;
      Component = _cc.Component;
      EventMouse = _cc.EventMouse;
      Input = _cc.Input;
      input = _cc.input;
      KeyCode = _cc.KeyCode;
      Vec3 = _cc.Vec3;
      _decorator = _cc._decorator;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "2cb60eqRUhET5w+/IxUeyqx", "CameraControl", undefined);

      ({
        ccclass,
        property
      } = _decorator);

      _export("INPUT", INPUT = {
        LEFT: 0,
        RIGHT: 0,
        UP: 0,
        DOWN: 0,
        FOWARD: 0,
        BACKWARD: 0,
        ZOOM: 0,
        ROTATE: 0,
        ROTATE_PARAMS: {
          x: 0,
          y: 0
        }
      });

      _export("CameraCtrl", CameraCtrl = (_dec = ccclass('CameraCtrl'), _dec(_class = (_class2 = class CameraCtrl extends Component {
        constructor() {
          super(...arguments);

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

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

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

          this.velocity = new Vec3();
          this.rotateVelocity = new Vec3();
        }

        /* -- LIFE CYCLE -- */
        onLoad() {
          this.addListener();
        }

        start() {}

        update(dt) {
          this.cameraMove(dt);
        }

        onDestroy() {
          this.removeListener();
        }
        /* -- METHODS -- */


        getVelocaity() {
          return this.velocity;
        }

        addListener() {
          input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
          input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
          input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
          input.on(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
          input.on(Input.EventType.MOUSE_UP, this.onMouseUp, this);
          input.on(Input.EventType.MOUSE_WHEEL, this.onMouseWheel, this);
        }

        removeListener() {
          input.off(Input.EventType.KEY_DOWN, this.onKeyDown, this);
          input.off(Input.EventType.KEY_UP, this.onKeyUp, this);
          input.off(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
          input.off(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
          input.off(Input.EventType.MOUSE_UP, this.onMouseUp, this);
          input.off(Input.EventType.MOUSE_WHEEL, this.onMouseWheel, this);
        }

        onKeyDown(event) {
          switch (event.keyCode) {
            case KeyCode.KEY_A:
              INPUT.LEFT = 1;
              break;

            case KeyCode.KEY_D:
              INPUT.RIGHT = 1;
              break;

            case KeyCode.KEY_W:
              INPUT.FOWARD = 1;
              break;

            case KeyCode.KEY_S:
              INPUT.BACKWARD = 1;
              break;

            case KeyCode.SPACE:
            case KeyCode.KEY_E:
              INPUT.UP = 1;
              break;

            case KeyCode.CTRL_LEFT:
            case KeyCode.KEY_Q:
              INPUT.DOWN = 1;
              break;
          }
        }

        onKeyUp(event) {
          switch (event.keyCode) {
            case KeyCode.KEY_A:
              INPUT.LEFT = 0;
              break;

            case KeyCode.KEY_D:
              INPUT.RIGHT = 0;
              break;

            case KeyCode.KEY_W:
              INPUT.FOWARD = 0;
              break;

            case KeyCode.KEY_S:
              INPUT.BACKWARD = 0;
              break;

            case KeyCode.SPACE:
            case KeyCode.KEY_E:
              INPUT.UP = 0;
              break;

            case KeyCode.CTRL_LEFT:
            case KeyCode.KEY_Q:
              INPUT.DOWN = 0;
              break;
          }
        }

        onMouseMove(event) {
          if (INPUT.ROTATE === 1) {
            INPUT.ROTATE_PARAMS.x = event.movementX;
            INPUT.ROTATE_PARAMS.y = event.movementY;
          }
        }

        onMouseDown(event) {
          switch (event.getButton()) {
            case EventMouse.BUTTON_RIGHT:
              INPUT.ROTATE = 1;
              break;
          }
        }

        onMouseUp(event) {
          switch (event.getButton()) {
            case EventMouse.BUTTON_RIGHT:
              INPUT.ROTATE = 0;
              break;
          }
        }

        onMouseWheel(event) {
          INPUT.ZOOM = event.getScrollY();
        }

        cameraMove(dt) {
          this.velocity.set(0, 0, 0);

          if (INPUT.LEFT === 1) {
            this.velocity.subtract(this.node.right);
          }

          if (INPUT.RIGHT === 1) {
            this.velocity.add(this.node.right);
          }

          if (INPUT.FOWARD === 1) {
            this.velocity.add(this.node.forward);
          }

          if (INPUT.BACKWARD === 1) {
            this.velocity.subtract(this.node.forward);
          }

          if (INPUT.UP === 1) {
            this.velocity.add(Vec3.UP);
          }

          if (INPUT.DOWN === 1) {
            this.velocity.subtract(Vec3.UP);
          }

          if (INPUT.ZOOM !== 0) {
            Vec3.multiplyScalar(this.velocity, this.node.forward, INPUT.ZOOM * this.zoomSpeed);
            INPUT.ZOOM = 0;
          }

          var newPos = this.node.worldPosition.add(this.velocity.multiplyScalar(this.speed * dt));
          this.node.setWorldPosition(newPos);

          if (INPUT.ROTATE === 1) {
            var eulerAngles = this.node.eulerAngles;
            this.rotateVelocity.set(-INPUT.ROTATE_PARAMS.y, -INPUT.ROTATE_PARAMS.x, 0);
            this.node.setRotationFromEuler(eulerAngles.add(this.rotateVelocity.multiplyScalar(this.rotateSpeed * dt)));
            INPUT.ROTATE_PARAMS.x = 0;
            INPUT.ROTATE_PARAMS.y = 0;
          }
        }

      }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "speed", [property], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function initializer() {
          return 100;
        }
      }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "rotateSpeed", [property], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function initializer() {
          return 10;
        }
      }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "zoomSpeed", [property], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function initializer() {
          return 0.05;
        }
      })), _class2)) || _class));

      _cclegacy._RF.pop();

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