tgui pump

This commit is contained in:
SteelSlayer
2020-09-18 12:22:19 -05:00
parent 6d72554dd6
commit 9c5a8a1235
3 changed files with 288 additions and 68 deletions
+71 -66
View File
@@ -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)
@@ -0,0 +1,215 @@
import { useBackend } from "../backend";
import { Button, Section, LabeledList, Slider, Box, ProgressBar, Flex } from "../components";
import { Window } from "../layouts";
export const PortablePump = (props, context) => {
const { act, data } = useBackend(context);
const { has_holding_tank } = data;
return (
<Window resizable>
<Window.Content>
<PumpSettings />
<PressureSettings />
{has_holding_tank ? (
<HoldingTank />
) : (
<Section title="Holding Tank">
<Box color="average" bold={1}>
No Holding Tank Inserted.
</Box>
</Section>
)}
</Window.Content>
</Window>
);
};
const PumpSettings = (props, context) => {
const { act, data } = useBackend(context);
const {
on,
direction,
port_connected,
} = data;
return (
<Section title="Pump Settings">
<LabeledList>
<LabeledList.Item label="Power">
<Button
icon={on ? "power-off" : "power-off"}
content={on ? "On" : "Off"}
color={on ? null : "red"}
selected={on}
onClick={() => act('power')} />
</LabeledList.Item>
<LabeledList.Item label="Pump Direction">
<Box
mt={0.5}
mb={1}>
<Button
icon="sign-in-alt"
content="In"
selected={!direction}
width={3.75}
onClick={() => act('set_direction', {
direction: 0,
})} />
<Button
icon="sign-out-alt"
content="Out"
selected={direction}
onClick={() => act('set_direction', {
direction: 1,
})} />
</Box>
</LabeledList.Item>
<LabeledList.Item label="Port status">
<Box
color={port_connected ? "green" : "average"}
bold={1}>
{port_connected ? "Connected" : "Disconnected"}
</Box>
</LabeledList.Item>
</LabeledList>
</Section>
);
};
const PressureSettings = (props, context) => {
const { act, data } = useBackend(context);
const {
tank_pressure,
target_pressure,
max_target_pressure,
} = data;
const average_pressure = max_target_pressure * 0.70;
const bad_pressure = max_target_pressure * 0.25;
return (
<Section title="Pressure Settings">
<LabeledList>
<LabeledList.Item label="Stored pressure">
<ProgressBar
value={tank_pressure}
minValue={0}
maxValue={max_target_pressure}
ranges={{
good: [average_pressure, Infinity],
average: [bad_pressure, average_pressure],
bad: [-Infinity, bad_pressure],
}}>
{tank_pressure} kPa
</ProgressBar>
</LabeledList.Item>
</LabeledList>
<Flex mt={2}>
<Flex.Item
mt={0.4}
grow={1}
color="label">
Target pressure:
</Flex.Item>
<Flex.Item>
<Button
icon="undo"
mr={0.5}
width={2.2}
textAlign="center"
onClick={() => act('set_pressure', {
pressure: 101.325,
})} />
<Button
icon="fast-backward"
mr={0.5}
width={2.2}
textAlign="center"
onClick={() => act('set_pressure', {
pressure: 0,
})} />
</Flex.Item>
<Flex.Item>
<Slider
animated
unit="kPa"
width={17.3}
stepPixelSize={0.22}
minValue={0}
maxValue={max_target_pressure}
value={target_pressure}
onChange={(e, value) => act('set_pressure', {
pressure: value,
})} />
</Flex.Item>
<Flex.Item>
<Button
icon="fast-forward"
ml={0.5}
width={2.2}
textAlign="center"
onClick={() => act('set_pressure', {
pressure: max_target_pressure,
})} />
</Flex.Item>
</Flex>
</Section>
);
};
const HoldingTank = (props, context) => {
const { act, data } = useBackend(context);
const {
holding_tank,
max_target_pressure,
} = data;
const average_pressure = max_target_pressure * 0.70;
const bad_pressure = max_target_pressure * 0.25;
return (
<Section
title="Holding Tank"
buttons={
<Button
onClick={() => act('remove_tank')}
icon="eject">
Eject
</Button>
}>
<Flex>
<Flex.Item
color="label"
mr={7.2}
mb={2.2}>
Tank Label:
</Flex.Item>
<Flex.Item mb={1} color="silver">
{holding_tank.name}
</Flex.Item>
</Flex>
<Flex>
<Flex.Item
color="label"
mt={0.5}
mr={3.8}>
Tank Pressure:
</Flex.Item>
<Flex.Item grow={1}>
<ProgressBar
value={holding_tank.tank_pressure}
minValue={0}
maxValue={max_target_pressure}
ranges={{
good: [average_pressure, Infinity],
average: [bad_pressure, average_pressure],
bad: [-Infinity, bad_pressure],
}}>
{holding_tank.tank_pressure} kPa
</ProgressBar>
</Flex.Item>
</Flex>
</Section>
);
};
File diff suppressed because one or more lines are too long