|
| 1 | +extends Control |
| 2 | + |
| 3 | +const ManualTickingBuffLabel = preload("uid://c1g42dnwl5xxp") |
| 4 | +const TEST_ATTRIBUTE_NAME := LevelAttribute.ATTRIBUTE_NAME |
| 5 | + |
| 6 | + |
| 7 | +@onready var apply_buff_button: Button = %ApplyBuffButton |
| 8 | +@onready var attribute_container: AttributeContainer = $AttributeContainer |
| 9 | +@onready var attribute_value_label: Label = %AttributeValueLabel |
| 10 | +@onready var buffs_v_box_container: VBoxContainer = %BuffsVBoxContainer |
| 11 | +@onready var end_turn_button: Button = %EndTurnButton |
| 12 | +@onready var turn_duration_spin_box: SpinBox = %TurnDurationSpinBox |
| 13 | + |
| 14 | + |
| 15 | +func _ready() -> void: |
| 16 | + attribute_container.apply_buff(InitializeAttributes.new()) |
| 17 | + |
| 18 | + attribute_container.buff_applied.connect(func (runtime_buff: RuntimeBuff): |
| 19 | + var buff_label := ManualTickingBuffLabel.new() |
| 20 | + |
| 21 | + buff_label.runtime_buff = runtime_buff |
| 22 | + |
| 23 | + buffs_v_box_container.add_child(buff_label) |
| 24 | + |
| 25 | + update_attribute_value_label() |
| 26 | + ) |
| 27 | + |
| 28 | + attribute_container.buff_time_elapsed.connect(func (_runtime_buff): |
| 29 | + for child in buffs_v_box_container.get_children(): |
| 30 | + child.draw() |
| 31 | + ) |
| 32 | + |
| 33 | + attribute_container.buff_removed.connect(func (runtime_buff: RuntimeBuff): |
| 34 | + for child in buffs_v_box_container.get_children(): |
| 35 | + if child.runtime_buff == runtime_buff: |
| 36 | + child.queue_free() |
| 37 | + ) |
| 38 | + |
| 39 | + apply_buff_button.pressed.connect(func (): |
| 40 | + var buff := TheBuff.new() |
| 41 | + buff.duration = turn_duration_spin_box.value |
| 42 | + attribute_container.apply_buff(buff) |
| 43 | + ) |
| 44 | + |
| 45 | + end_turn_button.pressed.connect(end_turn) |
| 46 | + |
| 47 | + update_attribute_value_label() |
| 48 | + |
| 49 | + |
| 50 | +func end_turn() -> void: |
| 51 | + attribute_container.set_tick(1.0) |
| 52 | + |
| 53 | + |
| 54 | +func update_attribute_value_label() -> void: |
| 55 | + attribute_value_label.text = TEST_ATTRIBUTE_NAME + " " + String.num(attribute_container.get_attribute_buffed_value_by_name(TEST_ATTRIBUTE_NAME), 0) |
| 56 | + |
| 57 | + |
| 58 | +class TheBuff extends AttributeBuff: |
| 59 | + func _init() -> void: |
| 60 | + attribute_name = TEST_ATTRIBUTE_NAME # that's just for the sake of the example |
| 61 | + buff_name = "Turn based buff" |
| 62 | + duration = 3.0 # the default number of turns |
| 63 | + operation = AttributeOperation.add(1.0) |
| 64 | + transient = true |
0 commit comments