From e82990eeafdf0be5d42d8aaa9b7fb6091e0d8435 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 13 Oct 2024 11:14:43 +0200 Subject: next commit --- Game/Client.gd | 6 ++++++ Game/Network.gd | 4 ++-- Game/Selection/selection_rectangle.gd | 2 +- Game/States/Build/BuilderElement.gd | 5 ++--- Game/States/Build/build_grid.gd | 21 +++++++++++++++------ 5 files changed, 26 insertions(+), 12 deletions(-) (limited to 'Game') diff --git a/Game/Client.gd b/Game/Client.gd index db33a26..60efbb8 100644 --- a/Game/Client.gd +++ b/Game/Client.gd @@ -24,6 +24,9 @@ func initialize_stage(stage: Stage): func place_tower(tower: Tower): + if not current_stage.can_place_tower(): + return + var network_id = multiplayer.get_unique_id() tower.owner_id = network_id tower.name = "Tower@" + str(network_id) + "@" + str(Time.get_ticks_usec()) @@ -59,6 +62,9 @@ func update_tower(path: NodePath, data: Tower.NetworkData): func spawn_unit(unit: Unit, spawn: Spawn, overwrite_target: PathNode = null): + if not current_stage.can_spawn_unit(): + return + var network_id = multiplayer.get_unique_id() unit.owner_id = network_id unit.name = "Unit@" + str(network_id) + "@" + str(Time.get_ticks_usec()) diff --git a/Game/Network.gd b/Game/Network.gd index 558c8fa..5a435b7 100644 --- a/Game/Network.gd +++ b/Game/Network.gd @@ -74,8 +74,8 @@ func get_player(id: int) -> Player: func get_players() -> Array[Node]: return %Players.get_children() -func get_ordered_player_ids() -> Array: - var keys = %Players.get_children().map(func(item: Player): +func get_ordered_player_ids(players = get_players()) -> Array: + var keys = players.map(func(item: Player): return item.id ) keys.sort_custom(func(a: int, b: int): diff --git a/Game/Selection/selection_rectangle.gd b/Game/Selection/selection_rectangle.gd index 5e7d1c1..944372d 100644 --- a/Game/Selection/selection_rectangle.gd +++ b/Game/Selection/selection_rectangle.gd @@ -16,7 +16,7 @@ var is_active: bool : get(): return abs(size) > Vector2(1, 1) and Client.state is StateDefault -@onready var camera: Camera2D = get_tree().get_first_node_in_group("camera") +@onready var camera: Camera = get_viewport().get_camera_2d() func _process(_delta: float) -> void: diff --git a/Game/States/Build/BuilderElement.gd b/Game/States/Build/BuilderElement.gd index eb5ae12..38417ff 100644 --- a/Game/States/Build/BuilderElement.gd +++ b/Game/States/Build/BuilderElement.gd @@ -88,10 +88,9 @@ func can_build(): if area.get_overlapping_bodies().size() > 0: return false - - if Client.current_stage.has_method("can_build"): - return Client.current_stage.can_build() + #if Client.current_stage.has_method("can_build"): + #return Client.current_stage.can_build() return true diff --git a/Game/States/Build/build_grid.gd b/Game/States/Build/build_grid.gd index 766c79b..67c962e 100644 --- a/Game/States/Build/build_grid.gd +++ b/Game/States/Build/build_grid.gd @@ -1,21 +1,30 @@ extends Node2D +@onready var camera: Camera = get_viewport().get_camera_2d() + + +func _ready() -> void: + camera.zoomed.connect(func(_zoom): + queue_redraw() + ) + + func _draw(): var area = Client.current_stage.map.get_used_rect() var cell_size = Client.current_stage.map.tile_set.tile_size var offset = area.position for row in range(0, area.size.y + 1): draw_line( - Vector2(offset.x * cell_size.x, offset.y + row * cell_size.y), - Vector2(offset.x * cell_size.x + area.size.x * cell_size.x, offset.y + row * cell_size.y), + Vector2(offset.x * cell_size.x, offset.y * cell_size.y + row * cell_size.y), + Vector2(offset.x * cell_size.x + area.size.x * cell_size.x, offset.y * cell_size.y + row * cell_size.y), Color(1, 1, 1, 0.25), - 1.0 + 1.0 / camera.zoom.x ) for column in range(0, area.size.x + 1): draw_line( - Vector2(offset.x * cell_size.x + column * cell_size.x, offset.y), - Vector2(offset.x * cell_size.x + column * cell_size.x, offset.y + area.size.y * cell_size.y), + Vector2(offset.x * cell_size.x + column * cell_size.x, offset.y * cell_size.y), + Vector2(offset.x * cell_size.x + column * cell_size.x, offset.y * cell_size.y + area.size.y * cell_size.y), Color(1, 1, 1, 0.25), - 1.0 + 1.0 / camera.zoom.x ) -- cgit v1.2.3