"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const godot_1 = require("godot");
const godot_annotations_1 = require("godot.annotations");
const message_bus_1 = __importDefault(require("./message_bus"));
class Player extends godot_1.CharacterBody3D {
    constructor() {
        super(...arguments);
        this.gravity = godot_1.ProjectSettings.get_setting('physics/3d/default_gravity');
        this.walk_speed = 3;
        this.walk_backward_speed = 2;
        this.run_speed = 6;
        this.turn_speed = 1;
        this._rotation_speed = 2 * Math.PI;
    }
    _ready() {
        this._rotation_speed = this.turn_speed * 2 * Math.PI;
        this._player_input = this.get_node(this.player_input);
        this._camera = this.get_viewport().get_camera_3d();
        message_bus_1.default.instance.active_camera_changed.connect(godot_1.Callable.create(this, this.on_camera_changed));
    }
    get_movement(delta) {
        const input = this._player_input.movement_input;
        return godot_1.Vector3.MULTIPLY(this.walk_speed, new godot_1.Vector3(input.x, 0, input.y));
    }
    //get_translation(_delta: float64): Vector3 {
    //  const forward = Vector3.MULTIPLY(-1, this.transform.basis.z)
    //  return Vector3.MULTIPLY(forward, this.get_movement())
    //}
    get_gravitational_force(delta) {
        return -this.gravity * delta;
    }
    relative_to(target, vec) {
        return vec.rotated(godot_1.Vector3.UP, target.rotation.y);
    }
    on_camera_changed(camera) {
        this._camera = camera;
    }
    _physics_process(delta) {
        const movement = this.relative_to(this._camera, this.get_movement(delta));
        if (!movement.is_zero_approx()) {
            this.look_at(godot_1.Vector3.NEGATE(godot_1.Vector3.ADD(this.position, movement)), godot_1.Vector3.UP);
        }
        this.velocity = new godot_1.Vector3(movement.x, this.velocity.y + this.get_gravitational_force(delta), movement.z);
        this.move_and_slide();
    }
}
exports.default = Player;
__decorate([
    (0, godot_annotations_1.export_)(godot_1.Variant.Type.TYPE_NODE_PATH)
], Player.prototype, "player_input", void 0);
__decorate([
    (0, godot_annotations_1.help)('Forward walk speed in units per second'),
    (0, godot_annotations_1.export_)(godot_1.Variant.Type.TYPE_FLOAT)
], Player.prototype, "walk_speed", void 0);
__decorate([
    (0, godot_annotations_1.help)('Backward walk speed in units per second'),
    (0, godot_annotations_1.export_)(godot_1.Variant.Type.TYPE_FLOAT)
], Player.prototype, "walk_backward_speed", void 0);
__decorate([
    (0, godot_annotations_1.help)('Run speed in units per second'),
    (0, godot_annotations_1.export_)(godot_1.Variant.Type.TYPE_FLOAT)
], Player.prototype, "run_speed", void 0);
__decorate([
    (0, godot_annotations_1.help)('Turn speed in rotations per second'),
    (0, godot_annotations_1.export_)(godot_1.Variant.Type.TYPE_FLOAT)
], Player.prototype, "turn_speed", void 0);
//# sourceMappingURL=player.js.map