From e2e8fb987f6b615cf7517a46639d9f2e9795b521 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 22 Aug 2024 22:50:22 +0100 Subject: [PATCH 1/8] Add blank line before starting tool --- script/claude.py | 1 + 1 file changed, 1 insertion(+) diff --git a/script/claude.py b/script/claude.py index 6c312fdd..0249879a 100755 --- a/script/claude.py +++ b/script/claude.py @@ -188,6 +188,7 @@ def check_continue() -> bool: case "content_block_start": if event.content_block.type == "tool_use": + console.print("\n") current_tool = event.content_block.name status = Status(f"{current_tool}…") status.start() From c2e1e52cb87da0b7d2755aff28f75b2449994fa8 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 22 Aug 2024 23:10:07 +0100 Subject: [PATCH 2/8] Multi-step jump path --- actors/player.gd | 13 +++-- galaxy/map/galaxy_map.gd | 49 +++++++++++++---- mechanics/hyperspace/hyperdrive_system.gd | 53 +++++++++++++------ .../hyperspace/hyperspace_scene_switcher.gd | 8 +-- screens/game/game.tscn | 6 +-- screens/game/hud/jump_destination_name.gd | 6 +-- 6 files changed, 95 insertions(+), 40 deletions(-) diff --git a/actors/player.gd b/actors/player.gd index d4c42a26..7024f296 100644 --- a/actors/player.gd +++ b/actors/player.gd @@ -137,8 +137,8 @@ func _on_hyperdrive_changed() -> void: func _next_system_connection() -> StarSystem: var current_destination_name: Variant = null - if self.ship.hyperdrive_system.jump_destination: - current_destination_name = self.ship.hyperdrive_system.jump_destination.name + if self.ship.hyperdrive_system.get_jump_destination(): + current_destination_name = self.ship.hyperdrive_system.get_jump_destination().name var current_system := self.ship.hyperdrive_system.current_system() var galaxy: Galaxy = current_system.galaxy.get_ref() @@ -175,7 +175,12 @@ func _unhandled_key_input(event: InputEvent) -> void: return if event.is_action_pressed("cycle_jump_destination", true): - self.ship.hyperdrive_system.jump_destination = self._next_system_connection() + var next_system := self._next_system_connection() + if next_system: + self.ship.hyperdrive_system.set_jump_path([next_system]) + else: + self.ship.hyperdrive_system.clear_jump_path() + self.get_viewport().set_input_as_handled() if event.is_action_pressed("cycle_target", true): @@ -212,7 +217,7 @@ func _on_broadcasted_input_event(receiver: Node, event: InputEvent) -> void: return func _jump_to_hyperspace() -> void: - if not self.ship.hyperdrive_system.jump_destination: + if not self.ship.hyperdrive_system.get_jump_destination(): return if not self.hyperspace_scene_switcher.start_jump(): diff --git a/galaxy/map/galaxy_map.gd b/galaxy/map/galaxy_map.gd index d0e5e48e..76b783f0 100644 --- a/galaxy/map/galaxy_map.gd +++ b/galaxy/map/galaxy_map.gd @@ -34,9 +34,19 @@ var hyperdrive_system: HyperdriveSystem ## Maps from each [member StarSystem.name] to the [GalaxyMapSystem] used to represent it. var _system_nodes: Dictionary = {} +## Line used to display the jump path +#var _jump_path_line: ImmediateGeometry3D + func _ready() -> void: self.hyperdrive_system.jumping_changed.connect(_on_jumping_changed) - self.hyperdrive_system.jump_destination_changed.connect(_on_jump_destination_changed) + self.hyperdrive_system.jump_path_changed.connect(_on_jump_path_changed) + + #_jump_path_line = ImmediateGeometry3D.new() + #_jump_path_line.material_override = StandardMaterial3D.new() + #_jump_path_line.material_override.albedo_color = Color(0, 1, 0, 0.5) # Semi-transparent green + #_jump_path_line.material_override.flags_unshaded = true + #_jump_path_line.material_override.flags_transparent = true + #galaxy_map_3d.add_child(_jump_path_line) var current_system := self.hyperdrive_system.current_system() @@ -74,18 +84,32 @@ func _on_jumping_changed(_hyperdrive_system: HyperdriveSystem) -> void: self.camera.center = new_system.position self._system_nodes[new_system.name].current = true -func _on_jump_destination_changed(_hyperdrive_system: HyperdriveSystem) -> void: +func _on_jump_path_changed(_hyperdrive_system: HyperdriveSystem) -> void: assert(self.hyperdrive_system == _hyperdrive_system) self._update_selection_state() +#func _update_jump_path_line() -> void: +# _jump_path_line.clear() +# _jump_path_line.begin(Mesh.PRIMITIVE_LINE_STRIP) +# +# var current_system = self.hyperdrive_system.current_system() +# _jump_path_line.add_vertex(current_system.position) +# +# for system in self.hyperdrive_system.jump_path: +# _jump_path_line.add_vertex(system.position) +# +# _jump_path_line.end() + func _update_selection_state() -> void: + var jump_path := self.hyperdrive_system.get_jump_path() + var jump_names := jump_path.map(func(system: StarSystem) -> StringName: return system.name) for system_name: String in self._system_nodes: var node: GalaxyMapSystem = self._system_nodes[system_name] - node.selected = self.hyperdrive_system.jump_destination and self.hyperdrive_system.jump_destination.name == system_name + node.selected = system_name in jump_names var presented_system: StarSystem - if self.hyperdrive_system.jump_destination: - presented_system = self.hyperdrive_system.jump_destination + if jump_path: + presented_system = jump_path[-1] self.current_or_destination_heading.text = "Destination system" else: presented_system = self.hyperdrive_system.current_system() @@ -158,13 +182,13 @@ func _on_system_clicked(star_system: StarSystem, _system_node: GalaxyMapSystem) return if star_system == self.hyperdrive_system.current_system(): - self.hyperdrive_system.jump_destination = null + self.hyperdrive_system.clear_jump_path() return - if star_system.name not in self.hyperdrive_system.current_system().connections: - return - - self.hyperdrive_system.jump_destination = star_system + if Input.is_key_pressed(KEY_SHIFT): + self.hyperdrive_system.add_to_jump_path(star_system) + else: + self.hyperdrive_system.set_jump_path([star_system]) func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void: if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: @@ -179,4 +203,7 @@ func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hype else: return - self.hyperdrive_system.jump_destination = connection + if Input.is_key_pressed(KEY_SHIFT): + self.hyperdrive_system.add_to_jump_path(connection) + else: + self.hyperdrive_system.set_jump_path([connection]) diff --git a/mechanics/hyperspace/hyperdrive_system.gd b/mechanics/hyperspace/hyperdrive_system.gd index 659c8630..a8b5fecd 100644 --- a/mechanics/hyperspace/hyperdrive_system.gd +++ b/mechanics/hyperspace/hyperdrive_system.gd @@ -13,7 +13,7 @@ var hyperdrive: Hyperdrive ## At the moment, changing this has no effect besides firing [signal jumping_changed]. var jumping: bool = false: set(value): - assert(not value or self.jump_destination != null, "If jumping, a jump destination should already be set") + assert(not value or self._jump_path, "If jumping, a jump path should already be set") if jumping == value: return @@ -21,26 +21,17 @@ var jumping: bool = false: jumping = value self.jumping_changed.emit(self) -## The current jump destination, if one is selected. -var jump_destination: StarSystem = null: - set(value): - assert(value != self.current_system(), "Jump destination should not be the same as the current system") - assert(value == null or value.name in self.current_system().connections, "Jump destination should be connected to the current system") - - if jump_destination == value: - return - - jump_destination = value - self.jump_destination_changed.emit(self) - ## The [Ship] this hyperdrive system is attached to. @onready var ship := get_parent() as Ship +## The planned multi-step hyperspace path. +var _jump_path: Array[StarSystem] = [] + ## Fires when [member jumping] changes. signal jumping_changed(hyperdrive_system: HyperdriveSystem) -## Fires when [member jump_destination] changes. -signal jump_destination_changed(hyperdrive_system: HyperdriveSystem) +## Fires when the [member jump_path] changes. +signal jump_path_changed(hyperdrive_system: HyperdriveSystem) ## The current system the ship is located in. func current_system() -> StarSystem: @@ -50,3 +41,35 @@ func current_system() -> StarSystem: return null return instance.star_system + +## Returns the planned jump path. +func get_jump_path() -> Array[StarSystem]: + return self._jump_path.duplicate() + +## Returns the immediately next jump destination. +func get_jump_destination() -> StarSystem: + return self._jump_path[0] if self._jump_path else null + +## Sets the planned jump path. +func set_jump_path(path: Array[StarSystem]) -> void: + if path == self._jump_path: + return + + self._jump_path = path.duplicate() + self.jump_path_changed.emit(self) + +## Adds a system to the end of the jump path. +func add_to_jump_path(system: StarSystem) -> void: + self._jump_path.append(system) + self.jump_path_changed.emit(self) + +## Clears the current jump path. +func clear_jump_path() -> void: + self._jump_path.clear() + self.jump_path_changed.emit(self) + +## Updates the jump path after a successful jump. +func shift_jump_path() -> void: + assert(self._jump_path, "Jump path must not be empty") + self._jump_path.pop_front() + self.jump_path_changed.emit(self) diff --git a/mechanics/hyperspace/hyperspace_scene_switcher.gd b/mechanics/hyperspace/hyperspace_scene_switcher.gd index 70ecec54..dd40c8fc 100644 --- a/mechanics/hyperspace/hyperspace_scene_switcher.gd +++ b/mechanics/hyperspace/hyperspace_scene_switcher.gd @@ -39,8 +39,8 @@ func start_jump() -> bool: if not self._hyperdrive_system.hyperdrive.consume_for_jump(): return false - if not self._loaded_system_nodes.has(self._hyperdrive_system.jump_destination.name): - ResourceLoader.load_threaded_request(self._hyperdrive_system.jump_destination.scene_path) + if not self._loaded_system_nodes.has(self._hyperdrive_system.get_jump_destination().name): + ResourceLoader.load_threaded_request(self._hyperdrive_system.get_jump_destination().scene_path) self._hyperdrive_system.jumping = true return true @@ -48,7 +48,7 @@ func start_jump() -> bool: func load_jump_destination() -> void: assert(self._hyperdrive_system.jumping, "Expected a jump to be in progress") - var destination := self._hyperdrive_system.jump_destination + var destination := self._hyperdrive_system.get_jump_destination() assert(destination, "Expected to have a jump destination") var player_ship := self._hyperdrive_system.ship @@ -71,7 +71,7 @@ func load_jump_destination() -> void: self.player.calendar.pass_approximate_days(HYPERSPACE_APPROXIMATE_TRAVEL_DAYS) - self._hyperdrive_system.jump_destination = null + self._hyperdrive_system.shift_jump_path() self.jump_destination_loaded.emit(star_system_instance) func finish_jump() -> void: diff --git a/screens/game/game.tscn b/screens/game/game.tscn index 53b3a337..d5730ce4 100644 --- a/screens/game/game.tscn +++ b/screens/game/game.tscn @@ -102,7 +102,7 @@ script = ExtResource("11_ag0i7") max_volume = 10.0 commodities = {} -[sub_resource type="Resource" id="Resource_0rcb3"] +[sub_resource type="Resource" id="Resource_kn2lj"] resource_local_to_scene = true script = ExtResource("13_q2g24") max_fuel = 6.0 @@ -183,7 +183,7 @@ hull = SubResource("Resource_ffax2") shield = SubResource("Resource_75c8j") battery = SubResource("Resource_xpwk4") cargo_hold = SubResource("Resource_bsv1l") -hyperdrive = SubResource("Resource_0rcb3") +hyperdrive = SubResource("Resource_kn2lj") [node name="CombatObject" parent="HyperspaceSceneSwitcher/Sol/PlayerCorvette" index="3" node_paths=PackedStringArray("targeted_sound")] targeted_sound = NodePath("../Player/TargetedSound") @@ -644,7 +644,7 @@ script = ExtResource("37_e11x7") [connection signal="jump_destination_loaded" from="HyperspaceSceneSwitcher" to="HyperspaceSceneSwitcher/Sol/PlayerCorvette/Player" method="_on_jump_destination_loaded"] [connection signal="jump_destination_loaded" from="HyperspaceSceneSwitcher" to="InGameGUI/MarginContainer/HBoxContainer/Sidebar/SystemName" method="_on_jump_destination_loaded"] -[connection signal="jump_destination_changed" from="HyperspaceSceneSwitcher/Sol/PlayerCorvette/HyperdriveSystem" to="InGameGUI/MarginContainer/HBoxContainer/Sidebar/PanelContainer/VBoxContainer/JumpDestinationName" method="_on_jump_destination_changed"] +[connection signal="jump_path_changed" from="HyperspaceSceneSwitcher/Sol/PlayerCorvette/HyperdriveSystem" to="InGameGUI/MarginContainer/HBoxContainer/Sidebar/PanelContainer/VBoxContainer/JumpDestinationName" method="_on_jump_path_changed"] [connection signal="jumping_changed" from="HyperspaceSceneSwitcher/Sol/PlayerCorvette/HyperdriveSystem" to="MainCameraTransform/MainCamera/HyperspaceEffect" method="_on_jumping_changed"] [connection signal="hull_changed" from="HyperspaceSceneSwitcher/Sol/PlayerCorvette/Player" to="InGameGUI/MarginContainer/HBoxContainer/Sidebar/PlayerVitalsContainer/VBoxContainer/PlayerVitals" method="_on_player_hull_changed"] [connection signal="hyperdrive_changed" from="HyperspaceSceneSwitcher/Sol/PlayerCorvette/Player" to="InGameGUI/MarginContainer/HBoxContainer/Sidebar/PanelContainer/VBoxContainer/FuelBar" method="_on_player_hyperdrive_changed"] diff --git a/screens/game/hud/jump_destination_name.gd b/screens/game/hud/jump_destination_name.gd index e76c5582..31c37953 100644 --- a/screens/game/hud/jump_destination_name.gd +++ b/screens/game/hud/jump_destination_name.gd @@ -2,9 +2,9 @@ extends Label @export var pick_sound: AudioStreamPlayer -func _on_jump_destination_changed(hyperdrive_system: HyperdriveSystem) -> void: - if hyperdrive_system.jump_destination == null: +func _on_jump_path_changed(hyperdrive_system: HyperdriveSystem) -> void: + if hyperdrive_system.get_jump_destination() == null: self.text = "" else: - self.text = hyperdrive_system.jump_destination.name + self.text = hyperdrive_system.get_jump_destination().name self.pick_sound.play() From 13340d1b5063e1fd84a9230886575550c35f61c8 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 22 Aug 2024 23:23:04 +0100 Subject: [PATCH 3/8] Fix path editing --- galaxy/map/galaxy_map.gd | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/galaxy/map/galaxy_map.gd b/galaxy/map/galaxy_map.gd index 76b783f0..f3b5a3fc 100644 --- a/galaxy/map/galaxy_map.gd +++ b/galaxy/map/galaxy_map.gd @@ -186,9 +186,32 @@ func _on_system_clicked(star_system: StarSystem, _system_node: GalaxyMapSystem) return if Input.is_key_pressed(KEY_SHIFT): - self.hyperdrive_system.add_to_jump_path(star_system) + self._update_multi_path(star_system) else: - self.hyperdrive_system.set_jump_path([star_system]) + self._replace_single_path(star_system) + +func _update_multi_path(star_system: StarSystem) -> void: + var current_path := self.hyperdrive_system.get_jump_path() + if not current_path: + return self._replace_single_path(star_system) + + var current_path_names := self.hyperdrive_system.get_jump_path().map(func(system: StarSystem) -> StringName: return system.name) + var index := current_path_names.find(star_system.name) + if index != -1: + # Reset path back to the clicked node + self.hyperdrive_system.set_jump_path(current_path.slice(0, index + 1)) + return + + # Add to end of path + var last_system := current_path[-1] + if star_system.name in last_system.connections: + self.hyperdrive_system.add_to_jump_path(star_system) + +func _replace_single_path(star_system: StarSystem) -> void: + if star_system.name not in self.hyperdrive_system.current_system().connections: + return + + self.hyperdrive_system.set_jump_path([star_system]) func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void: if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: From 4b63ed7638eed235986dbebf6a00c20bcab6410f Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 23 Aug 2024 21:20:12 +0100 Subject: [PATCH 4/8] Somewhat working selection state --- galaxy/map/galaxy_map.gd | 75 ++++++++++++---------------- galaxy/map/galaxy_map_hyperlane.gd | 9 ++++ galaxy/map/galaxy_map_hyperlane.tscn | 4 +- screens/game/game.tscn | 4 +- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/galaxy/map/galaxy_map.gd b/galaxy/map/galaxy_map.gd index f3b5a3fc..4ebe7b28 100644 --- a/galaxy/map/galaxy_map.gd +++ b/galaxy/map/galaxy_map.gd @@ -34,29 +34,23 @@ var hyperdrive_system: HyperdriveSystem ## Maps from each [member StarSystem.name] to the [GalaxyMapSystem] used to represent it. var _system_nodes: Dictionary = {} -## Line used to display the jump path -#var _jump_path_line: ImmediateGeometry3D +## Maps from a hyperlane's name to the [GalaxyMapHyperlane] used to represent it. +## +## Hyperlane names are formatted as "from > to". +var _hyperlane_nodes: Dictionary = {} func _ready() -> void: self.hyperdrive_system.jumping_changed.connect(_on_jumping_changed) self.hyperdrive_system.jump_path_changed.connect(_on_jump_path_changed) - #_jump_path_line = ImmediateGeometry3D.new() - #_jump_path_line.material_override = StandardMaterial3D.new() - #_jump_path_line.material_override.albedo_color = Color(0, 1, 0, 0.5) # Semi-transparent green - #_jump_path_line.material_override.flags_unshaded = true - #_jump_path_line.material_override.flags_transparent = true - #galaxy_map_3d.add_child(_jump_path_line) - var current_system := self.hyperdrive_system.current_system() for system in galaxy.systems: var system_node: GalaxyMapSystem = self.galaxy_map_system.instantiate() - self._system_nodes[system.name] = system_node system_node.clicked.connect(func(node: GalaxyMapSystem) -> void: self._on_system_clicked(system, node)) - system_node.name = system.name system_node.current = (system == current_system) + self._system_nodes[system.name] = system_node self.galaxy_map_3d.add_child(system_node) system_node.transform.origin = system.position @@ -64,11 +58,11 @@ func _ready() -> void: for connection in system.connections: var connected_system := self.galaxy.get_system(connection) var hyperlane: GalaxyMapHyperlane = self.galaxy_map_hyperlane.instantiate() - hyperlane.clicked.connect(func(node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system, node)) - + # hyperlane.clicked.connect(func(node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system, node)) hyperlane.name = "%s > %s" % [system.name, connection] hyperlane.starting_position = system.position hyperlane.ending_position = connected_system.position + self._hyperlane_nodes[hyperlane.name] = hyperlane self.galaxy_map_3d.add_child(hyperlane) self._update_selection_state() @@ -88,18 +82,6 @@ func _on_jump_path_changed(_hyperdrive_system: HyperdriveSystem) -> void: assert(self.hyperdrive_system == _hyperdrive_system) self._update_selection_state() -#func _update_jump_path_line() -> void: -# _jump_path_line.clear() -# _jump_path_line.begin(Mesh.PRIMITIVE_LINE_STRIP) -# -# var current_system = self.hyperdrive_system.current_system() -# _jump_path_line.add_vertex(current_system.position) -# -# for system in self.hyperdrive_system.jump_path: -# _jump_path_line.add_vertex(system.position) -# -# _jump_path_line.end() - func _update_selection_state() -> void: var jump_path := self.hyperdrive_system.get_jump_path() var jump_names := jump_path.map(func(system: StarSystem) -> StringName: return system.name) @@ -107,8 +89,17 @@ func _update_selection_state() -> void: var node: GalaxyMapSystem = self._system_nodes[system_name] node.selected = system_name in jump_names + for hyperlane_name: String in self._hyperlane_nodes: + var node: GalaxyMapHyperlane = self._hyperlane_nodes[hyperlane_name] + node.selected = false + var presented_system: StarSystem if jump_path: + for i in range(0, jump_path.size()): + var last_name := jump_path[i - 1].name if i > 0 else self.hyperdrive_system.current_system().name + var hyperlane_name := "%s > %s" % [last_name, jump_path[i].name] + self._hyperlane_nodes[hyperlane_name].selected = true + presented_system = jump_path[-1] self.current_or_destination_heading.text = "Destination system" else: @@ -213,20 +204,20 @@ func _replace_single_path(star_system: StarSystem) -> void: self.hyperdrive_system.set_jump_path([star_system]) -func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void: - if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: - return - - var current_system := self.hyperdrive_system.current_system() - var connection: StarSystem - if from_system == current_system: - connection = to_system - elif to_system == current_system: - connection = from_system - else: - return - - if Input.is_key_pressed(KEY_SHIFT): - self.hyperdrive_system.add_to_jump_path(connection) - else: - self.hyperdrive_system.set_jump_path([connection]) +# func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void: +# if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: +# return + +# var current_system := self.hyperdrive_system.current_system() +# var connection: StarSystem +# if from_system == current_system: +# connection = to_system +# elif to_system == current_system: +# connection = from_system +# else: +# return + +# if Input.is_key_pressed(KEY_SHIFT): +# self.hyperdrive_system.add_to_jump_path(connection) +# else: +# self.hyperdrive_system.set_jump_path([connection]) diff --git a/galaxy/map/galaxy_map_hyperlane.gd b/galaxy/map/galaxy_map_hyperlane.gd index cfe2931c..fc451dbc 100644 --- a/galaxy/map/galaxy_map_hyperlane.gd +++ b/galaxy/map/galaxy_map_hyperlane.gd @@ -16,6 +16,15 @@ class_name GalaxyMapHyperlane ## This is expected to have a [CylinderMesh] attached. @export var mesh: MeshInstance3D +## When [member selected] is true, this material overrides the [member mesh]'s material. +@export var selected_material: Material + +## Whether this hyperlane is selected. +@export var selected: bool: + set(value): + selected = value + self.mesh.material_override = self.selected_material if value else null + ## The shape defining the clickable region of this hyperlane. ## ## This is expected to have a [CylinderShape3D] attached. diff --git a/galaxy/map/galaxy_map_hyperlane.tscn b/galaxy/map/galaxy_map_hyperlane.tscn index 04ba8fa1..e6a0075f 100644 --- a/galaxy/map/galaxy_map_hyperlane.tscn +++ b/galaxy/map/galaxy_map_hyperlane.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://d3lphosly5y8b"] +[gd_scene load_steps=6 format=3 uid="uid://d3lphosly5y8b"] [ext_resource type="Script" path="res://galaxy/map/galaxy_map_hyperlane.gd" id="1_qtr5l"] +[ext_resource type="Material" uid="uid://wjykkjty1dt5" path="res://galaxy/map/galaxy_map_current_mat.tres" id="2_xrjew"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_futeo"] emission = Color(1, 1, 1, 1) @@ -20,6 +21,7 @@ radius = 0.1 [node name="Hyperlane" type="StaticBody3D" node_paths=PackedStringArray("mesh", "collision_shape", "debugging_label")] script = ExtResource("1_qtr5l") mesh = NodePath("MeshInstance3D") +selected_material = ExtResource("2_xrjew") collision_shape = NodePath("CollisionShape3D") debugging_label = NodePath("DebuggingLabel") node_radius = 0.1 diff --git a/screens/game/game.tscn b/screens/game/game.tscn index d5730ce4..d4d4affc 100644 --- a/screens/game/game.tscn +++ b/screens/game/game.tscn @@ -102,7 +102,7 @@ script = ExtResource("11_ag0i7") max_volume = 10.0 commodities = {} -[sub_resource type="Resource" id="Resource_kn2lj"] +[sub_resource type="Resource" id="Resource_0g6jc"] resource_local_to_scene = true script = ExtResource("13_q2g24") max_fuel = 6.0 @@ -183,7 +183,7 @@ hull = SubResource("Resource_ffax2") shield = SubResource("Resource_75c8j") battery = SubResource("Resource_xpwk4") cargo_hold = SubResource("Resource_bsv1l") -hyperdrive = SubResource("Resource_kn2lj") +hyperdrive = SubResource("Resource_0g6jc") [node name="CombatObject" parent="HyperspaceSceneSwitcher/Sol/PlayerCorvette" index="3" node_paths=PackedStringArray("targeted_sound")] targeted_sound = NodePath("../Player/TargetedSound") From ae95806d5bf4e7959a6c40192986c806bd4998c5 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 23 Aug 2024 21:31:33 +0100 Subject: [PATCH 5/8] Better selection state --- galaxy/map/galaxy_map.gd | 7 +++++-- galaxy/map/galaxy_map_system.gd | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/galaxy/map/galaxy_map.gd b/galaxy/map/galaxy_map.gd index 4ebe7b28..6e660dd5 100644 --- a/galaxy/map/galaxy_map.gd +++ b/galaxy/map/galaxy_map.gd @@ -83,11 +83,14 @@ func _on_jump_path_changed(_hyperdrive_system: HyperdriveSystem) -> void: self._update_selection_state() func _update_selection_state() -> void: + var current_system := self.hyperdrive_system.current_system() + var jump_path := self.hyperdrive_system.get_jump_path() var jump_names := jump_path.map(func(system: StarSystem) -> StringName: return system.name) for system_name: String in self._system_nodes: var node: GalaxyMapSystem = self._system_nodes[system_name] - node.selected = system_name in jump_names + node.current = system_name in jump_names or system_name == current_system.name + node.selected = system_name == jump_names[-1] if jump_path else false for hyperlane_name: String in self._hyperlane_nodes: var node: GalaxyMapHyperlane = self._hyperlane_nodes[hyperlane_name] @@ -103,7 +106,7 @@ func _update_selection_state() -> void: presented_system = jump_path[-1] self.current_or_destination_heading.text = "Destination system" else: - presented_system = self.hyperdrive_system.current_system() + presented_system = current_system self.current_or_destination_heading.text = "Current system" self.system_name_label.text = presented_system.name diff --git a/galaxy/map/galaxy_map_system.gd b/galaxy/map/galaxy_map_system.gd index 86b2b05b..bf6334de 100644 --- a/galaxy/map/galaxy_map_system.gd +++ b/galaxy/map/galaxy_map_system.gd @@ -12,7 +12,7 @@ class_name GalaxyMapSystem ## When [member current] is true, this material overrides the [member mesh]'s material. @export var current_node_material: Material -## Whether the system represented by this node is the player's current system. +## Whether the system represented by this node is the player's current system or part of the current hyperspace path. @export var current: bool: set(value): current = value @@ -21,7 +21,7 @@ class_name GalaxyMapSystem ## When [member selected] is true, this sprite is shown. @export var selected_sprite: Sprite3D -## Whether this system has been selected by the player in the galaxy map. +## Whether this system is currently selected by the player in the galaxy map. @export var selected: bool: set(value): selected = value From f6e38530bde0b7ec3a96c23f513c0935dd0cd2a7 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 23 Aug 2024 21:35:27 +0100 Subject: [PATCH 6/8] Don't create lanes both directions --- galaxy/map/galaxy_map.gd | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/galaxy/map/galaxy_map.gd b/galaxy/map/galaxy_map.gd index 6e660dd5..5c747bfe 100644 --- a/galaxy/map/galaxy_map.gd +++ b/galaxy/map/galaxy_map.gd @@ -56,6 +56,11 @@ func _ready() -> void: system_node.transform.origin = system.position for connection in system.connections: + var reverse_name := "%s > %s" % [connection, system.name] + if reverse_name in self._hyperlane_nodes: + # Only create one lane even if it's bidirectional + continue + var connected_system := self.galaxy.get_system(connection) var hyperlane: GalaxyMapHyperlane = self.galaxy_map_hyperlane.instantiate() # hyperlane.clicked.connect(func(node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system, node)) @@ -100,8 +105,14 @@ func _update_selection_state() -> void: if jump_path: for i in range(0, jump_path.size()): var last_name := jump_path[i - 1].name if i > 0 else self.hyperdrive_system.current_system().name - var hyperlane_name := "%s > %s" % [last_name, jump_path[i].name] - self._hyperlane_nodes[hyperlane_name].selected = true + + var forward_name := "%s > %s" % [last_name, jump_path[i].name] + if forward_name in self._hyperlane_nodes: + self._hyperlane_nodes[forward_name].selected = true + + var backward_name := "%s > %s" % [jump_path[i].name, last_name] + if backward_name in self._hyperlane_nodes: + self._hyperlane_nodes[backward_name].selected = true presented_system = jump_path[-1] self.current_or_destination_heading.text = "Destination system" From 67dc4531d12d9a10484ae8f6af733fce40824a0d Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 23 Aug 2024 21:37:09 +0100 Subject: [PATCH 7/8] Reduce near clipping plane in galaxy map --- galaxy/map/galaxy_map_3d.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy/map/galaxy_map_3d.tscn b/galaxy/map/galaxy_map_3d.tscn index e90e5e94..649904db 100644 --- a/galaxy/map/galaxy_map_3d.tscn +++ b/galaxy/map/galaxy_map_3d.tscn @@ -31,7 +31,7 @@ sky_mode = 1 [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(1, -6.97574e-16, -1.5246e-23, -1.5246e-23, -4.37114e-08, 1, -6.97574e-16, -1, -4.37114e-08, 2.08165e-12, 5, 2.08165e-12) current = true -near = 1.0 +near = 0.001 far = 50.0 script = ExtResource("3_h6pmd") From cbe9a495c08c116856e292d8f5056899057b1f23 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 23 Aug 2024 21:42:18 +0100 Subject: [PATCH 8/8] Make lanes clickable to update path --- galaxy/map/galaxy_map.gd | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/galaxy/map/galaxy_map.gd b/galaxy/map/galaxy_map.gd index 5c747bfe..3f832c2e 100644 --- a/galaxy/map/galaxy_map.gd +++ b/galaxy/map/galaxy_map.gd @@ -47,7 +47,7 @@ func _ready() -> void: for system in galaxy.systems: var system_node: GalaxyMapSystem = self.galaxy_map_system.instantiate() - system_node.clicked.connect(func(node: GalaxyMapSystem) -> void: self._on_system_clicked(system, node)) + system_node.clicked.connect(func(node: GalaxyMapSystem) -> void: self._on_system_clicked(system)) system_node.name = system.name system_node.current = (system == current_system) self._system_nodes[system.name] = system_node @@ -63,7 +63,7 @@ func _ready() -> void: var connected_system := self.galaxy.get_system(connection) var hyperlane: GalaxyMapHyperlane = self.galaxy_map_hyperlane.instantiate() - # hyperlane.clicked.connect(func(node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system, node)) + hyperlane.clicked.connect(func(_node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system)) hyperlane.name = "%s > %s" % [system.name, connection] hyperlane.starting_position = system.position hyperlane.ending_position = connected_system.position @@ -182,7 +182,7 @@ func _input(event: InputEvent) -> void: func _on_window_close_requested() -> void: self.queue_free() -func _on_system_clicked(star_system: StarSystem, _system_node: GalaxyMapSystem) -> void: +func _on_system_clicked(star_system: StarSystem) -> void: if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: return @@ -195,6 +195,17 @@ func _on_system_clicked(star_system: StarSystem, _system_node: GalaxyMapSystem) else: self._replace_single_path(star_system) +func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem) -> void: + if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: + return + + var current_system := self.hyperdrive_system.current_system() + var jump_path := self.hyperdrive_system.get_jump_path() + if from_system == current_system or from_system in jump_path: + self._on_system_clicked(to_system) + elif to_system == current_system or to_system in jump_path: + self._on_system_clicked(from_system) + func _update_multi_path(star_system: StarSystem) -> void: var current_path := self.hyperdrive_system.get_jump_path() if not current_path: @@ -217,21 +228,3 @@ func _replace_single_path(star_system: StarSystem) -> void: return self.hyperdrive_system.set_jump_path([star_system]) - -# func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void: -# if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping: -# return - -# var current_system := self.hyperdrive_system.current_system() -# var connection: StarSystem -# if from_system == current_system: -# connection = to_system -# elif to_system == current_system: -# connection = from_system -# else: -# return - -# if Input.is_key_pressed(KEY_SHIFT): -# self.hyperdrive_system.add_to_jump_path(connection) -# else: -# self.hyperdrive_system.set_jump_path([connection])