diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-19 15:24:50 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-19 15:24:50 +0100 |
commit | 72863ffa31e27f4c6be862d80472cfb897fccaea (patch) | |
tree | ce04be8d77b10c797c8ff854c8ff1a219eb1af46 /Towers | |
parent | 63d2a59042fb9d90a586ad85d8364de7c38aea8e (diff) |
Diffstat (limited to 'Towers')
-rw-r--r-- | Towers/Components/Assets/poison-component.png | bin | 0 -> 176 bytes | |||
-rw-r--r-- | Towers/Components/Assets/poison-component.png.import | 34 | ||||
-rw-r--r-- | Towers/Components/BurnComponent.tscn | 2 | ||||
-rw-r--r-- | Towers/Components/PoisonComponent.gd | 7 | ||||
-rw-r--r-- | Towers/Components/PoisonComponent.tscn | 12 | ||||
-rw-r--r-- | Towers/Components/TowerComponent.gd | 4 | ||||
-rw-r--r-- | Towers/Tower.gd | 21 | ||||
-rw-r--r-- | Towers/Tower.tscn | 1 |
8 files changed, 70 insertions, 11 deletions
diff --git a/Towers/Components/Assets/poison-component.png b/Towers/Components/Assets/poison-component.png Binary files differnew file mode 100644 index 0000000..76f561d --- /dev/null +++ b/Towers/Components/Assets/poison-component.png diff --git a/Towers/Components/Assets/poison-component.png.import b/Towers/Components/Assets/poison-component.png.import new file mode 100644 index 0000000..8a1c383 --- /dev/null +++ b/Towers/Components/Assets/poison-component.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://rkeldjv41ww8" +path="res://.godot/imported/poison-component.png-83d1bbb149be90a9cdae02ce5657d8f9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Towers/Components/Assets/poison-component.png" +dest_files=["res://.godot/imported/poison-component.png-83d1bbb149be90a9cdae02ce5657d8f9.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Towers/Components/BurnComponent.tscn b/Towers/Components/BurnComponent.tscn index 285cfa0..11e65ff 100644 --- a/Towers/Components/BurnComponent.tscn +++ b/Towers/Components/BurnComponent.tscn @@ -4,7 +4,7 @@ [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")] +[node name="BurnTowerComponent" instance=ExtResource("1_56lm4")] script = ExtResource("2_nevgj") type = 4 diff --git a/Towers/Components/PoisonComponent.gd b/Towers/Components/PoisonComponent.gd new file mode 100644 index 0000000..77ee4fb --- /dev/null +++ b/Towers/Components/PoisonComponent.gd @@ -0,0 +1,7 @@ +extends TowerComponent + + +func on_shoot(target: Unit): + var effect = preload("res://Effects/PoisonEffect.tscn").instantiate() + effect.level = level + target.add_effect(effect) diff --git a/Towers/Components/PoisonComponent.tscn b/Towers/Components/PoisonComponent.tscn new file mode 100644 index 0000000..9e6b21e --- /dev/null +++ b/Towers/Components/PoisonComponent.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=4 format=3 uid="uid://bx1bi1ko6tyqq"] + +[ext_resource type="PackedScene" uid="uid://cly4agfoqhq2q" path="res://Towers/Components/TowerComponent.tscn" id="1_euxd5"] +[ext_resource type="Script" path="res://Towers/Components/PoisonComponent.gd" id="2_dnmjy"] +[ext_resource type="Texture2D" uid="uid://rkeldjv41ww8" path="res://Towers/Components/Assets/poison-component.png" id="3_3hijl"] + +[node name="PoisonTowerComponent" instance=ExtResource("1_euxd5")] +script = ExtResource("2_dnmjy") +type = 5 + +[node name="Sprite" parent="." index="0"] +texture = ExtResource("3_3hijl") diff --git a/Towers/Components/TowerComponent.gd b/Towers/Components/TowerComponent.gd index 30b1c44..9a16845 100644 --- a/Towers/Components/TowerComponent.gd +++ b/Towers/Components/TowerComponent.gd @@ -66,7 +66,9 @@ 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() + var component = load( + "res://Towers/Components/%sComponent.tscn" % [ComponentType.keys()[data.type]] + ).instantiate() component.type = data.type component.level = data.level diff --git a/Towers/Tower.gd b/Towers/Tower.gd index 34e12ae..73b1614 100644 --- a/Towers/Tower.gd +++ b/Towers/Tower.gd @@ -151,12 +151,13 @@ func add_component(component: TowerComponent): func redraw_components(): - var keys = components.keys() - for idx in range(keys.size()): - var key = keys[idx] - var component: TowerComponent = components[key] - var sprite = %ComponentsAnchor.get_node(NodePath(component.id)) - sprite.position.y = (idx + 1) * -16 + pass + #var keys = components.keys() + #for idx in range(keys.size()): + #var key = keys[idx] + #var component: TowerComponent = components[key] + ##var sprite = %ComponentsAnchor.get_node(NodePath(component.id)) + ##sprite.position.y = (idx + 1) * -16 func get_region(): @@ -220,9 +221,11 @@ func to_network_data() -> NetworkData: func update_with_network_data(data: NetworkData): for component_data in data.components: - var component = get_node(component_data.path) as TowerComponent - component.update_with_network_data(dict_to_inst(component_data)) - redraw_components() + var component = get_node_or_null(component_data.path) as TowerComponent + if not component: + add_component(TowerComponent.from_network_data(dict_to_inst(component_data))) + else: + component.update_with_network_data(dict_to_inst(component_data)) static func from_network_data(data: NetworkData) -> Tower: var tower: Tower = preload("res://Towers/Tower.tscn").instantiate() diff --git a/Towers/Tower.tscn b/Towers/Tower.tscn index 839917c..cb6edd9 100644 --- a/Towers/Tower.tscn +++ b/Towers/Tower.tscn @@ -114,3 +114,4 @@ position = Vector2(16, 16) [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"] +[connection signal="select_secondary" from="SelectableArea" to="." method="_on_selectable_area_select_secondary"] |