Add food and yam interaction

This commit is contained in:
snider committed 2022-08-14 05:40:14 -07:00
1 parent 2874c11658
commit d20642e267
41 files changed
+2747 -42

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
extends Spatial
const StateIdle = preload("res://scripts/oven/state/idle.gd")
const StateCooking = preload("res://scripts/oven/state/cooking.gd")
const StateHoldingItem = preload("res://scripts/oven/state/holding_item.gd")
export var cook_time: float = 2.0
var state = null
func _ready():
$cook_timer.wait_time = cook_time
state = 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_cook_timer_timeout():
state.on_cook_timer_timeout()
func _on_item_holder_item_changed(item):
state.on_item_holder_item_changed(item)
+33
View File
@@ -0,0 +1,33 @@
extends Reference
const NAME = "cooking"
const cooked_yam = preload("res://item_types/cooked_yam.tres")
var ctx = null
var mat: SpatialMaterial = SpatialMaterial.new()
func _init():
mat.albedo_color = Color.red
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("cook_timer").start()
ctx.get_node("%coil").set_surface_material(0, mat)
func exit_to(state):
ctx.get_node("%coil").set_surface_material(0, null)
func on_coin_machine_coin_requirement_met(player):
assert(false, "coin machine should be disabled while growing")
func on_cook_timer_timeout():
var item_holder = ctx.get_node("%item_holder")
item_holder.destroy_item()
item_holder.spawn_item(cooked_yam)
ctx.change_state(ctx.StateHoldingItem.new())
func on_item_holder_item_changed(item):
assert(item == null || item.item_type == cooked_yam)
+35
View File
@@ -0,0 +1,35 @@
extends Reference
const NAME = "holding_item"
const raw_yam = preload("res://item_types/raw_yam.tres")
var ctx = null
func _init():
pass
func enter_from(state):
if ctx.get_node("%item_holder").item_in_hold.item_type == raw_yam:
ctx.get_node("coin_machine").enabled = true
ctx.get_node("%item_holder").add_enabled = false
ctx.get_node("%item_holder").remove_enabled = false
else:
ctx.get_node("coin_machine").enabled = false
ctx.get_node("%item_holder").add_enabled = true
ctx.get_node("%item_holder").remove_enabled = true
func exit_to(state):
pass
func on_coin_machine_coin_requirement_met(player):
if ctx.get_node("%item_holder").item_in_hold.item_type == raw_yam:
ctx.change_state(ctx.StateCooking.new())
func on_cook_timer_timeout():
assert(false)
func on_item_holder_item_changed(item):
if item == null:
ctx.change_state(ctx.StateIdle.new())
else:
ctx.change_state(ctx.StateHoldingItem.new())
+26
View File
@@ -0,0 +1,26 @@
extends Reference
const NAME = "idle"
var ctx = null
func _init():
pass
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 = false # not possible
func exit_to(state):
pass
func on_coin_machine_coin_requirement_met(player):
assert(false, "coin machine should be disabled while idle")
func on_cook_timer_timeout():
assert(false, "cook timer shouldn't trigger while idle")
func on_item_holder_item_changed(item):
assert(item != null, "there should be no item to remove while idle")
ctx.change_state(ctx.StateHoldingItem.new())