extends StaticBody2D class_name Base enum DockState { Ready, Process, Busy } signal dock_requested ## Reference to star system @onready var star_system: StarSystem = get_tree().current_scene @onready var gate_static = $Gate @onready var gate_area = $GateArea @onready var dock_area = $DockingArea @export var faction: Game.Faction var dock_state: DockState = DockState.Ready var touching_gate = false var touching_dock = false var player_ship = null func _ready(): mouse_entered.connect(star_system.set_targeted_node.bind(self)) mouse_exited.connect(star_system.clear_targeted_node) gate_area.body_entered.connect(gate_area_body_entered) gate_area.body_exited.connect(gate_area_body_exited) dock_area.body_entered.connect(dock_area_body_entered) dock_area.body_exited.connect(dock_area_body_exited) dock_requested.connect(on_dock_requested) dock_ready() ## Switches dock state func on_dock_requested(): player_ship = star_system.player_ship match dock_state: DockState.Ready: dock_process() DockState.Process: dock_ready() func gate_area_body_entered(body): if body.ship is PlayerShip: touching_gate = true func gate_area_body_exited(body): if body.ship is PlayerShip: touching_gate = false func dock_area_body_entered(body): if body.ship is PlayerShip: touching_dock = true func dock_area_body_exited(body): if body.ship is PlayerShip: touching_dock = false func _process(_delta): if dock_state == DockState.Process: var distance_to_player = global_position.distance_to(player_ship.global_position) if touching_dock and !touching_gate: dock_busy() if !touching_dock and !touching_gate and distance_to_player > 2048: dock_ready() ## Sets dock state to Ready func dock_ready(): dock_state = DockState.Ready gate_static.visible = true gate_static.process_mode = Node.PROCESS_MODE_INHERIT gate_area.visible = false dock_area.visible = false touching_gate = false touching_dock = false ## Sets dock state to Process func dock_process(): dock_state = DockState.Process gate_static.visible = false gate_static.process_mode = Node.PROCESS_MODE_DISABLED gate_area.visible = true dock_area.visible = true touching_gate = false touching_dock = false ## Sets dock state to Busy func dock_busy(): dock_state = DockState.Busy gate_static.visible = true gate_static.process_mode = Node.PROCESS_MODE_INHERIT gate_area.visible = false dock_area.visible = false touching_gate = false touching_dock = true # TODO: implement opening the base menu