Added broken state to hydroponic station and fixed a bug with all the brokens tates where they wouldn't heal the object back up on repair
This commit is contained in:
1 parent
6e6da14975
commit
ef4b8bd7cf
10 files changed
+105
-7
No files matched your search
@@ -1,16 +1,20 @@
|
||||
extends Spatial
|
||||
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 = StateIdle.new()
|
||||
|
||||
state = StateBroken.new() if start_broken else StateIdle.new()
|
||||
state.ctx = self
|
||||
state.enter_from(null)
|
||||
print("hydroponics_station: NULL -> ", state.NAME)
|
||||
@@ -30,3 +34,10 @@ func _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()
|
||||
@@ -10,6 +10,9 @@ func _init():
|
||||
func enter_from(state):
|
||||
ctx.get_node("coin_machine").enabled = false
|
||||
ctx.get_node("item_holder").add_enabled = true
|
||||
ctx.get_node("item_holder").remove_enabled = true
|
||||
ctx.status_light.warn()
|
||||
ctx.item_dump.enabled = false
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
@@ -23,3 +26,10 @@ func on_grow_timer_timeout():
|
||||
func on_item_holder_item_changed(item):
|
||||
if item == null:
|
||||
ctx.change_state(ctx.StateIdle.new())
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
assert(false)
|
||||
|
||||
func on_damage_taken():
|
||||
if ctx.current_hp <= 0:
|
||||
ctx.change_state(ctx.StateBroken.new())
|
||||
@@ -0,0 +1,36 @@
|
||||
extends Reference
|
||||
|
||||
const NAME = "broken"
|
||||
|
||||
var ctx = null
|
||||
|
||||
func _init():
|
||||
pass
|
||||
|
||||
func enter_from(state):
|
||||
ctx.get_node("coin_machine").enabled = false
|
||||
ctx.get_node("item_holder").add_enabled = false
|
||||
ctx.get_node("item_holder").remove_enabled = false
|
||||
ctx.status_light.fail()
|
||||
ctx.item_dump.enabled = true
|
||||
ctx.item_dump.reset()
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
|
||||
func on_coin_machine_coin_requirement_met(player):
|
||||
assert(false)
|
||||
|
||||
func on_grow_timer_timeout():
|
||||
assert(false)
|
||||
|
||||
func on_item_holder_item_changed(item):
|
||||
if item == null:
|
||||
ctx.change_state(ctx.StateIdle.new())
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
ctx.full_heal()
|
||||
ctx.change_state(ctx.StateIdle.new())
|
||||
|
||||
func on_damage_taken():
|
||||
assert(false, "cant take damage when broken")
|
||||
@@ -12,8 +12,11 @@ func _init():
|
||||
func enter_from(state):
|
||||
ctx.get_node("coin_machine").enabled = false
|
||||
ctx.get_node("item_holder").add_enabled = false
|
||||
ctx.get_node("item_holder").remove_enabled = false
|
||||
ctx.get_node("grow_timer").start()
|
||||
ctx.get_node("MeshInstance").set_surface_material(0, mat)
|
||||
ctx.status_light.activate()
|
||||
ctx.item_dump.enabled = false
|
||||
|
||||
func exit_to(state):
|
||||
ctx.get_node("MeshInstance").set_surface_material(0, null)
|
||||
@@ -28,3 +31,11 @@ func on_grow_timer_timeout():
|
||||
|
||||
func on_item_holder_item_changed(item):
|
||||
assert(item.item_type == raw_yam)
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
assert(false)
|
||||
|
||||
func on_damage_taken():
|
||||
ctx.get_node("grow_timer").stop()
|
||||
if ctx.current_hp <= 0:
|
||||
ctx.change_state(ctx.StateBroken.new())
|
||||
@@ -10,6 +10,9 @@ func _init():
|
||||
func enter_from(state):
|
||||
ctx.get_node("coin_machine").enabled = true
|
||||
ctx.get_node("item_holder").add_enabled = true
|
||||
ctx.get_node("item_holder").remove_enabled = true
|
||||
ctx.status_light.idle()
|
||||
ctx.item_dump.enabled = false
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
@@ -23,3 +26,10 @@ func on_grow_timer_timeout():
|
||||
func on_item_holder_item_changed(item):
|
||||
assert(item != null)
|
||||
ctx.change_state(ctx.StateBlocked.new())
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
assert(false)
|
||||
|
||||
func on_damage_taken():
|
||||
if ctx.current_hp <= 0:
|
||||
ctx.change_state(ctx.StateBroken.new())
|
||||
Reference in new issue
Block a user