44 lines
1.3 KiB
GDScript
44 lines
1.3 KiB
GDScript
extends Damageable
|
|
|
|
const StateIdle = preload("res://scripts/hydroponics_station/state/idle.gd")
|
|
const StateGrowing = preload("res://scripts/hydroponics_station/state/growing.gd")
|
|
const StateBlocked = preload("res://scripts/hydroponics_station/state/blocked.gd")
|
|
const StateBroken = preload("res://scripts/hydroponics_station/state/broken.gd")
|
|
|
|
export var grow_time: float = 2.0
|
|
var state = null
|
|
|
|
onready var status_light = $"%status_light"
|
|
onready var item_dump = $"%item_dump"
|
|
|
|
func _ready():
|
|
$grow_timer.wait_time = grow_time
|
|
|
|
state = StateBroken.new() if start_broken else StateIdle.new()
|
|
state.ctx = self
|
|
state.enter_from(null)
|
|
print("hydroponics_station: NULL -> ", state.NAME)
|
|
|
|
func change_state(new_state):
|
|
print("hydroponics_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_grow_timer_timeout():
|
|
state.on_grow_timer_timeout()
|
|
|
|
func _on_item_holder_item_changed(item):
|
|
state.on_item_holder_item_changed(item)
|
|
|
|
func _on_item_dump_item_dump_completed():
|
|
state.on_item_dump_item_dump_completed()
|
|
|
|
func take_damage(damage : int = 1):
|
|
.take_damage(damage)
|
|
state.on_damage_taken()
|