Plant spawn

This commit is contained in:
Rendo 2025-08-03 18:34:54 +05:00
commit 941912d7f1
25 changed files with 281 additions and 40 deletions

View file

@ -3,12 +3,35 @@ extends Node
class_name LevelData
static var state : LevelStates = LevelStates.NotInGame
static var sun_count : float
static var sun_count : float = 100
var hotbar_seedpackets : Array[SeedpacketResource]
func _ready() -> void:
LevelEventBus.packet_selected.connect(on_seedpacket_clicked)
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):
@ -17,6 +40,11 @@ func on_seedpacket_clicked(seedpacket : SeedpacketResource):
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
@ -27,6 +55,6 @@ enum LevelStates {
Game,
## Game ended
Postgame,
## Not in a level,
## Not in a level
NotInGame
}