Files
VMSolidus 963a74711b Timer Processing Cleanup (#22821)
<img width="1144" height="599" alt="image"
src="https://github.com/user-attachments/assets/675f645e-23c7-4c5b-905c-6ab259676fb3"
/>

Not a single one of these timers are doing anything, but they occupy
processing time. This PR makes them not do that. When you activate a
timer, they start processing. When the timer finishes, it stops
processing. No need for it to linger in the processing queue
indefinitely. There's like a hundred of these things on live.
2026-07-11 14:33:47 +00:00

102 lines
2.2 KiB
Plaintext

/obj/item/assembly/timer
name = "timer"
desc = "Used to time things. Works well with contraptions which has to count down. Tick tock."
icon_state = "timer"
drop_sound = 'sound/items/drop/component.ogg'
pickup_sound = 'sound/items/pickup/component.ogg'
origin_tech = list(TECH_MAGNET = 1)
matter = list(DEFAULT_WALL_MATERIAL = 500, MATERIAL_GLASS = 50)
wires = WIRE_PULSE_ASSEMBLY
secured = FALSE
var/timing = FALSE
var/time = 3
/obj/item/assembly/timer/activate()
. = ..()
if(!.)
return FALSE //Cooldown check
timing = !timing
update_icon()
START_PROCESSING(SSprocessing, src)
return FALSE
/obj/item/assembly/timer/toggle_secure()
secured = !secured
if(secured)
START_PROCESSING(SSprocessing, src)
else
timing = FALSE
STOP_PROCESSING(SSprocessing, src)
update_icon()
return secured
/obj/item/assembly/timer/proc/timer_end()
STOP_PROCESSING(SSprocessing, src)
if(!secured)
return FALSE
pulse(FALSE)
if(!holder)
audible_message("[icon2html(src, viewers(get_turf(src)))] *beep* *beep*", "*beep* *beep*")
cooldown = 2
addtimer(CALLBACK(src, PROC_REF(process_cooldown)), 1 SECOND)
/obj/item/assembly/timer/process()
if(!timing)
return PROCESS_KILL
if(time > 0)
time--
if(time <= 0)
timing = FALSE
timer_end()
time = 10
/obj/item/assembly/timer/update_icon()
ClearOverlays()
attached_overlays = list()
if(timing)
AddOverlays("timer_timing")
attached_overlays += "timer_timing"
if(holder)
holder.update_icon()
/obj/item/assembly/timer/interact(mob/user)
if(!secured)
to_chat(user, SPAN_WARNING("\The [src] is unsecured!"))
return
ui_interact(user)
/obj/item/assembly/timer/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Timer", "Timer Assembly", 320, 220)
ui.open()
/obj/item/assembly/timer/ui_data(mob/user)
var/list/data = list()
data["timeractive"] = timing
data["time"] = time
return data
/obj/item/assembly/timer/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
switch(action)
if("time")
timing = !timing
update_icon()
. = TRUE
if("tp")
var/tp = text2num(params["tp"])
time = clamp(tp, 1, 600)
. = TRUE