Added Damageable class that crating_station inherits from. Added new broken state to crafting_station with status light

This commit is contained in:
akshay committed 2022-08-18 01:56:07 -04:00
1 parent 63c0199d77
commit 7289eba670
15 files changed
+180 -72

No files matched your search

+15 -5
View File
@@ -3,17 +3,20 @@ extends Reference
const NAME = "blocked"
var ctx = null
var label : String = "Blocked!"
func _init():
pass
func _init(block_string : String):
label = block_string
func enter_from(state, block_string = null):
ctx.progress_text.text = block_string
func enter_from(state):
ctx.progress_text.text = label
ctx.coin_machine.enabled = false
ctx.item_dump.enabled = false
ctx.item_holder.add_enabled = true
for item_slot in ctx.item_slots:
item_slot.add_enabled = true
item_slot.remove_enabled = true
ctx.status_light.warn()
func exit_to(state):
pass
@@ -32,4 +35,11 @@ func on_slot_item_changed(item):
func on_item_holder_item_changed(item):
if item == null:
ctx.change_state(ctx.StateIdle.new())
ctx.change_state(ctx.States[ctx.EState.IDLE].new())
func on_item_dump_item_dump_completed():
pass
func on_damage_taken():
if ctx.current_hp <= 0:
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
+46
View File
@@ -0,0 +1,46 @@
extends Reference
const NAME = "broken"
var ctx = null
func _init():
pass
func enter_from(state):
ctx.coin_machine.enabled = false
ctx.item_dump.enabled = true
ctx.item_dump.reset()
ctx.item_holder.add_enabled = true
ctx.progress_text.text = "Broken"
for item_slot in ctx.item_slots:
item_slot.add_enabled = true
item_slot.remove_enabled = true
ctx.status_light.fail()
func exit_to(state):
pass
func update(delta):
pass
func on_coin_machine_coin_requirement_met(player):
assert(false)
func on_gen_timer_timeout():
assert(false)
func on_slot_item_changed(item):
pass
func on_item_holder_item_changed(item):
pass
func on_item_dump_item_dump_completed():
if ctx.item_holder.item_in_hold == null:
ctx.change_state(ctx.States[ctx.EState.IDLE].new())
else:
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!"))
func on_damage_taken():
assert(false, "cant take damage if already broken")
+17 -4
View File
@@ -8,11 +8,12 @@ var item_to_craft = null
func _init():
pass
func enter_from(state, user_data = null):
func enter_from(state):
for item_slot in ctx.item_slots:
item_slot.add_enabled = true
item_slot.remove_enabled = true
ctx.item_holder.add_enabled = true
ctx.item_dump.enabled = false
ctx.progress_text.text = "Ready!"
update_coin_machine_status()
@@ -25,7 +26,7 @@ func update(delta):
func on_coin_machine_coin_requirement_met(player):
item_to_craft = get_craft_recipe_item()
assert(item_to_craft != null)
ctx.change_state(ctx.StateWorking.new(), item_to_craft)
ctx.change_state(ctx.States[ctx.EState.WORKING].new(item_to_craft) )
func on_gen_timer_timeout():
assert(false, "gen timer shouldn't trigger while idle")
@@ -37,8 +38,15 @@ func on_slot_item_changed(item):
func on_item_holder_item_changed(item):
# if target spot is occupied, go to blocked state
if item != null:
ctx.change_state(ctx.StateBlocked.new(), "Blocked!")
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!"))
func on_item_dump_item_dump_completed():
pass
func on_damage_taken():
if ctx.current_hp <= 0:
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
func get_craft_recipe_item():
var items_in_slots = []
for item_slot in ctx.item_slots:
@@ -49,4 +57,9 @@ func get_craft_recipe_item():
return ctx.recipes.find_recipe(items_in_slots)
func update_coin_machine_status():
ctx.coin_machine.enabled = get_craft_recipe_item() != null
var can_craft_recipe : bool = get_craft_recipe_item() != null
ctx.coin_machine.enabled = can_craft_recipe
if can_craft_recipe:
ctx.status_light.prime()
else:
ctx.status_light.idle()
+13 -5
View File
@@ -5,18 +5,19 @@ const NAME = "working"
var ctx = null
var crafting_item = null
func _init():
pass
func enter_from(state, item_to_craft = null):
func _init(item_to_craft : Resource):
crafting_item = item_to_craft
assert(crafting_item != null)
func enter_from(state):
ctx.coin_machine.enabled = false
ctx.item_dump.enabled = false
ctx.item_holder.add_enabled = false
for item_slot in ctx.item_slots:
item_slot.add_enabled = false
item_slot.remove_enabled = false
ctx.gen_timer.start()
ctx.status_light.activate()
ctx.progress_text.text = "Progress: 0%"
func exit_to(state):
@@ -31,15 +32,22 @@ func update(delta):
func on_coin_machine_coin_requirement_met(player):
assert(false, "coin machine should be disabled while crafting")
func on_item_dump_item_dump_completed():
pass
func on_gen_timer_timeout():
for item_slot in ctx.item_slots:
if item_slot.has_item():
item_slot.destroy_item()
ctx.item_holder.spawn_item(crafting_item)
ctx.change_state(ctx.StateBlocked.new(), "Finished: %s" % crafting_item.name)
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Finished: %s" % crafting_item.name))
func on_slot_item_changed(item):
assert(item == null, "slot items can only be destroyed at this point")
func on_item_holder_item_changed(item):
assert(item.item_type == crafting_item, "only the crafted item can be added to the item holder")
func on_damage_taken():
if ctx.current_hp <= 0:
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())