seedpackets and handlers
This commit is contained in:
parent
2a7c402cd0
commit
73a2fe42ad
16 changed files with 157 additions and 58 deletions
|
|
@ -1,5 +1,9 @@
|
|||
extends AspectRatioContainer
|
||||
|
||||
## Class that allows player to choose SeedpacketResource
|
||||
|
||||
class_name Seedpacket
|
||||
|
||||
@onready var button := $TextureButton
|
||||
@onready var preview :=$TextureButton/PreviewContainer/Preview
|
||||
@onready var cost := $TextureButton/Cost
|
||||
|
|
@ -9,53 +13,33 @@ extends AspectRatioContainer
|
|||
@onready var locked_rect := $TextureButton/Locked
|
||||
|
||||
var held_resource : SeedpacketResource
|
||||
var forbidden : bool = false
|
||||
var locked : bool = false
|
||||
var hotbar : bool = false
|
||||
var disabled : bool = false
|
||||
|
||||
#region Godot methods
|
||||
func _ready() -> void:
|
||||
LevelEventBus.entity_placed.connect(on_entity_placed)
|
||||
LevelEventBus.sun_count_updated.connect(on_sun_count_updated)
|
||||
LevelEventBus.state_changed.connect(on_level_state_changed)
|
||||
var handler : SeedpacketHandler
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
button.disabled = recharge_timer.time_left > 0 or forbidden or locked or disabled
|
||||
update_contents()
|
||||
#endregion
|
||||
button.disabled = recharge_timer.time_left > 0 or handler.is_avaiable() == false
|
||||
|
||||
#region Signal methods
|
||||
func on_pressed():
|
||||
LevelEventBus.packet_selected.emit(held_resource)
|
||||
if LevelData.state == LevelData.LevelStates.Game:
|
||||
LevelEventBus.packet_selected_during_game.emit(held_resource)
|
||||
if LevelEventBus.packet_placed.is_connected(on_packet_placed) == false:
|
||||
LevelEventBus.packet_placed.connect(on_packet_placed)
|
||||
focus_exited.connect(disconnect_placement)
|
||||
|
||||
func on_entity_placed(entity : SeedpacketResource):
|
||||
if entity == held_resource:
|
||||
recharge_timer.start()
|
||||
#endregion
|
||||
|
||||
func set_resource(to : SeedpacketResource):
|
||||
held_resource = to
|
||||
func set_handler(to : SeedpacketHandler):
|
||||
if handler:
|
||||
handler.exit()
|
||||
handler = to
|
||||
update_contents()
|
||||
|
||||
func update_contents():
|
||||
cost.text = str(held_resource.cost)
|
||||
preview.texture = held_resource.preview
|
||||
avaibility.visible = forbidden or locked or disabled
|
||||
locked_rect.visible = locked
|
||||
forbidden_rect.visible = forbidden
|
||||
avaibility.visible = handler.is_avaiable() == false
|
||||
handler.on_updated_contents()
|
||||
|
||||
func on_sun_count_updated(to : float):
|
||||
if hotbar:
|
||||
disabled = held_resource.cost < to
|
||||
func on_packet_placed(packet : SeedpacketResource):
|
||||
if held_resource != packet: return
|
||||
disconnect_placement()
|
||||
|
||||
func on_level_state_changed(state : LevelData.LevelStates):
|
||||
match state:
|
||||
LevelData.LevelStates.Game:
|
||||
disabled = held_resource.cost < LevelData.sun_count
|
||||
LevelData.LevelStates.PlantPick:
|
||||
disabled = false
|
||||
_:
|
||||
disabled = true
|
||||
func disconnect_placement():
|
||||
LevelEventBus.packet_placed.disconnect(on_packet_placed)
|
||||
focus_exited.disconnect(disconnect_placement)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue