Merge pull request #7024 from atlantiscze/2020_04_21_ValveProgram

Converts Shutoff valve monitoring into a MC program
This commit is contained in:
Atermonera
2020-04-28 14:57:24 -07:00
committed by VirgoBot
parent c66c3cec86
commit bdf186d16b
6 changed files with 95 additions and 69 deletions

View File

@@ -5,66 +5,27 @@
icon_screen = "power:0"
light_color = "#a97faa"
circuit = /obj/item/weapon/circuitboard/shutoff_monitor
var/datum/nano_module/shutoff_monitor/monitor
/obj/machinery/computer/shutoff_monitor/attack_hand(var/mob/user)
/obj/machinery/computer/shutoff_monitor/New()
..()
monitor = new(src)
/obj/machinery/computer/shutoff_monitor/Destroy()
qdel(monitor)
monitor = null
..()
/obj/machinery/computer/shutoff_monitor/attack_hand(var/mob/user as mob)
..()
ui_interact(user)
/obj/machinery/computer/shutoff_monitor/attack_robot(var/mob/user) // Borgs and AI will want to see this too
..()
ui_interact(user)
/obj/machinery/computer/shutoff_monitor/attack_ai(var/mob/user)
ui_interact(user)
/obj/machinery/computer/shutoff_monitor/ui_interact(mob/user, ui_key = "shutoff_monitor", var/datum/nanoui/ui = null, var/force_open = 1, var/key_state = null)
var/data[0]
data["valves"] = list()
for(var/obj/machinery/atmospherics/valve/shutoff/S in GLOB.shutoff_valves)
data["valves"][++data["valves"].len] = list("name" = S.name, "enable" = S.close_on_leaks, "open" = S.open, "x" = S.x, "y" = S.y, "z" = S.z, "ref" = "\ref[S]")
// update the ui if it exists, returns null if no ui is passed/found
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if(!ui)
// the ui does not exist, so we'll create a new() one
// for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
ui = new(user, src, ui_key, "shutoff_monitor.tmpl", "Automated Shutoff Valve Monitor", 625, 700, state = key_state)
// when the ui is first opened this is the data it will use
ui.set_initial_data(data)
// open the new ui window
ui.open()
// auto update every 20 Master Controller tick
ui.set_auto_update(20) // Longer term to reduce the rate of data collection and processing
/obj/machinery/computer/shutoff_monitor/Topic(href, href_list)
if(..())
return 1
if(href_list["toggle_enable"])
var/obj/machinery/atmospherics/valve/shutoff/S = locate(href_list["toggle_enable"])
// Invalid ref
if(!istype(S))
return 0
S.close_on_leaks = !S.close_on_leaks
if(href_list["toggle_open"])
var/obj/machinery/atmospherics/valve/shutoff/S = locate(href_list["toggle_open"])
// Invalid ref
if(!istype(S))
return 0
if(S.open)
S.close()
else
S.open()
return
/obj/machinery/computer/shutoff_monitor/ui_interact(mob/user, ui_key = "shutoff_monitor", var/datum/nanoui/ui = null, var/force_open = 1)
monitor.ui_interact(user, ui_key, ui, force_open)
/obj/machinery/computer/shutoff_monitor/update_icon()
..()
if(!(stat & (NOPOWER|BROKEN)))
add_overlay("ai-fixer-empty")
else
cut_overlay("ai-fixer-empty")