extends Node

onready var fps_label = get_node("Status/FPS")
onready var debug_label = get_node("Status/Debug")
onready var car = get_node("Monteri")
onready var fl_wheel_controller = get_node("Monteri/FL")
onready var fr_wheel_controller = get_node("Monteri/FR")
onready var rl_wheel_controller = get_node("Monteri/RL")
onready var rr_wheel_controller = get_node("Monteri/RR")


func _process(_delta):
	if Input.is_action_just_released("ui_cancel"):
		get_tree().quit()
	var fps = Performance.get_monitor(Performance.TIME_FPS)
	var speed: float = car.linear_velocity.length()
	var acceleration: float = car.acceleration_measurement
	var force_ratio: float = car.get_acceleration_force_relative()
	var velocity_rear_axis: float = car.get_velocity_rear_axis()
	var turn_radius: float = car.get_turn_radius(speed)
	var grip: bool = car.get_grip()
	var grip_force: float = car.get_grip_force()
	var omega_reference = car.get_omega_reference()
	var omega_measurement = car.angular_velocity.y
	var format = "FPS: %2.0f"
	var fl_force: Vector3 = fl_wheel_controller.get_force()
	var fl_offset: Vector3 = fl_wheel_controller.get_offset()
	var fr_force: Vector3 = fr_wheel_controller.get_force()
	var fr_offset: Vector3 = fr_wheel_controller.get_offset()
	var rl_force: Vector3 = rl_wheel_controller.get_force()
	var rl_offset: Vector3 = rl_wheel_controller.get_offset()
	var rr_force: Vector3 = rr_wheel_controller.get_force()
	var rr_offset: Vector3 = rr_wheel_controller.get_offset()
	fps_label.text = format % fps
	format = "Speed: %.0f m/s (Acceleration: %.1f)\n"
	format += "Force Ratio: %.2f\n"
	format += "Velocity Rear: %.0f m/s\n\n"
	format += "Grip: %s\n"
	format += "Grip Force: %.1f N\n\n"
	format += "Omega: %.1f (ref: %.1f)\n"
	format += "Turn Radius: %.0f m\n\n"
	format += "FL force: %.1f N\nFL offset: (%.1f %.1f %.1f)\n\n"
	format += "FR force: %.1f N\nFR offset: (%.1f %.1f %.1f)\n\n"
	format += "RL force: %.1f N\nRL offset: (%.1f %.1f %.1f)\n\n"
	format += "RR force: %.1f N\nRR offset: (%.1f %.1f %.1f)\n\n"
	debug_label.text = format % [speed, acceleration, force_ratio, velocity_rear_axis, grip, grip_force, omega_measurement, omega_reference, turn_radius, fl_force.y, fl_offset.x, fl_offset.y, fl_offset.z, fr_force.y, fr_offset.x, fr_offset.y, fr_offset.z, rl_force.y, rl_offset.x, rl_offset.y, rl_offset.z, rr_force.y, rr_offset.x, rr_offset.y, rr_offset.z]
