mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-22 11:37:40 +01:00
tgui pump
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
|
||||
/// The maximum `target_pressure` you can set on the pump. Equates to about 1013.25 kPa.
|
||||
#define MAX_TARGET_PRESSURE 10 * ONE_ATMOSPHERE
|
||||
/// The pump will be siphoning gas.
|
||||
#define DIRECTION_IN 0
|
||||
/// The pump will be pumping gas out.
|
||||
#define DIRECTION_OUT 1
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump
|
||||
name = "Portable Air Pump"
|
||||
|
||||
icon = 'icons/obj/atmos.dmi'
|
||||
icon_state = "psiphon:0"
|
||||
density = 1
|
||||
|
||||
var/on = 0
|
||||
var/direction_out = 0 //0 = siphoning, 1 = releasing
|
||||
var/target_pressure = 100
|
||||
|
||||
var/pressuremin = 0
|
||||
var/pressuremax = 10 * ONE_ATMOSPHERE
|
||||
|
||||
density = TRUE
|
||||
volume = 1000
|
||||
/// If the pump is turned on or off.
|
||||
var/on = FALSE
|
||||
/// The direction the pump is operating in. This should be either `DIRECTION_IN` or `DIRECTION_OUT`.
|
||||
var/direction = DIRECTION_IN
|
||||
/// The desired pressure the pump should be outputting, either into the atmosphere, or into a holding tank.
|
||||
var/target_pressure = 101.325
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/update_icon()
|
||||
src.overlays = 0
|
||||
overlays = 0
|
||||
|
||||
if(on)
|
||||
icon_state = "psiphon:1"
|
||||
@@ -39,7 +44,7 @@
|
||||
on = !on
|
||||
|
||||
if(prob(100/severity))
|
||||
direction_out = !direction_out
|
||||
direction = !direction
|
||||
|
||||
target_pressure = rand(0,1300)
|
||||
update_icon()
|
||||
@@ -54,7 +59,7 @@
|
||||
environment = holding.air_contents
|
||||
else
|
||||
environment = loc.return_air()
|
||||
if(direction_out)
|
||||
if(direction == DIRECTION_OUT)
|
||||
var/pressure_delta = target_pressure - environment.return_pressure()
|
||||
//Can not have a pressure delta that would cause environment pressure > tank pressure
|
||||
|
||||
@@ -87,9 +92,7 @@
|
||||
air_update_turf()
|
||||
|
||||
air_contents.merge(removed)
|
||||
//src.update_icon()
|
||||
|
||||
src.updateDialog()
|
||||
return
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/return_air()
|
||||
@@ -102,72 +105,74 @@
|
||||
if(on)
|
||||
on = FALSE
|
||||
update_icon()
|
||||
else if(on && holding && direction_out)
|
||||
else if(on && holding && direction == DIRECTION_OUT)
|
||||
investigate_log("[key_name(user)] started a transfer into [holding].<br>", "atmos")
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/attack_ai(var/mob/user as mob)
|
||||
src.add_hiddenprint(user)
|
||||
return src.attack_hand(user)
|
||||
/obj/machinery/portable_atmospherics/pump/attack_ai(mob/user)
|
||||
add_hiddenprint(user)
|
||||
return attack_hand(user)
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/attack_ghost(var/mob/user as mob)
|
||||
return src.attack_hand(user)
|
||||
/obj/machinery/portable_atmospherics/pump/attack_ghost(mob/user)
|
||||
return attack_hand(user)
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/attack_hand(var/mob/user as mob)
|
||||
ui_interact(user)
|
||||
/obj/machinery/portable_atmospherics/pump/attack_hand(mob/user)
|
||||
tgui_interact(user)
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = GLOB.physical_state)
|
||||
// update the ui if it exists, returns null if no ui is passed/found
|
||||
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
/obj/machinery/portable_atmospherics/pump/tgui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_default_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, 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, "portpump.tmpl", "Portable Pump", 480, 400, state = state)
|
||||
// open the new ui window
|
||||
ui = new(user, src, ui_key, "PortablePump", "Portable Pump", 434, 377, master_ui, state)
|
||||
ui.open()
|
||||
// auto update every Master Controller tick
|
||||
ui.set_auto_update(1)
|
||||
ui.set_autoupdate(TRUE)
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.physical_state)
|
||||
var/data[0]
|
||||
data["portConnected"] = connected_port ? 1 : 0
|
||||
data["tankPressure"] = round(air_contents.return_pressure() > 0 ? air_contents.return_pressure() : 0)
|
||||
data["targetpressure"] = round(target_pressure)
|
||||
data["pump_dir"] = direction_out
|
||||
data["minpressure"] = round(pressuremin)
|
||||
data["maxpressure"] = round(pressuremax)
|
||||
data["on"] = on ? 1 : 0
|
||||
|
||||
data["hasHoldingTank"] = holding ? 1 : 0
|
||||
/obj/machinery/portable_atmospherics/pump/tgui_data(mob/user)
|
||||
var/list/data = list(
|
||||
"on" = on,
|
||||
"direction" = direction,
|
||||
"port_connected" = connected_port ? TRUE : FALSE,
|
||||
"max_target_pressure" = MAX_TARGET_PRESSURE,
|
||||
"target_pressure" = round(target_pressure, 0.001),
|
||||
"tank_pressure" = air_contents.return_pressure() > 0 ? round(air_contents.return_pressure(), 0.001) : 0
|
||||
)
|
||||
if(holding)
|
||||
data["holdingTank"] = list("name" = holding.name, "tankPressure" = round(holding.air_contents.return_pressure() > 0 ? holding.air_contents.return_pressure() : 0))
|
||||
data["has_holding_tank"] = TRUE
|
||||
data["holding_tank"] = list("name" = holding.name, "tank_pressure" = holding.air_contents.return_pressure() > 0 ? round(holding.air_contents.return_pressure(), 0.001) : 0)
|
||||
else
|
||||
data["has_holding_tank"] = FALSE
|
||||
|
||||
return data
|
||||
|
||||
/obj/machinery/portable_atmospherics/pump/Topic(href, href_list)
|
||||
/obj/machinery/portable_atmospherics/pump/tgui_act(action, list/params)
|
||||
if(..())
|
||||
return 1
|
||||
return
|
||||
|
||||
if(href_list["power"])
|
||||
on = !on
|
||||
if(on && direction_out)
|
||||
investigate_log("[key_name(usr)] started a transfer into [holding].<br>", "atmos")
|
||||
update_icon()
|
||||
switch(action)
|
||||
if("power")
|
||||
on = !on
|
||||
if(on && direction == DIRECTION_OUT)
|
||||
investigate_log("[key_name(usr)] started a transfer into [holding].<br>", "atmos")
|
||||
update_icon()
|
||||
return TRUE
|
||||
|
||||
if(href_list["direction"])
|
||||
direction_out = !direction_out
|
||||
if(on && holding)
|
||||
investigate_log("[key_name(usr)] started a transfer into [holding].<br>", "atmos")
|
||||
if("set_direction")
|
||||
if(text2num(params["direction"]) == DIRECTION_IN)
|
||||
direction = DIRECTION_IN
|
||||
else
|
||||
direction = DIRECTION_OUT
|
||||
if(on && holding)
|
||||
investigate_log("[key_name(usr)] started a transfer into [holding].<br>", "atmos")
|
||||
return TRUE
|
||||
|
||||
if(href_list["remove_tank"])
|
||||
if(holding)
|
||||
on = FALSE
|
||||
holding.loc = loc
|
||||
holding = null
|
||||
update_icon()
|
||||
if("remove_tank")
|
||||
if(holding)
|
||||
on = FALSE
|
||||
holding.forceMove(get_turf(src))
|
||||
holding = null
|
||||
update_icon()
|
||||
return TRUE
|
||||
|
||||
if(href_list["pressure_adj"])
|
||||
var/diff = text2num(href_list["pressure_adj"])
|
||||
target_pressure = clamp(target_pressure+diff, pressuremin, pressuremax)
|
||||
update_icon()
|
||||
if("set_pressure")
|
||||
target_pressure = clamp(text2num(params["pressure"]), 0, MAX_TARGET_PRESSURE)
|
||||
return TRUE
|
||||
|
||||
src.add_fingerprint(usr)
|
||||
add_fingerprint(usr)
|
||||
|
||||
Reference in New Issue
Block a user