42 lines
1.2 KiB
GDScript

extends Damageable
const StateIdle = preload("res://scripts/rover_station/state/idle.gd")
const StateBroken = preload("res://scripts/rover_station/state/broken.gd")
const StatePlaying = preload("res://scripts/rover_station/state/playing.gd")
var state = null
var treasure := [] # array of ItemTypes
func _ready():
state = StateBroken.new() if start_broken else StateIdle.new()
state.ctx = self
state.enter_from(null)
print("rover_station: NULL -> ", state.NAME)
func change_state(new_state):
print("rover_station: ", state.NAME, " -> ", new_state.NAME)
new_state.ctx = self
state.exit_to(new_state)
new_state.enter_from(state)
state = new_state
func _on_coin_machine_coin_requirement_met(player):
state.on_coin_machine_coin_requirement_met(player)
func _on_item_dump_completed():
state.on_item_dump_completed()
func on_player_sleep():
state.on_player_sleep()
func add_treasure(item_type: Resource):
if $item_holder.item_in_hold == null:
$item_holder.add_item(item_type.spawn_node())
else:
treasure.push_back(item_type)
func _on_item_holder_item_changed(item):
if item == null and not treasure.empty():
$item_holder.add_item(treasure.pop_front().spawn_node())