From 608809e0e4e84970e84a75a440b7cd7100c05106 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 28 Apr 2018 15:34:39 -0400 Subject: [PATCH] [Hero 4] Fix destroy not networking --- scripts/heroes/1_wall.gd | 4 ++-- scripts/heroes/5_portal.gd | 4 ++-- scripts/placeable.gd | 9 +++------ scripts/placement.gd | 17 +++++++++-------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/heroes/1_wall.gd b/scripts/heroes/1_wall.gd index 9c87f84..f359e33 100644 --- a/scripts/heroes/1_wall.gd +++ b/scripts/heroes/1_wall.gd @@ -7,7 +7,7 @@ func _process(delta): if being_touched > 0: maker_node.switch_charge += touch_charge * delta -func init(maker, index): +func init(maker): for player in get_node("/root/Level/Players").get_children(): player.connect("body_entered", self, "count_bodies", [player, 1]) @@ -27,7 +27,7 @@ func init(maker, index): mat.albedo_color = color get_node("MeshInstance").set_surface_material(0, mat) - .init(maker, index) + .init(maker) func count_bodies(with, player, delta): if with == self: diff --git a/scripts/heroes/5_portal.gd b/scripts/heroes/5_portal.gd index 239e6ea..79e9d94 100644 --- a/scripts/heroes/5_portal.gd +++ b/scripts/heroes/5_portal.gd @@ -23,7 +23,7 @@ func _exit_tree(): maker_node.placement.placed.remove(index - 1) other.queue_free() -func init(maker, index): +func init(maker): # If index is odd, we're the second (1, 3...), if even, first (0, 4...) var second = index % 2 != 0 @@ -37,7 +37,7 @@ func init(maker, index): mat.albedo_color = color get_node("MeshInstance").set_surface_material(0, mat) - .init(maker, index) + .init(maker) func place(): .place() diff --git a/scripts/placeable.gd b/scripts/placeable.gd index 13853d0..2fe4971 100644 --- a/scripts/placeable.gd +++ b/scripts/placeable.gd @@ -3,14 +3,12 @@ extends StaticBody var maker_node var material var destroy_cost = 20 -var index func _ready(): get_node("CollisionShape").disabled = true -func init(maker, index): +func init(maker): maker_node = maker - self.index = index material = get_node("MeshInstance").get_surface_material(0) if not material: @@ -24,9 +22,8 @@ func place(): get_node("CollisionShape").disabled = false material.flags_transparent = false -func destroy(): - maker_node.placement.remove_placed(index) - return destroy_cost +sync func destroy(): + maker_node.placement.remove_placed(get_name()) func make_last(): material.flags_transparent = true diff --git a/scripts/placement.gd b/scripts/placement.gd index ca4a9e8..e0c79fc 100644 --- a/scripts/placement.gd +++ b/scripts/placement.gd @@ -31,12 +31,12 @@ master func request_placed(): for node in placed: rpc_id(get_tree().get_rpc_sender_id(), "slave_place", node.transform) -func place_input(radius=-1, require_ghost=false): +func place_input(radius=-1, can_build=true, require_ghost=false): # We allow you to just click to place, without needing to press E var confirm = Input.is_action_just_pressed(confirm_action) - if Input.is_action_just_pressed(start_action) or (confirm and not is_placing and not require_ghost): + if can_build and Input.is_action_just_pressed(start_action) or (confirm and not is_placing and not require_ghost): # Press button twice to cancel if is_placing: # We changed our mind, delete the placing wall @@ -50,7 +50,7 @@ func place_input(radius=-1, require_ghost=false): if Input.is_action_just_pressed(delete_action): var pick = player.pick_from(placed) if pick != -1: - rpc("remove_placed", pick) + rpc("remove_placed", placed[pick].get_name()) if is_placing: position_placement(placing_node) @@ -62,7 +62,7 @@ func place_input(radius=-1, require_ghost=false): else: placing_node.within_range() - if (confirm and not require_ghost) or (confirm and is_placing): + if can_build and (confirm and not require_ghost) or (confirm and is_placing): # Order matters here: confirm_placement resets placing_node so we have to do anything with it first rpc("slave_place", placing_node.transform) confirm_placement(placing_node) @@ -125,13 +125,14 @@ slave func slave_place(tf): var node = create() confirm_placement(node, tf) -sync func remove_placed(index): - placed[index].queue_free() - placed.remove(index) +sync func remove_placed(name): + var what = get_node("/root/Level").get_node(name) + placed.erase(what) + what.queue_free() func create(): var node = scene.instance() player.get_node("/root/Level").add_child(node) - node.init(player, placed.size()) + node.init(player) return node