summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-06 22:35:04 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-06 22:35:04 +0100
commit63d2a59042fb9d90a586ad85d8364de7c38aea8e (patch)
treef4c648b39313f10f44898d0216a9147dfb4ba491
parentf20b3a48a14f34def41d823fabb476981ef7055e (diff)
next commit
-rw-r--r--Game/Client.gd9
-rw-r--r--Game/Selection/SelectionManager.gd24
-rw-r--r--Game/Selection/SelectionManager.tscn6
-rw-r--r--Game/States/Build/StateBuild.gd21
-rw-r--r--Stages/Wintermaul/HUD.gd2
-rw-r--r--Stages/Wintermaul/hud_tower.gd33
-rw-r--r--Stages/Wintermaul/hud_tower.tscn1
-rw-r--r--Towers/Components/AttackComponent.gd29
-rw-r--r--Towers/Components/AttackComponent.tscn19
-rw-r--r--Towers/Components/BurnComponent.gd5
-rw-r--r--Towers/Components/BurnComponent.tscn12
-rw-r--r--Towers/Components/FrostComponent.gd5
-rw-r--r--Towers/Components/FrostComponent.tscn12
-rw-r--r--Towers/Components/RangeComponent.gd33
-rw-r--r--Towers/Components/RangeComponent.tscn22
-rw-r--r--Towers/Components/TowerComponent.gd27
-rw-r--r--Towers/Components/TowerComponent.tscn14
-rw-r--r--Towers/Tower.gd101
-rw-r--r--Towers/Tower.tscn24
19 files changed, 201 insertions, 198 deletions
diff --git a/Game/Client.gd b/Game/Client.gd
index 2c3bb69..7ca26ec 100644
--- a/Game/Client.gd
+++ b/Game/Client.gd
@@ -16,16 +16,17 @@ var state: State :
var current_stage: Stage
+var selection: SelectionManager
+
var player: Player:
get():
return Network.get_player(multiplayer.get_unique_id())
-func _ready():
- pass
-
-
func initialize_stage(stage: Stage):
+ selection = preload("res://Game/Selection/SelectionManager.tscn").instantiate()
+ add_child(selection)
+
current_stage = stage
diff --git a/Game/Selection/SelectionManager.gd b/Game/Selection/SelectionManager.gd
index c58dc69..49cb319 100644
--- a/Game/Selection/SelectionManager.gd
+++ b/Game/Selection/SelectionManager.gd
@@ -2,5 +2,29 @@ class_name SelectionManager
extends Node
+var selection_groups := {}
+
+signal selected_group_changed
+var selected_group := "":
+ set(value):
+ selected_group = value
+ selected_group_changed.emit()
+
+
func _ready() -> void:
pass
+
+
+func change_selection_group_id(towers: Array[Tower], previous_id: String, new_id: String) -> void:
+ if new_id not in selection_groups:
+ selection_groups[new_id] = []
+
+ selection_groups[new_id].append_array(towers)
+
+ for tower in towers:
+ selection_groups[previous_id].erase(tower)
+
+ if selection_groups[previous_id].is_empty():
+ selection_groups.erase(previous_id)
+ if previous_id == selected_group:
+ selected_group = new_id
diff --git a/Game/Selection/SelectionManager.tscn b/Game/Selection/SelectionManager.tscn
new file mode 100644
index 0000000..e89880f
--- /dev/null
+++ b/Game/Selection/SelectionManager.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://mgm4npqeybbr"]
+
+[ext_resource type="Script" path="res://Game/Selection/SelectionManager.gd" id="1_1w5l7"]
+
+[node name="SelectionManager" type="Node"]
+script = ExtResource("1_1w5l7")
diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd
index ea06671..0bd5efb 100644
--- a/Game/States/Build/StateBuild.gd
+++ b/Game/States/Build/StateBuild.gd
@@ -19,18 +19,19 @@ func _state_exit():
func _state_input(event: InputEvent):
if event.is_action_pressed("builder_tower_select"):
- if current_builder_element and current_builder_element.can_build():
+ if current_builder_element:
get_viewport().set_input_as_handled()
- var placed_tower = current_builder_element.element.instantiate() as Tower
-
- placed_tower.global_position = current_builder_element.global_position
-
- Client.place_tower(placed_tower)
-
- if not Input.is_action_pressed("builder_tower_place_keep"):
- current_builder_element.queue_free()
- current_builder_element = null
+ if current_builder_element.can_build():
+ var placed_tower = current_builder_element.element.instantiate() as Tower
+
+ placed_tower.global_position = current_builder_element.global_position
+
+ Client.place_tower(placed_tower)
+
+ if not Input.is_action_pressed("builder_tower_place_keep"):
+ current_builder_element.queue_free()
+ current_builder_element = null
if event.is_action_pressed("build_mode_start"):
get_viewport().set_input_as_handled()
diff --git a/Stages/Wintermaul/HUD.gd b/Stages/Wintermaul/HUD.gd
index be2dacb..1033c8e 100644
--- a/Stages/Wintermaul/HUD.gd
+++ b/Stages/Wintermaul/HUD.gd
@@ -104,6 +104,8 @@ func _ready():
)
tower.selection_group_id_changed.connect(func(previous_id: String):
+ #Client.selection.change_selection_group_id([tower], previous_id, tower.selection_group_id)
+
if not tower.selection_group_id in selection_groups:
selection_groups[tower.selection_group_id] = []
selection_groups[tower.selection_group_id].append(tower)
diff --git a/Stages/Wintermaul/hud_tower.gd b/Stages/Wintermaul/hud_tower.gd
index 24a7a8d..99d9e62 100644
--- a/Stages/Wintermaul/hud_tower.gd
+++ b/Stages/Wintermaul/hud_tower.gd
@@ -17,9 +17,12 @@ func set_current_tower(tower: Tower):
redraw_components()
current_tower.components_changed.connect(redraw_components)
- #%Data.text = "Range: %s - Power: %s - Speed: %s" % [
- #current_tower.attack_range, current_tower.attack_power, current_tower.attack_speed
- #]
+
+ %Data.text = "Range: %s - Power: %s - Speed: %s" % [
+ current_tower.components.get(TowerComponent.ComponentType.Range).range,
+ current_tower.components.get(TowerComponent.ComponentType.Attack).power,
+ current_tower.components.get(TowerComponent.ComponentType.Attack).speed,
+ ]
func redraw_components():
@@ -131,7 +134,7 @@ func _on_range_gui_input(event: InputEvent) -> void:
return
for tower: Tower in towers:
- tower.add_component(preload("res://Towers/Components/RangeComponent.gd").new())
+ tower.add_component(preload("res://Towers/Components/RangeComponent.tscn").instantiate())
Client.update_tower(tower.get_path(), tower.to_network_data())
@@ -156,7 +159,7 @@ func _on_attack_gui_input(event: InputEvent) -> void:
return
for tower: Tower in towers:
- tower.add_component(preload("res://Towers/Components/AttackComponent.gd").new())
+ tower.add_component(preload("res://Towers/Components/AttackComponent.tscn").instantiate())
Client.update_tower(tower.get_path(), tower.to_network_data())
@@ -181,7 +184,7 @@ func _on_frost_gui_input(event: InputEvent) -> void:
return
for tower: Tower in towers:
- tower.add_component(preload("res://Towers/Components/FrostComponent.gd").new())
+ tower.add_component(preload("res://Towers/Components/FrostComponent.tscn").instantiate())
Client.update_tower(tower.get_path(), tower.to_network_data())
@@ -206,7 +209,7 @@ func _on_burn_gui_input(event: InputEvent) -> void:
return
for tower: Tower in towers:
- tower.add_component(preload("res://Towers/Components/BurnComponent.gd").new())
+ tower.add_component(preload("res://Towers/Components/BurnComponent.tscn").instantiate())
Client.update_tower(tower.get_path(), tower.to_network_data())
@@ -223,7 +226,7 @@ func _on_range_level_up_pressed() -> void:
if not component:
return
- var cost = 25 * component.level * towers.size()
+ var cost = pow(5, component.level) * towers.size()
if Client.player.money < cost:
Client.current_stage.add_status_message("Not enough money to level up")
return
@@ -239,6 +242,12 @@ func _on_range_level_up_pressed() -> void:
Network.update_player.rpc(Client.player.id, {
"money": -cost,
})
+
+ %Data.text = "Range: %s - Power: %s - Speed: %s" % [
+ current_tower.components.get(TowerComponent.ComponentType.Range).range,
+ current_tower.components.get(TowerComponent.ComponentType.Attack).power,
+ current_tower.components.get(TowerComponent.ComponentType.Attack).speed,
+ ]
func _on_attack_level_up_pressed() -> void:
@@ -265,6 +274,12 @@ func _on_attack_level_up_pressed() -> void:
Network.update_player.rpc(Client.player.id, {
"money": -cost,
})
+
+ %Data.text = "Range: %s - Power: %s - Speed: %s" % [
+ current_tower.components.get(TowerComponent.ComponentType.Range).range,
+ current_tower.components.get(TowerComponent.ComponentType.Attack).power,
+ current_tower.components.get(TowerComponent.ComponentType.Attack).speed,
+ ]
func _on_frost_level_up_pressed() -> void:
@@ -349,7 +364,7 @@ func _on_range_level_up_mouse_entered() -> void:
return
var towers = get_selected_towers()
- var cost = 25 * component.level * towers.size()
+ var cost = pow(5, component.level) * towers.size()
$Components/Range/RangeLevelUp.tooltip_text = "Cost: " + str(cost)
func _on_attack_mouse_entered() -> void:
diff --git a/Stages/Wintermaul/hud_tower.tscn b/Stages/Wintermaul/hud_tower.tscn
index 4a23f10..e8c6487 100644
--- a/Stages/Wintermaul/hud_tower.tscn
+++ b/Stages/Wintermaul/hud_tower.tscn
@@ -14,7 +14,6 @@ script = ExtResource("1_aog4m")
[node name="Data" type="Label" parent="."]
unique_name_in_owner = true
-visible = false
layout_mode = 2
text = "Data"
diff --git a/Towers/Components/AttackComponent.gd b/Towers/Components/AttackComponent.gd
index c7660cf..0b09ac1 100644
--- a/Towers/Components/AttackComponent.gd
+++ b/Towers/Components/AttackComponent.gd
@@ -4,32 +4,33 @@ extends TowerComponent
var power := 1
-var speed_base := 1.0
+var speed_base := 2.0
var speed := 1
-var shoot_cooldown := Timer.new()
-var shoot_sound := AudioStreamPlayer2D.new()
+@onready var shoot_cooldown := $ShootCooldown
+@onready var shoot_sound := $ShootSound
-@export var range_component: RangeTowerComponent:
+var range_component: RangeTowerComponent:
get():
return current_tower.components[ComponentType.Range]
-func _init() -> void:
- type = ComponentType.Attack
- set_sprite(preload("res://Towers/Components/Assets/attack-component.png"))
-
+func _ready() -> void:
update_power()
- update_speed()
level_changed.connect(update_power)
+
+ update_speed()
level_changed.connect(update_speed)
func update_power():
- power = ceil(level / 2.0)
+ if level <= 2:
+ power = level
+ else:
+ power = 1 + max(1, level - ceil(level / 2.0))
func update_speed():
- speed = level - ceil(level / 2.0)
+ speed = max(1, ceil(level / 2.0))
shoot_cooldown.wait_time = speed_base / speed
func update_range():
@@ -39,12 +40,6 @@ func update_range():
func on_add(tower: Tower):
super.on_add(tower)
- shoot_cooldown.one_shot = true
- tower.add_child(shoot_cooldown)
-
- shoot_sound.stream = preload("res://Towers/Assets/shoot.ogg")
- tower.add_child(shoot_sound)
-
update_range()
range_component.range_changed.connect(update_range)
diff --git a/Towers/Components/AttackComponent.tscn b/Towers/Components/AttackComponent.tscn
new file mode 100644
index 0000000..2cad794
--- /dev/null
+++ b/Towers/Components/AttackComponent.tscn
@@ -0,0 +1,19 @@
+[gd_scene load_steps=5 format=3 uid="uid://4nd1npteqvh3"]
+
+[ext_resource type="PackedScene" uid="uid://cly4agfoqhq2q" path="res://Towers/Components/TowerComponent.tscn" id="1_j2cqy"]
+[ext_resource type="Script" path="res://Towers/Components/AttackComponent.gd" id="2_dbyck"]
+[ext_resource type="Texture2D" uid="uid://gbknvb38euuq" path="res://Towers/Components/Assets/attack-component.png" id="2_vr0du"]
+[ext_resource type="AudioStream" uid="uid://cpkwvp5llf7x6" path="res://Towers/Assets/shoot.ogg" id="4_ytht8"]
+
+[node name="AttackTowerComponent" instance=ExtResource("1_j2cqy")]
+script = ExtResource("2_dbyck")
+type = 1
+
+[node name="Sprite" parent="." index="0"]
+texture = ExtResource("2_vr0du")
+
+[node name="ShootCooldown" type="Timer" parent="." index="1"]
+one_shot = true
+
+[node name="ShootSound" type="AudioStreamPlayer2D" parent="." index="2"]
+stream = ExtResource("4_ytht8")
diff --git a/Towers/Components/BurnComponent.gd b/Towers/Components/BurnComponent.gd
index d708d4f..ddac88b 100644
--- a/Towers/Components/BurnComponent.gd
+++ b/Towers/Components/BurnComponent.gd
@@ -1,11 +1,6 @@
extends TowerComponent
-func _init() -> void:
- type = ComponentType.Burn
- set_sprite(preload("res://Towers/Components/Assets/burn-component.png"))
-
-
func on_shoot(target: Unit):
var effect = preload("res://Effects/BurnEffect.tscn").instantiate()
effect.level = level
diff --git a/Towers/Components/BurnComponent.tscn b/Towers/Components/BurnComponent.tscn
new file mode 100644
index 0000000..285cfa0
--- /dev/null
+++ b/Towers/Components/BurnComponent.tscn
@@ -0,0 +1,12 @@
+[gd_scene load_steps=4 format=3 uid="uid://c0xtty8n0lwpr"]
+
+[ext_resource type="PackedScene" uid="uid://cly4agfoqhq2q" path="res://Towers/Components/TowerComponent.tscn" id="1_56lm4"]
+[ext_resource type="Script" path="res://Towers/Components/BurnComponent.gd" id="2_nevgj"]
+[ext_resource type="Texture2D" uid="uid://2djpswd6sgng" path="res://Towers/Components/Assets/burn-component.png" id="3_o6seh"]
+
+[node name="TowerComponent" instance=ExtResource("1_56lm4")]
+script = ExtResource("2_nevgj")
+type = 4
+
+[node name="Sprite" parent="." index="0"]
+texture = ExtResource("3_o6seh")
diff --git a/Towers/Components/FrostComponent.gd b/Towers/Components/FrostComponent.gd
index 2443b70..4d2b04c 100644
--- a/Towers/Components/FrostComponent.gd
+++ b/Towers/Components/FrostComponent.gd
@@ -1,11 +1,6 @@
extends TowerComponent
-func _init() -> void:
- type = ComponentType.Frost
- set_sprite(preload("res://Towers/Components/Assets/frost-component.png"))
-
-
func on_shoot(target: Unit):
var effect = preload("res://Effects/SlowEffect.tscn").instantiate()
effect.level = level
diff --git a/Towers/Components/FrostComponent.tscn b/Towers/Components/FrostComponent.tscn
new file mode 100644
index 0000000..976d3e8
--- /dev/null
+++ b/Towers/Components/FrostComponent.tscn
@@ -0,0 +1,12 @@
+[gd_scene load_steps=4 format=3 uid="uid://b1opnngyr3de4"]
+
+[ext_resource type="PackedScene" uid="uid://cly4agfoqhq2q" path="res://Towers/Components/TowerComponent.tscn" id="1_8hes5"]
+[ext_resource type="Script" path="res://Towers/Components/FrostComponent.gd" id="2_bsb0f"]
+[ext_resource type="Texture2D" uid="uid://ba3dmlce1wv2p" path="res://Towers/Components/Assets/frost-component.png" id="3_qwp1n"]
+
+[node name="FrostTowerComponent" instance=ExtResource("1_8hes5")]
+script = ExtResource("2_bsb0f")
+type = 3
+
+[node name="Sprite" parent="." index="0"]
+texture = ExtResource("3_qwp1n")
diff --git a/Towers/Components/RangeComponent.gd b/Towers/Components/RangeComponent.gd
index a2f7ae7..74a6eeb 100644
--- a/Towers/Components/RangeComponent.gd
+++ b/Towers/Components/RangeComponent.gd
@@ -9,17 +9,14 @@ var range := 0:
range = value
range_changed.emit()
-var area := Area2D.new()
-var collision_shape := CollisionShape2D.new()
-var shape := CircleShape2D.new()
+@onready var area: Area2D = $Range
+@onready var collision_shape := $Range/CollisionShape2D
+@onready var shape: CircleShape2D = collision_shape.shape
var units_in_range: Array[Unit]
-func _init() -> void:
- type = ComponentType.Range
- set_sprite(preload("res://Towers/Components/Assets/range-component.png"))
-
+func _ready() -> void:
update_range()
level_changed.connect(update_range)
@@ -34,19 +31,11 @@ func update_range():
func on_add(tower: Tower):
super.on_add(tower)
- area.set_collision_layer_value(1, false)
- area.set_collision_mask_value(1, true)
-
- area.body_entered.connect(func(body: Node2D):
- units_in_range.append(body)
- )
- area.body_exited.connect(func(body: Node2D):
- units_in_range.erase(body)
- )
-
area.position = tower.get_node("CenterAnchor").position
-
- collision_shape.shape = shape
- area.add_child(collision_shape)
-
- tower.add_child(area)
+
+
+func _on_range_body_entered(body: Node2D) -> void:
+ units_in_range.append(body)
+
+func _on_range_body_exited(body: Node2D) -> void:
+ units_in_range.erase(body)
diff --git a/Towers/Components/RangeComponent.tscn b/Towers/Components/RangeComponent.tscn
new file mode 100644
index 0000000..1047529
--- /dev/null
+++ b/Towers/Components/RangeComponent.tscn
@@ -0,0 +1,22 @@
+[gd_scene load_steps=5 format=3 uid="uid://b0bdw5n6p5k8u"]
+
+[ext_resource type="PackedScene" uid="uid://cly4agfoqhq2q" path="res://Towers/Components/TowerComponent.tscn" id="1_738xf"]
+[ext_resource type="Script" path="res://Towers/Components/RangeComponent.gd" id="2_4fk2a"]
+[ext_resource type="Texture2D" uid="uid://dx07y4scyi5a1" path="res://Towers/Components/Assets/range-component.png" id="3_7nqma"]
+
+[sub_resource type="CircleShape2D" id="CircleShape2D_q388v"]
+
+[node name="RangeTowerComponent" instance=ExtResource("1_738xf")]
+script = ExtResource("2_4fk2a")
+
+[node name="Sprite" parent="." index="0"]
+texture = ExtResource("3_7nqma")
+
+[node name="Range" type="Area2D" parent="." index="1"]
+collision_layer = 0
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Range" index="0"]
+shape = SubResource("CircleShape2D_q388v")
+
+[connection signal="body_entered" from="Range" to="." method="_on_range_body_entered"]
+[connection signal="body_exited" from="Range" to="." method="_on_range_body_exited"]
diff --git a/Towers/Components/TowerComponent.gd b/Towers/Components/TowerComponent.gd
index 7ca766a..30b1c44 100644
--- a/Towers/Components/TowerComponent.gd
+++ b/Towers/Components/TowerComponent.gd
@@ -1,8 +1,10 @@
class_name TowerComponent
-extends Node
+extends Node2D
-var current_tower: Tower
+var current_tower: Tower:
+ get():
+ return get_parent()
enum ComponentType {
Range,
@@ -13,8 +15,15 @@ enum ComponentType {
Poison,
}
-var type: ComponentType
-var sprite: TextureRect = TextureRect.new()
+@export var type: ComponentType
+var sprite: TextureRect:
+ get():
+ @warning_ignore("shadowed_variable")
+ var sprite := $Sprite.duplicate()
+ sprite.name = get_type_name()
+
+ return sprite
+
var id: String:
get():
@@ -28,12 +37,8 @@ var level: int = 1:
func set_sprite(texture: Texture2D):
+ sprite = get_node("Sprite")
sprite.texture = texture
-
- sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
- #sprite.centered = false
- sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
- #sprite.scale = Vector2(2, 2)
sprite.name = get_type_name()
@@ -57,8 +62,8 @@ func to_network_data() -> NetworkData:
return data
-func update_with_network_data(_data: NetworkData):
- pass
+func update_with_network_data(data: NetworkData):
+ level = data.level
static func from_network_data(data: NetworkData) -> TowerComponent:
var component = preload("res://Towers/Components/TowerComponent.gd").new()
diff --git a/Towers/Components/TowerComponent.tscn b/Towers/Components/TowerComponent.tscn
new file mode 100644
index 0000000..6b1d7b2
--- /dev/null
+++ b/Towers/Components/TowerComponent.tscn
@@ -0,0 +1,14 @@
+[gd_scene load_steps=2 format=3 uid="uid://cly4agfoqhq2q"]
+
+[ext_resource type="Script" path="res://Towers/Components/TowerComponent.gd" id="1_jb46t"]
+
+[node name="TowerComponent" type="Node2D"]
+visible = false
+script = ExtResource("1_jb46t")
+
+[node name="Sprite" type="TextureRect" parent="."]
+texture_filter = 1
+offset_right = 40.0
+offset_bottom = 40.0
+stretch_mode = 5
+metadata/_edit_use_anchors_ = true
diff --git a/Towers/Tower.gd b/Towers/Tower.gd
index 1d856f3..34e12ae 100644
--- a/Towers/Tower.gd
+++ b/Towers/Tower.gd
@@ -40,10 +40,6 @@ var is_highlighted := false:
is_highlighted = value
queue_redraw()
-#var mobs_in_range: Array = []
-
-#var selection_area: Area2D
-
signal selection_group_id_changed(previous_id: String)
@onready var selection_group_id := get_group_id():
set(value):
@@ -54,20 +50,6 @@ signal selection_group_id_changed(previous_id: String)
# rpc owner id
@export var owner_id = 1
-#@export var attack_range: int = 32:
- #set(value):
- #attack_range = value
- #$Range/CollisionShape2D.shape.radius = attack_range
- #$SoundShoot.max_distance = attack_range * Client.current_stage.map.tile_set.tile_size.x
-
-#@export var attack_power: int = 1
-
-#var attack_speed_base: float = 2.0
-#@export var attack_speed: int = 1:
- #set(value):
- #attack_speed = value
- #%ShootCooldown.wait_time = attack_speed_base / attack_speed
-
signal components_changed
@export var components: Dictionary
@@ -79,7 +61,7 @@ func _init():
func _ready():
$AnimatedSprite2D.play()
- for component in [RangeTowerComponent.new(), AttackTowerComponent.new()]:
+ for component in [preload("res://Towers/Components/RangeComponent.tscn").instantiate(), preload("res://Towers/Components/AttackComponent.tscn").instantiate()]:
add_component(component)
redraw_components()
@@ -120,17 +102,6 @@ func _process(delta: float) -> void:
for component in components.values():
if component.has_method("process"):
component.process(delta)
-
- #if $ShootCooldown.is_stopped() and not mobs_in_range.is_empty():
- #shoot()
- #$ShootCooldown.start()
-
- #if selection_area and is_instance_valid(selection_area):
- #var bodies = selection_area.get_overlapping_bodies()
- #if bodies.size() > 0:
- #selection_area.queue_free()
- #for body in bodies:
- #Client.select_tower(body)
func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
@@ -146,13 +117,6 @@ func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
Client.remove_tower(self)
-#func _on_range_body_entered(body: Node2D) -> void:
- #mobs_in_range.append(body)
-#
-#func _on_range_body_exited(body: Node2D) -> void:
- #mobs_in_range.erase(body)
-
-
func _on_selectable_area_hover_enter() -> void:
is_hovered = true
@@ -176,24 +140,15 @@ func _on_selectable_area_select_primary(event: InputEvent) -> void:
func add_component(component: TowerComponent):
components[component.type] = component
+ add_child(component)
component.on_add(self)
- var sprite = component.sprite
+ var sprite = component.sprite.duplicate()
%ComponentsAnchor.add_child(sprite)
redraw_components()
components_changed.emit()
-func remove_component(component: TowerComponent):
- components.erase(component.type)
- %ComponentsAnchor.remove_child(%ComponentsAnchor.get_node(NodePath(component.id)))
- #for component in components:
- #if component.name == component_name:
- #components.erase(component)
- #$ComponentsAnchor.remove_child($ComponentsAnchor.get_node(NodePath(component.name)))
- #break
- redraw_components()
- components_changed.emit()
func redraw_components():
var keys = components.keys()
@@ -204,30 +159,6 @@ func redraw_components():
sprite.position.y = (idx + 1) * -16
-#func is_melee_range():
- #return attack_range <= (Client.current_stage.map.tile_set.tile_size.x * 2)
-
-
-#func shoot():
- #var target = mobs_in_range[0] as Unit
- #
- #for component in components:
- #if component.has_method("on_shoot"):
- #component.on_shoot(target)
- #
- #shoot_fx.rpc()
- #
- #if is_melee_range():
- #target.set_hp(target.hp - 1)
- #else: # TODO
- #target.set_hp(target.hp - 1)
-#
-#@rpc("authority", "call_local")
-#func shoot_fx():
- #$SoundShoot.play()
-
-
-
func get_region():
var collision_shape := $CollisionShape2D
var shape = $CollisionShape2D.shape as RectangleShape2D
@@ -241,10 +172,6 @@ func get_region():
func get_group_id() -> String:
var string := ""
- #string += str(attack_range)
- #string += str(attack_power)
- #string += str(attack_speed)
-
for component: TowerComponent in components.values():
string += component.id
string += str(component.level)
@@ -277,11 +204,11 @@ func to_network_data() -> NetworkData:
data.owner_id = owner_id
data.position = global_position
- #data.attack_range = attack_range
- #data.attack_power = attack_power
- #data.attack_speed = attack_speed
data.components = components.values().map(func(item: TowerComponent):
- return inst_to_dict(item.to_network_data())
+ var component_data = inst_to_dict(item.to_network_data())
+ component_data["path"] = item.get_path()
+
+ return component_data
)
data.sprite_modulate = $AnimatedSprite2D.modulate
@@ -292,14 +219,10 @@ func to_network_data() -> NetworkData:
return data
func update_with_network_data(data: NetworkData):
- for component in components.duplicate():
- remove_component(component.id)
-
for component_data in data.components:
- var component_network_data: TowerComponent.NetworkData = dict_to_inst(component_data)
- var component = load("res://Towers/Components/" + component_network_data.name + "Component.gd").new()
- component.level = component_network_data.level
- add_component(component)
+ var component = get_node(component_data.path) as TowerComponent
+ component.update_with_network_data(dict_to_inst(component_data))
+ redraw_components()
static func from_network_data(data: NetworkData) -> Tower:
var tower: Tower = preload("res://Towers/Tower.tscn").instantiate()
@@ -308,10 +231,6 @@ static func from_network_data(data: NetworkData) -> Tower:
tower.owner_id = data.owner_id
tower.global_position = data.position
- #tower.attack_range = data.attack_range
- #tower.attack_power = data.attack_power
- #tower.attack_speed = data.attack_speed
-
tower.get_node("AnimatedSprite2D").modulate = data.sprite_modulate
tower.get_node("%ComponentsAnchor").modulate = data.components_anchor_modulate
diff --git a/Towers/Tower.tscn b/Towers/Tower.tscn
index 0bd4579..839917c 100644
--- a/Towers/Tower.tscn
+++ b/Towers/Tower.tscn
@@ -1,10 +1,9 @@
-[gd_scene load_steps=16 format=3 uid="uid://by1x56w21o165"]
+[gd_scene load_steps=14 format=3 uid="uid://by1x56w21o165"]
[ext_resource type="Script" path="res://Towers/Tower.gd" id="1_axo1d"]
[ext_resource type="Texture2D" uid="uid://b1b18rd0tqbar" path="res://core_outdoor.png" id="1_mrep8"]
[ext_resource type="PackedScene" uid="uid://cqktpc8c7ecn3" path="res://Game/Selection/SelectableArea.tscn" id="3_57d5u"]
[ext_resource type="Texture2D" uid="uid://dujcs2ls3u6tj" path="res://Towers/Assets/spritesheet.png" id="3_brkps"]
-[ext_resource type="AudioStream" uid="uid://cpkwvp5llf7x6" path="res://Towers/Assets/shoot.ogg" id="5_i05ow"]
[sub_resource type="AtlasTexture" id="AtlasTexture_1ubf7"]
atlas = ExtResource("3_brkps")
@@ -59,8 +58,6 @@ animations = [{
[sub_resource type="RectangleShape2D" id="RectangleShape2D_atm5x"]
size = Vector2(31, 31)
-[sub_resource type="CircleShape2D" id="CircleShape2D_qa8kt"]
-
[sub_resource type="RectangleShape2D" id="RectangleShape2D_312i7"]
size = Vector2(32, 32)
@@ -91,19 +88,6 @@ centered = false
position = Vector2(16, 16)
shape = SubResource("RectangleShape2D_atm5x")
-[node name="Range" type="Area2D" parent="."]
-unique_name_in_owner = true
-visible = false
-collision_layer = 0
-
-[node name="CollisionShape2D" type="CollisionShape2D" parent="Range"]
-position = Vector2(16, 16)
-shape = SubResource("CircleShape2D_qa8kt")
-
-[node name="ShootCooldown" type="Timer" parent="."]
-unique_name_in_owner = true
-one_shot = true
-
[node name="SelectableArea" parent="." instance=ExtResource("3_57d5u")]
[node name="CollisionShape2D" type="CollisionShape2D" parent="SelectableArea"]
@@ -125,14 +109,8 @@ position = Vector2(16, 29)
[node name="CenterAnchor" type="Marker2D" parent="."]
position = Vector2(16, 16)
-[node name="SoundShoot" type="AudioStreamPlayer2D" parent="."]
-visible = false
-stream = ExtResource("5_i05ow")
-
[connection signal="input_event" from="." to="." method="_on_input_event"]
[connection signal="tree_exiting" from="." to="." method="_on_tree_exiting"]
-[connection signal="body_entered" from="Range" to="." method="_on_range_body_entered"]
-[connection signal="body_exited" from="Range" to="." method="_on_range_body_exited"]
[connection signal="hover_enter" from="SelectableArea" to="." method="_on_selectable_area_hover_enter"]
[connection signal="hover_exit" from="SelectableArea" to="." method="_on_selectable_area_hover_exit"]
[connection signal="select_primary" from="SelectableArea" to="." method="_on_selectable_area_select_primary"]