This commit is contained in:
snider committed 2022-08-15 21:42:48 -07:00
1 parent 83fc7e5924
commit 4c8a337a2d
12 files changed
+344 -3

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
extends Resource
class_name ItemTypeCount
export var item_type: Resource
export var count: int
+52
View File
@@ -0,0 +1,52 @@
extends Spatial
signal item_dump_completed
signal item_dumped
# Godot is not configurable enough (without great pains)
# to make this look less dumb
export var item_type_0: Resource
export var item_count_0: int
export var item_type_1: Resource
export var item_count_1: int
export var item_type_2: Resource
export var item_count_2: int
var remaining := {}
export var enabled = true
func _ready():
reset()
func reset():
remaining.clear()
if item_type_0 and item_count_0 > 0:
remaining[item_type_0] = item_count_0
if item_type_1 and item_count_1 > 0:
remaining[item_type_1] = item_count_1
if item_type_2 and item_count_2 > 0:
remaining[item_type_2] = item_count_2
func on_player_interact(player) -> bool:
if not enabled:
return false
if remaining.empty():
return false
if not player.has_item():
return false
if not remaining.has(player.item_in_hand.item_type):
return false
assert(remaining[player.item_in_hand.item_type] > 0, "remaining dictionary should always erase keys with a value of 0")
# Remove the player's item and mark off the item on the remaining list
var item = player.drop_item_in_hand()
remaining[item.item_type] -= 1
if remaining[item.item_type] <= 0:
remaining.erase(item.item_type)
item.queue_free()
emit_signal("item_dumped")
# Check if everything's been checked off
if remaining.empty():
emit_signal("item_dump_completed")
return true
+16 -2
View File
@@ -3,18 +3,28 @@ 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")
const StateBroken = preload("res://scripts/oven/state/broken.gd")
export var cook_time: float = 2.0
export var broken: bool = false setget set_broken
var state = null
func _ready():
$cook_timer.wait_time = cook_time
state = StateIdle.new()
if broken:
state = StateBroken.new()
else:
state = StateIdle.new()
state.ctx = self
state.enter_from(null)
print("oven: NULL -> ", state.NAME)
func set_broken(new_value: bool):
if broken == new_value:
return
broken == new_value
state.on_broken(broken)
func change_state(new_state):
print("oven: ", state.NAME, " -> ", new_state.NAME)
new_state.ctx = self
@@ -30,3 +40,7 @@ func _on_cook_timer_timeout():
func _on_item_holder_item_changed(item):
state.on_item_holder_item_changed(item)
func _on_item_dump_item_dump_completed():
pass # Replace with function body.
+34
View File
@@ -0,0 +1,34 @@
extends Reference
const NAME = "broken"
var ctx = null
func _init():
pass
func enter_from(state):
ctx.get_node("item_dump").enabled = true
ctx.get_node("item_dump").reset()
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("status_light").fail()
func exit_to(state):
pass
func on_break():
assert(false, "should be impossible while broken")
func on_fix():
ctx.change_state(ctx.StateIdle.new())
func on_coin_machine_coin_requirement_met(player):
assert(false, "should be impossible while broken")
func on_cook_timer_timeout():
assert(false, "should be impossible while broken")
func on_item_holder_item_changed(item):
assert(false, "should be impossible while broken")
+2
View File
@@ -16,6 +16,8 @@ func enter_from(state):
ctx.get_node("cook_timer").start()
ctx.get_node("%coil").set_surface_material(0, mat)
ctx.get_node("status_light").light_color = Color.green
ctx.get_node("status_light").activate()
func exit_to(state):
ctx.get_node("%coil").set_surface_material(0, null)
+2
View File
@@ -13,10 +13,12 @@ func enter_from(state):
ctx.get_node("coin_machine").enabled = true
ctx.get_node("%item_holder").add_enabled = false
ctx.get_node("%item_holder").remove_enabled = false
ctx.get_node("status_light").prime()
else:
ctx.get_node("coin_machine").enabled = false
ctx.get_node("%item_holder").add_enabled = true
ctx.get_node("%item_holder").remove_enabled = true
ctx.get_node("status_light").warn()
func exit_to(state):
pass
+1
View File
@@ -11,6 +11,7 @@ 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
ctx.get_node("status_light").light_color = Color.white
func exit_to(state):
pass
+19
View File
@@ -0,0 +1,19 @@
extends OmniLight
func _ready():
idle()
func idle():
$AnimationPlayer.play("idle")
func prime():
$AnimationPlayer.play("prime")
func activate():
$AnimationPlayer.play("activate")
func warn():
$AnimationPlayer.play("warn")
func fail():
$AnimationPlayer.play("fail")