summaryrefslogtreecommitdiff
path: root/Towers/Components/TowerComponent.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Towers/Components/TowerComponent.gd')
-rw-r--r--Towers/Components/TowerComponent.gd48
1 files changed, 38 insertions, 10 deletions
diff --git a/Towers/Components/TowerComponent.gd b/Towers/Components/TowerComponent.gd
index 609f88c..7ca766a 100644
--- a/Towers/Components/TowerComponent.gd
+++ b/Towers/Components/TowerComponent.gd
@@ -1,30 +1,58 @@
class_name TowerComponent
-extends Resource
+extends Node
-var name: String
-var sprite: Sprite2D = Sprite2D.new()
-var level: int = 1
+var current_tower: Tower
+
+enum ComponentType {
+ Range,
+ Attack,
+ Speed,
+ Frost,
+ Burn,
+ Poison,
+}
+
+var type: ComponentType
+var sprite: TextureRect = TextureRect.new()
+
+var id: String:
+ get():
+ return get_type_name()
+
+signal level_changed
+var level: int = 1:
+ set(value):
+ level = value
+ level_changed.emit()
func set_sprite(texture: Texture2D):
sprite.texture = texture
sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
- sprite.centered = false
- sprite.scale = Vector2(2, 2)
- sprite.name = name
+ #sprite.centered = false
+ sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
+ #sprite.scale = Vector2(2, 2)
+ sprite.name = get_type_name()
+
+
+func get_type_name(component_type: ComponentType = type):
+ return ComponentType.keys()[component_type]
+
+func on_add(tower: Tower):
+ current_tower = tower
class NetworkData extends Resource:
- var name: String
+ var type: ComponentType
var level: int
func to_network_data() -> NetworkData:
var data = NetworkData.new()
- data.name = name
+ data.type = type
data.level = level
return data
@@ -35,7 +63,7 @@ func update_with_network_data(_data: NetworkData):
static func from_network_data(data: NetworkData) -> TowerComponent:
var component = preload("res://Towers/Components/TowerComponent.gd").new()
- component.name = data.name
+ component.type = data.type
component.level = data.level
return component