seedpackets and handlers
This commit is contained in:
parent
2a7c402cd0
commit
73a2fe42ad
16 changed files with 157 additions and 58 deletions
32
scripts/gui/seedpacket/hotbar_handler.gd
Normal file
32
scripts/gui/seedpacket/hotbar_handler.gd
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
extends SeedpacketHandler
|
||||
|
||||
## Seedpacket handler for hotbar plants.
|
||||
|
||||
class_name HotbarHandler
|
||||
|
||||
## Is current state valid for use?
|
||||
|
||||
var valid_state : bool = false
|
||||
var enough_sun : bool = true
|
||||
|
||||
func _init(seedpacket : Seedpacket) -> void:
|
||||
super._init(seedpacket)
|
||||
LevelEventBus.state_changed.connect(on_level_state_changed)
|
||||
LevelEventBus.sun_count_updated.connect(on_sun_count_updated)
|
||||
|
||||
func exit() -> void:
|
||||
LevelEventBus.state_changed.disconnect(on_level_state_changed)
|
||||
LevelEventBus.sun_count_updated.disconnect(on_sun_count_updated)
|
||||
|
||||
func is_avaiable():
|
||||
return valid_state and enough_sun
|
||||
|
||||
func on_level_state_changed(state : LevelData.LevelStates):
|
||||
valid_state = state == LevelData.LevelStates.PlantPick or state == LevelData.LevelStates.Game
|
||||
if state == LevelData.LevelStates.Game:
|
||||
enough_sun = LevelData.sun_count >= seedpacket.held_resource.cost
|
||||
seedpacket.update_contents()
|
||||
|
||||
func on_sun_count_updated(to : float):
|
||||
enough_sun = to >= seedpacket.held_resource.cost
|
||||
seedpacket.update_contents()
|
||||
Loading…
Add table
Add a link
Reference in a new issue