Updated item_generator to have states. Also made it extend Damageable class and added a broken state
This commit is contained in:
1 parent
14eb5b24de
commit
6e6da14975
9 files changed
+260
-70
No files matched your search
@@ -0,0 +1,43 @@
|
||||
extends Reference
|
||||
|
||||
const NAME = "blocked"
|
||||
|
||||
var ctx = null
|
||||
var label : String = "Blocked!"
|
||||
|
||||
func _init(var block_string : String):
|
||||
label = block_string
|
||||
|
||||
func enter_from(state):
|
||||
for item_slot in ctx.item_slots:
|
||||
item_slot.add_enabled = true
|
||||
item_slot.remove_enabled = true
|
||||
ctx.item_dump.enabled = false
|
||||
ctx.coin_machine.enabled = false
|
||||
ctx.progress_text.text = label
|
||||
ctx.status_light.warn()
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
pass
|
||||
|
||||
func on_coin_machine_coin_requirement_met(player):
|
||||
assert(false, "coin machine should be disabled while blocked")
|
||||
|
||||
func on_gen_timer_timeout():
|
||||
assert(false, "gen timer should be disabled while blocked")
|
||||
|
||||
func on_item_slot_item_changed(item):
|
||||
for item_slot in ctx.item_slots:
|
||||
if item_slot.has_item():
|
||||
return
|
||||
ctx.change_state(ctx.States[ctx.EState.IDLE].new())
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
assert(false, "item dump should be disabled while blocked")
|
||||
|
||||
func on_damage_taken():
|
||||
if ctx.current_hp <= 0:
|
||||
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
|
||||
@@ -0,0 +1,43 @@
|
||||
extends Reference
|
||||
|
||||
const NAME = "broken"
|
||||
|
||||
var ctx = null
|
||||
|
||||
func _init():
|
||||
pass
|
||||
|
||||
func enter_from(state):
|
||||
for item_slot in ctx.item_slots:
|
||||
item_slot.add_enabled = true
|
||||
item_slot.remove_enabled = true
|
||||
ctx.item_dump.enabled = true
|
||||
ctx.item_dump.reset()
|
||||
ctx.coin_machine.enabled = false
|
||||
ctx.progress_text.text = "Broken!"
|
||||
ctx.status_light.fail()
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
pass
|
||||
|
||||
func on_coin_machine_coin_requirement_met(player):
|
||||
assert(false, "coin machine should be disabled while broken")
|
||||
|
||||
func on_gen_timer_timeout():
|
||||
assert(false, "gen timer should be disabled while broken")
|
||||
|
||||
func on_item_slot_item_changed(item):
|
||||
assert(false, "item dump should be disabled while broken")
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
for item_slot in ctx.item_slots:
|
||||
if item_slot.has_item():
|
||||
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!"))
|
||||
return
|
||||
ctx.change_state(ctx.States[ctx.EState.IDLE].new())
|
||||
|
||||
func on_damage_taken():
|
||||
assert(false, "cant take damage if already broken")
|
||||
@@ -0,0 +1,41 @@
|
||||
extends Reference
|
||||
|
||||
const NAME = "idle"
|
||||
|
||||
var ctx = null
|
||||
var item_to_craft = null
|
||||
|
||||
func _init():
|
||||
pass
|
||||
|
||||
func enter_from(state):
|
||||
for item_slot in ctx.item_slots:
|
||||
item_slot.add_enabled = true
|
||||
item_slot.remove_enabled = true
|
||||
ctx.item_dump.enabled = false
|
||||
ctx.coin_machine.enabled = true
|
||||
ctx.progress_text.text = "Ready!"
|
||||
ctx.status_light.idle()
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
pass
|
||||
|
||||
func on_coin_machine_coin_requirement_met(player):
|
||||
ctx.change_state(ctx.States[ctx.EState.WORKING].new())
|
||||
|
||||
func on_gen_timer_timeout():
|
||||
assert(false, "gen timer cannot be running while idle")
|
||||
|
||||
func on_item_slot_item_changed(item):
|
||||
if item != null:
|
||||
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Blocked!"))
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
assert(false, "item dump should be disabled while idle")
|
||||
|
||||
func on_damage_taken():
|
||||
if ctx.current_hp <= 0:
|
||||
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
|
||||
@@ -0,0 +1,50 @@
|
||||
extends Reference
|
||||
|
||||
const NAME = "working"
|
||||
|
||||
var ctx = null
|
||||
|
||||
func _init():
|
||||
pass
|
||||
|
||||
func enter_from(state):
|
||||
for item_slot in ctx.item_slots:
|
||||
item_slot.add_enabled = false
|
||||
item_slot.remove_enabled = false
|
||||
ctx.item_dump.enabled = false
|
||||
ctx.coin_machine.enabled = false
|
||||
ctx.progress_text.text = "Progress: 0%"
|
||||
ctx.status_light.activate()
|
||||
ctx.gen_timer.start()
|
||||
|
||||
func exit_to(state):
|
||||
pass
|
||||
|
||||
func update(delta):
|
||||
var time_left : float = ctx.gen_timer.time_left
|
||||
var time_passed : float = ctx.gen_time - time_left
|
||||
var percent_complete : float = (time_passed / ctx.gen_time) * 100.0
|
||||
ctx.progress_text.text = "Progress: %d%%" % percent_complete
|
||||
|
||||
func on_coin_machine_coin_requirement_met(player):
|
||||
assert(false, "coin machine should be disabled while working")
|
||||
|
||||
func on_gen_timer_timeout():
|
||||
var count : int = 0
|
||||
for item_slot in ctx.item_slots:
|
||||
if count < ctx.gen_count:
|
||||
item_slot.spawn_item(ctx.gen_item)
|
||||
count += 1
|
||||
item_slot.add_enabled = true
|
||||
ctx.change_state(ctx.States[ctx.EState.BLOCKED].new("Finished!"))
|
||||
|
||||
func on_item_slot_item_changed(item):
|
||||
assert(item != null)
|
||||
|
||||
func on_item_dump_item_dump_completed():
|
||||
assert(false, "item dump should be disabled while working")
|
||||
|
||||
func on_damage_taken():
|
||||
if ctx.current_hp <= 0:
|
||||
ctx.gen_timer.stop()
|
||||
ctx.change_state(ctx.States[ctx.EState.BROKEN].new())
|
||||
Reference in new issue
Block a user