mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-13 03:02:38 +00:00
* [MDB IGNORE] APC controller and Power Monitor/AmpCheck fixes, aka How do I write PR titles (#69146) About The Pull Request bgug fix stuff APC controller UI has its elements section'ed off. The backend has been redone to make the behaviour of the APC controller a bit less janky. The console should be more stable, and all the soul has been removed from the code and the UI. before this PR stales out from nobody wanting to review my pr, I should probably outline what exactly changed: APC controller consoles have had their APC code almost entirely reworked. They no longer have to hold a reference to the person using the controller currently, and APCs themselves no longer hold a reference to the controller, instead to the person directly. A lot of code was moved to APC themselves to make it a lot more stable. APC controller used to call toggle_breaker without passing args, causing a runtime. Fixed in Fixes the power flow control console not actually being able to toggle breakers #69343 APC controller UI has had the Window.Content tags moved up to the top component, and a lot has been sectioned off to make the UI more sane. AmpCheck used to look for a wire on it's turf, or as a fallback look for the Area APC. A check to see if the APC has a terminal did so on a weakref, causing a runtime and preventing the program from ever finding a valid APC in it's area, making it show nothing. This has been fixed. On the other hand, the power monitor console did not store the ground wire or APC terminal as a weakref, this has been updated. As a fallback, if there are still no APCs in the powernet, the UI will show a dimmer popup. There was a "secret" power monitor variation in code so PDAs could not access monitors in hidden places. With the removal of PDAs, this control console is useless. Why It's Good For The Game Tiny bit of (much needed) polish on some useful tools in the engineering department. Changelog cl fix: Fixed runtime when using AmpCheck without connecting the console with a wire. fix: Fixed a few runtimes that could occur when using APC controller consoles. qol: Sucked soul out of APC controller code and UI. del: Removed "secret" power monitor console. /cl * [MDB IGNORE] APC controller and Power Monitor/AmpCheck fixes, aka How do I write PR titles * update paths Co-authored-by: distributivgesetz <distributivgesetz93@gmail.com> Co-authored-by: Tom <8881105+tf-4@users.noreply.github.com>
113 lines
3.6 KiB
Plaintext
113 lines
3.6 KiB
Plaintext
//modular computer program version is located in code\modules\modular_computers\file_system\programs\powermonitor.dm, /datum/computer_file/program/power_monitor
|
|
|
|
/obj/machinery/computer/monitor
|
|
name = "power monitoring console"
|
|
desc = "It monitors power levels across the station."
|
|
icon_screen = "power"
|
|
icon_keyboard = "power_key"
|
|
light_color = LIGHT_COLOR_YELLOW
|
|
use_power = ACTIVE_POWER_USE
|
|
circuit = /obj/item/circuitboard/computer/powermonitor
|
|
tgui_id = "PowerMonitor"
|
|
|
|
var/datum/weakref/attached_wire_ref
|
|
var/datum/weakref/local_apc_ref
|
|
|
|
var/list/history = list()
|
|
var/record_size = 60
|
|
var/record_interval = 50
|
|
var/next_record = 0
|
|
|
|
/obj/machinery/computer/monitor/Initialize(mapload)
|
|
. = ..()
|
|
search()
|
|
history["supply"] = list()
|
|
history["demand"] = list()
|
|
|
|
/obj/machinery/computer/monitor/process()
|
|
if(!get_powernet())
|
|
update_use_power(IDLE_POWER_USE)
|
|
search()
|
|
else
|
|
update_use_power(ACTIVE_POWER_USE)
|
|
record()
|
|
|
|
/obj/machinery/computer/monitor/proc/search() //keep in sync with /obj/machinery/computer/monitor's version
|
|
var/turf/T = get_turf(src)
|
|
attached_wire_ref = WEAKREF(locate(/obj/structure/cable) in T)
|
|
if(attached_wire_ref)
|
|
return
|
|
var/area/A = get_area(src) //if the computer isn't directly connected to a wire, attempt to find the APC powering it to pull it's powernet instead
|
|
if(!A)
|
|
return
|
|
var/obj/machinery/power/apc/local_apc = A.apc
|
|
if(!local_apc)
|
|
return
|
|
if(!local_apc.terminal) //this really shouldn't happen without badminnery.
|
|
local_apc = null
|
|
local_apc_ref = WEAKREF(local_apc)
|
|
|
|
/obj/machinery/computer/monitor/proc/get_powernet() //keep in sync with /datum/computer_file/program/power_monitor's version //np
|
|
var/obj/structure/cable/attached_wire = attached_wire_ref?.resolve()
|
|
var/obj/machinery/power/apc/local_apc = local_apc_ref?.resolve()
|
|
if(attached_wire || (local_apc?.terminal))
|
|
return attached_wire ? attached_wire.powernet : local_apc.terminal.powernet
|
|
return FALSE
|
|
|
|
/obj/machinery/computer/monitor/proc/record() //keep in sync with /datum/computer_file/program/power_monitor's version
|
|
if(world.time >= next_record)
|
|
next_record = world.time + record_interval
|
|
|
|
var/datum/powernet/connected_powernet = get_powernet()
|
|
|
|
var/list/supply = history["supply"]
|
|
if(connected_powernet)
|
|
supply += connected_powernet.viewavail
|
|
if(supply.len > record_size)
|
|
supply.Cut(1, 2)
|
|
|
|
var/list/demand = history["demand"]
|
|
if(connected_powernet)
|
|
demand += connected_powernet.viewload
|
|
if(demand.len > record_size)
|
|
demand.Cut(1, 2)
|
|
|
|
/obj/machinery/computer/monitor/ui_interact(mob/user, datum/tgui/ui)
|
|
. = ..()
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
ui = new(user, src, "PowerMonitor", name)
|
|
ui.open()
|
|
|
|
/obj/machinery/computer/monitor/ui_data()
|
|
var/datum/powernet/connected_powernet = get_powernet()
|
|
var/list/data = list()
|
|
data["stored"] = record_size
|
|
data["interval"] = record_interval / 10
|
|
data["attached"] = connected_powernet ? TRUE : FALSE
|
|
data["history"] = history
|
|
data["areas"] = list()
|
|
|
|
if(connected_powernet)
|
|
data["supply"] = display_power(connected_powernet.viewavail)
|
|
data["demand"] = display_power(connected_powernet.viewload)
|
|
for(var/obj/machinery/power/terminal/term in connected_powernet.nodes)
|
|
var/obj/machinery/power/apc/A = term.master
|
|
if(istype(A))
|
|
var/cell_charge
|
|
if(!A.cell)
|
|
cell_charge = 0
|
|
else
|
|
cell_charge = A.cell.percent()
|
|
data["areas"] += list(list(
|
|
"name" = A.area.name,
|
|
"charge" = cell_charge,
|
|
"load" = display_power(A.lastused_total),
|
|
"charging" = A.charging,
|
|
"eqp" = A.equipment,
|
|
"lgt" = A.lighting,
|
|
"env" = A.environ
|
|
))
|
|
|
|
return data
|