From 647e2e1812c00e29337a61560644f7aa91d0eb0f Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 12 Oct 2024 13:59:11 +0200 Subject: next commit --- Units/Unit.gd | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'Units') diff --git a/Units/Unit.gd b/Units/Unit.gd index 06cf346..3ce9384 100644 --- a/Units/Unit.gd +++ b/Units/Unit.gd @@ -31,7 +31,7 @@ var is_hovered = false : is_hovered = value queue_redraw() -var target: Vector2 : +var target: Node2D: set(value): target = value reset_path() @@ -164,8 +164,8 @@ func _on_navigation_base_area_entered(area: Area2D): queue_free() if area.is_in_group("path"): var path_node: PathNode = area.get_parent() - if path_node.path_position == target: - target = path_node.next_node.path_position + if path_node == target: + target = path_node.next_node func walk_along_path(path: PackedVector2Array, index: int, delta: float): @@ -230,12 +230,12 @@ func reset_path(): # reached end of partial path if current_path.size() == 1 and current_path[0] == global_position: roaming_mode = true - current_path = PackedVector2Array([target + Vector2(16,16)]) + current_path = PackedVector2Array([target.path_position + Vector2(16,16)]) # iterating between one or more closest paths elif recent_closest_paths.count(current_path) >= 2: roaming_mode = true - current_path = PackedVector2Array([target + Vector2(16,16)]) + current_path = PackedVector2Array([target.path_position + Vector2(16,16)]) recent_closest_paths = [] else: recent_closest_paths = [] @@ -250,7 +250,7 @@ func reset_path(): func get_grid_path(partial = false): return Client.stage.path_grid.get_point_path( Client.stage.map.local_to_map(global_position), - Client.stage.map.local_to_map(target), + Client.stage.map.local_to_map(target.path_position), partial ) @@ -285,7 +285,7 @@ func _on_tree_exiting() -> void: class NetworkData extends Resource: var name: String var position: Vector2 - var target_position: Vector2 + var target_path: String var hp: int var speed: float var texture_path: String @@ -295,19 +295,24 @@ func to_network_data() -> NetworkData: data.name = name data.position = global_position - data.target_position = target + data.target_path = target.get_path() data.hp = hp data.speed = speed data.texture_path = get_node("Sprite2D").texture.resource_path return data + +#func update_with_network_data(data: NetworkData): + # TODO + + static func from_network_data(data: NetworkData) -> Unit: var unit: Unit = preload("res://Units/Unit.tscn").instantiate() unit.name = data.name unit.global_position = data.position - unit.target = data.target_position + unit.target = unit.get_tree().current_scene.get_node(data.target_path) unit.hp = data.hp unit.speed = data.speed unit.get_node("Sprite2D").texture = load(data.texture_path) -- cgit v1.2.3