blob: 7ca766a430f473703f4306872efefd5e796a343a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
class_name TowerComponent
extends Node
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.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 type: ComponentType
var level: int
func to_network_data() -> NetworkData:
var data = NetworkData.new()
data.type = type
data.level = level
return data
func update_with_network_data(_data: NetworkData):
pass
static func from_network_data(data: NetworkData) -> TowerComponent:
var component = preload("res://Towers/Components/TowerComponent.gd").new()
component.type = data.type
component.level = data.level
return component
|