60 lines
1.4 KiB
GDScript
60 lines
1.4 KiB
GDScript
extends Node
|
|
|
|
class_name LevelData
|
|
|
|
static var state : LevelStates = LevelStates.NotInGame
|
|
static var sun_count : float = 100
|
|
|
|
var hotbar_seedpackets : Array[SeedpacketResource]
|
|
|
|
func _ready() -> void:
|
|
set_state(LevelStates.PlantPick)
|
|
LevelEventBus.state_advance_requested.connect(advance_state)
|
|
LevelEventBus.packet_placed.connect(on_packet_placed)
|
|
|
|
func _exit_tree() -> void:
|
|
set_state(LevelStates.NotInGame)
|
|
|
|
func advance_state() -> void:
|
|
set_state(state + 1)
|
|
|
|
func set_state(to : LevelStates):
|
|
state = to
|
|
match state:
|
|
LevelStates.PlantPick:
|
|
LevelEventBus.packet_selected.connect(on_seedpacket_clicked)
|
|
LevelStates.Pregame:
|
|
LevelEventBus.packet_selected.disconnect(on_seedpacket_clicked)
|
|
LevelStates.Game:
|
|
pass
|
|
LevelStates.Postgame:
|
|
pass
|
|
LevelStates.NotInGame:
|
|
pass
|
|
LevelEventBus.state_changed.emit(state)
|
|
|
|
func on_seedpacket_clicked(seedpacket : SeedpacketResource):
|
|
if hotbar_seedpackets.has(seedpacket):
|
|
hotbar_seedpackets.erase(seedpacket)
|
|
else:
|
|
hotbar_seedpackets.append(seedpacket)
|
|
LevelEventBus.hotbar_packets_update.emit(hotbar_seedpackets)
|
|
|
|
func on_packet_placed(seedpacket : SeedpacketResource):
|
|
print(seedpacket)
|
|
sun_count -= seedpacket.cost
|
|
LevelEventBus.sun_count_updated.emit(sun_count)
|
|
|
|
## Possible states of level
|
|
enum LevelStates {
|
|
## The game is during plant pick stage
|
|
PlantPick,
|
|
## The game is not yet started
|
|
Pregame,
|
|
## Game started
|
|
Game,
|
|
## Game ended
|
|
Postgame,
|
|
## Not in a level
|
|
NotInGame
|
|
}
|