32 lines
1,000 B
GDScript
32 lines
1,000 B
GDScript
extends SeedpacketHandler
|
|
|
|
## Seedpacket handler for hotbar plants.
|
|
|
|
class_name HotbarHandler
|
|
|
|
## Is current state valid for use?
|
|
|
|
var valid_state : bool = true
|
|
var enough_sun : bool = true
|
|
|
|
func _init(packet : Seedpacket) -> void:
|
|
super._init(packet)
|
|
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()
|