Skip to content

Commit

Permalink
continuation hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
silicons committed Dec 26, 2024
1 parent 8b93b0e commit f94e476
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/datums/combo/combo_tracker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var/tmp/sec_position

/datum/combo_tracker/proc/reset()
// do not cut, make a new list; subtypes might be referencing this before reset!
stored = list()
sec_set = null
sec_possible = null
Expand Down
9 changes: 9 additions & 0 deletions code/game/click/melee/melee_combo_tracker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
var/continuation_timeout = 3 SECONDS
var/tmp/continuation_timeout_active = FALSE
var/tmp/continuation_last
/// if exists, invoked with ()
/// * this is not allowed to sleep.
var/datum/callback/on_continuation_begin
/// if exists, invoked with (list/stored_keys)
/// * this is not allowed to sleep.
var/datum/callback/on_continuation_timeout

/datum/combo_tracker/melee/New(continuation_timeout)
if(!isnull(continuation_timeout))
Expand All @@ -15,12 +21,15 @@
continuation_last = world.time
if(!continuation_timeout_active)
on_timeout()
on_continuation_begin?.invoke_no_sleep()

/datum/combo_tracker/melee/proc/on_timeout()
continuation_timeout_active = FALSE
var/remaining_time = continuation_last - (world.time - continuation_timeout)
if(remaining_time < 0)
var/list/stored_keys = stored
reset()
on_continuation_timeout?.invoke_no_sleep(stored_keys)
return
addtimer(CALLBACK(src, PROC_REF(on_timeout)), remaining_time)
continuation_timeout_active = TRUE
Expand Down
13 changes: 13 additions & 0 deletions code/modules/mining/tools/kinetic/kinetic_gauntlets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
var/datum/combo_tracker/melee/combo_tracker
/// only reapplied on un-equip/re-equip right now!
var/combo_continuation_timeout = 3 SECONDS
/// our combo is active; we won't go onto clickdelay until it falls off
var/combo_continuation_active = FALSE

/obj/item/kinetic_gauntlets/update_icon()
cut_overlays()
Expand Down Expand Up @@ -65,12 +67,23 @@
start_recharge()
if(!combo_tracker)
combo_tracker = new(combo_continuation_timeout)
combo_tracker.on_continuation_begin = CALLBACK(src, PROC_REF(on_continuation_begin))
combo_tracker.on_continuation_timeout = CALLBACK(src, PROC_REF(on_continuation_timeout))

/obj/item/kinetic_gauntlets/on_unequipped(mob/wearer, slot_id_or_index, inv_op_flags, datum/event_args/actor/actor)
. = ..()
discharge()
QDEL_NULL(combo_tracker)

/obj/item/kinetic_gauntlets/proc/on_continuation_begin()
SHOULD_NOT_SLEEP(TRUE)
combo_continuation_active = TRUE

/obj/item/kinetic_gauntlets/proc/on_continuation_timeout()
SHOULD_NOT_SLEEP(TRUE)
discharge()
combo_continuation_active = FALSE

/obj/item/kinetic_gauntlets/proc/recharge()
charged = TRUE
charge_timerid = null
Expand Down

0 comments on commit f94e476

Please sign in to comment.