2020-03-01 23:18:15 +00:00
|
|
|
extends Spatial
|
|
|
|
|
2020-04-02 18:24:42 +00:00
|
|
|
var plan : Plan = Plan.new()
|
2020-04-18 17:26:09 +00:00
|
|
|
var is_local : bool = false
|
2020-03-01 23:18:15 +00:00
|
|
|
|
2020-04-18 17:26:09 +00:00
|
|
|
func init() -> void:
|
|
|
|
get_parent().get_parent().console_print("Player is set to local? " + String(is_local))
|
|
|
|
if is_local:
|
|
|
|
$MainPanel.visible = true
|
|
|
|
$ThrustPanel.visible = true
|
2020-03-01 23:18:15 +00:00
|
|
|
|
2020-04-18 17:26:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_TimeBar_value_changed(value : float) -> void:
|
|
|
|
var min_time : float = plan.current_time()
|
|
|
|
get_parent().get_parent().console_print("Current plan time is " + String(min_time))
|
|
|
|
if value <= min_time:
|
|
|
|
$MainPanel/TimeBar.value = min_time
|
|
|
|
|
|
|
|
|
|
|
|
func _on_AddButton_pressed() -> void:
|
|
|
|
var new_thrust_element : ThrustElement = ThrustElement.new()
|
|
|
|
new_thrust_element.linear_thrust = get_linear_vector()
|
|
|
|
new_thrust_element.rotational_thrust = get_rotational_vector()
|
|
|
|
new_thrust_element.time = $MainPanel/TimeBar.value - plan.current_time()
|
|
|
|
if (plan.add_element(new_thrust_element)):
|
|
|
|
get_parent().get_parent().console_print("Added thrust element")
|
|
|
|
else:
|
|
|
|
get_parent().get_parent().console_print("Failed to add thrust element")
|
|
|
|
|
|
|
|
|
|
|
|
func _on_RemoveButton_pressed() -> void:
|
|
|
|
plan.remove_last_element()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ClearButton_pressed() -> void:
|
|
|
|
plan.remove_all_elements()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_EndTurnButton_pressed() -> void:
|
|
|
|
plan.new_turn()
|
|
|
|
# TODO: Add the rest functionality
|
|
|
|
|
|
|
|
|
|
|
|
func get_linear_vector() -> Vector3:
|
|
|
|
return Vector3($ThrustPanel/XLin.value, $ThrustPanel/YLin.value, $ThrustPanel/ZLin.value)
|
|
|
|
|
|
|
|
func get_rotational_vector() -> Vector3:
|
|
|
|
return Vector3($ThrustPanel/XRot.value, $ThrustPanel/YRot.value, $ThrustPanel/ZRot.value)
|
|
|
|
|
|
|
|
func _on_XLin_value_changed(value : float) -> void:
|
|
|
|
get_parent().get_parent().console_print("Length of vector = " + String(get_linear_vector().length()))
|
|
|
|
if get_linear_vector().length() < 1.0:
|
|
|
|
return
|
|
|
|
$ThrustPanel/XLin.value = sign($ThrustPanel/XLin.value) * \
|
|
|
|
sqrt(1 - pow($ThrustPanel/YLin.value, 2) - pow($ThrustPanel/ZLin.value, 2))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_XRot_value_changed(value : float) -> void:
|
|
|
|
if get_rotational_vector().length() < 1.0:
|
|
|
|
return
|
|
|
|
$ThrustPanel/XRot.value = sign($ThrustPanel/XRot.value) * \
|
|
|
|
sqrt(1 - pow($ThrustPanel/YRot.value, 2) - pow($ThrustPanel/ZRot.value, 2))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_YLin_value_changed(value : float) -> void:
|
|
|
|
if get_linear_vector().length() < 1.0:
|
|
|
|
return
|
|
|
|
$ThrustPanel/YLin.value = sign($ThrustPanel/YLin.value) * \
|
|
|
|
sqrt(1 - pow($ThrustPanel/XLin.value, 2) - pow($ThrustPanel/ZLin.value, 2))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_YRot_value_changed(value : float) -> void:
|
|
|
|
if get_rotational_vector().length() < 1.0:
|
|
|
|
return
|
|
|
|
$ThrustPanel/YRot.value = sign($ThrustPanel/YRot.value) * \
|
|
|
|
sqrt(1 - pow($ThrustPanel/XRot.value, 2) - pow($ThrustPanel/ZRot.value, 2))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ZLin_value_changed(value : float) -> void:
|
|
|
|
if get_linear_vector().length() < 1.0:
|
|
|
|
return
|
|
|
|
$ThrustPanel/ZLin.value = sign($ThrustPanel/ZLin.value) * \
|
|
|
|
sqrt(1 - pow($ThrustPanel/YLin.value, 2) - pow($ThrustPanel/XLin.value, 2))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ZRot_value_changed(value : float) -> void:
|
|
|
|
if get_rotational_vector().length() < 1.0:
|
|
|
|
return
|
|
|
|
$ThrustPanel/ZRot.value = sign($ThrustPanel/ZRot.value) * \
|
|
|
|
sqrt(1 - pow($ThrustPanel/YRot.value, 2) - pow($ThrustPanel/XRot.value, 2))
|