Merge pull request #14604 from variableundefined/tgui-airlock

[TGUI] Airlock Controller -> TGUI, Remove Advanced Airlock Controller
This commit is contained in:
AffectedArc07
2020-10-14 18:18:21 +01:00
committed by GitHub
6 changed files with 115 additions and 191 deletions
@@ -16,61 +16,6 @@
..()
program = new/datum/computer/file/embedded_program/airlock(src)
//Advanced airlock controller for when you want a more versatile airlock controller - useful for turning simple access control rooms into airlocks
/obj/machinery/embedded_controller/radio/airlock/advanced_airlock_controller
name = "Advanced Airlock Controller"
/obj/machinery/embedded_controller/radio/airlock/advanced_airlock_controller/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "advanced_airlock_console.tmpl", name, 470, 290)
ui.open()
ui.set_auto_update(1)
/obj/machinery/embedded_controller/radio/airlock/advanced_airlock_controller/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.default_state)
var/data[0]
data = list(
"chamber_pressure" = round(program.memory["chamber_sensor_pressure"]),
"external_pressure" = round(program.memory["external_sensor_pressure"]),
"internal_pressure" = round(program.memory["internal_sensor_pressure"]),
"processing" = program.memory["processing"],
"purge" = program.memory["purge"],
"secure" = program.memory["secure"]
)
return data
/obj/machinery/embedded_controller/radio/airlock/advanced_airlock_controller/Topic(href, href_list)
if(..())
return 1
usr.set_machine(src)
src.add_fingerprint(usr)
var/clean = 0
switch(href_list["command"]) //anti-HTML-hacking checks
if("cycle_ext")
clean = 1
if("cycle_int")
clean = 1
if("force_ext")
clean = 1
if("force_int")
clean = 1
if("abort")
clean = 1
if("purge")
clean = 1
if("secure")
clean = 1
if(clean)
program.receive_user_command(href_list["command"])
return 1
//Airlock controller for airlock control - most airlocks on the station use this
/obj/machinery/embedded_controller/radio/airlock/airlock_controller
name = "Airlock Controller"
@@ -91,49 +36,34 @@
tag_chamber_sensor = given_tag_chamber_sensor
..()
/obj/machinery/embedded_controller/radio/airlock/airlock_controller/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
/obj/machinery/embedded_controller/radio/airlock/airlock_controller/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)
ui = new(user, src, ui_key, "simple_airlock_console.tmpl", name, 470, 290)
ui = new(user, src, ui_key, "ExternalAirlockController", name, 470, 290, master_ui, state)
ui.open()
ui.set_auto_update(1)
/obj/machinery/embedded_controller/radio/airlock/airlock_controller/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.default_state)
var/data[0]
/obj/machinery/embedded_controller/radio/airlock/airlock_controller/tgui_data(mob/user)
var/list/data = list()
data = list(
"chamber_pressure" = round(program.memory["chamber_sensor_pressure"]),
"exterior_status" = program.memory["exterior_status"],
"interior_status" = program.memory["interior_status"],
"processing" = program.memory["processing"],
)
data["chamber_pressure"] = round(program.memory["chamber_sensor_pressure"])
data["exterior_status"] = program.memory["exterior_status"]
data["interior_status"] = program.memory["interior_status"]
data["processing"] = program.memory["processing"]
return data
/obj/machinery/embedded_controller/radio/airlock/airlock_controller/Topic(href, href_list)
/obj/machinery/embedded_controller/radio/airlock/airlock_controller/tgui_act(action, params)
if(..())
return
usr.set_machine(src)
src.add_fingerprint(usr)
add_fingerprint(usr)
var/clean = 0
switch(href_list["command"]) //anti-HTML-hacking checks
if("cycle_ext")
clean = 1
if("cycle_int")
clean = 1
if("force_ext")
clean = 1
if("force_int")
clean = 1
if("abort")
clean = 1
var/list/allowed_actions = list("cycle_ext", "cycle_int", "force_ext", "force_int", "abort")
if(action in allowed_actions) //anti-HTML-hacking checks
program.receive_user_command(action)
if(clean)
program.receive_user_command(href_list["command"])
return 1
return TRUE
//Access controller for door control - used in virology and the like
@@ -27,18 +27,15 @@
src.updateDialog()
/obj/machinery/embedded_controller/attack_ghost(mob/user as mob)
src.ui_interact(user)
tgui_interact(user)
/obj/machinery/embedded_controller/attack_ai(mob/user as mob)
src.ui_interact(user)
tgui_interact(user)
/obj/machinery/embedded_controller/attack_hand(mob/user as mob)
if(!user.IsAdvancedToolUser())
return 0
src.ui_interact(user)
/obj/machinery/embedded_controller/ui_interact()
return
return FALSE
tgui_interact(user)
/obj/machinery/embedded_controller/radio
icon = 'icons/obj/airlock_machines.dmi'
@@ -1,60 +0,0 @@
<div class="item" style="padding-top: 10px">
<div class="item">
<div class="itemLabel">
External Pressure:
</div>
<div class="itemContent">
{{:helper.displayBar(data.external_pressure, 0, 200, (data.external_pressure < 80 || data.external_pressure > 120) ? 'bad' : (data.external_pressure < 95 || data.external_pressure > 110) ? 'average' : 'good')}}
<div class="statusValue">
{{:helper.smoothRound(data.external_pressure)}} kPa
</div>
</div>
</div>
<div class="item">
<div class="itemLabel">
Chamber Pressure:
</div>
<div class="itemContent">
{{:helper.displayBar(data.chamber_pressure, 0, 200, (data.chamber_pressure < 80 || data.chamber_pressure > 120) ? 'bad' : (data.chamber_pressure < 95 || data.chamber_pressure > 110) ? 'average' : 'good')}}
<div class="statusValue">
{{:helper.smoothRound(data.chamber_pressure)}} kPa
</div>
</div>
</div>
<div class="item">
<div class="itemLabel">
Internal Pressure:
</div>
<div class="itemContent">
{{:helper.displayBar(data.internal_pressure, 0, 200, (data.internal_pressure < 80 || data.internal_pressure > 120) ? 'bad' : (data.internal_pressure < 95 || data.internal_pressure > 110) ? 'average' : 'good')}}
<div class="statusValue">
{{:helper.smoothRound(data.internal_pressure)}} kPa
</div>
</div>
</div>
</div>
<div class="item" style="padding-top: 10px">
<div class="item" style="width: auto; float: left">
<div class="itemContent">
{{:helper.link('Cycle to Exterior', 'arrow-circle-o-left', {'command' : 'cycle_ext'}, data.processing ? 'disabled' : null)}}
{{:helper.link('Cycle to Interior', 'arrow-circle-right', {'command' : 'cycle_int'}, data.processing ? 'disabled' : null)}}
</div>
<div class="itemContent" style="padding-top: 2px">
{{:helper.link('Force exterior door', 'exclamation-triangle', {'command' : 'force_ext'}, null, data.processing ? 'yellowButton' : null)}}
{{:helper.link('Force interior door', 'exclamation-triangle', {'command' : 'force_int'}, null, data.processing ? 'yellowButton' : null)}}
</div>
</div>
<div style="padding-left: 10px; width: 80px; float: left">
<div class="item">
<div class="itemContent" style="padding-bottom: 2px; width: auto">
{{:helper.link('Purge', 'refresh', {'command' : 'purge'}, data.processing ? 'disabled' : null, data.purge ? 'linkOn' : null)}}
</div>
<div class="itemContent" style="width: auto">
{{:helper.link('Secure', data.secure ? 'lock' : 'unlock', {'command' : 'secure'}, data.processing ? 'disabled' : null, data.secure ? 'linkOn' : null)}}
</div>
</div>
</div>
<div class="item" style="padding-top: 10px">
{{:helper.link('Abort', 'ban', {'command' : 'abort'}, data.processing ? null : 'disabled', data.processing ? 'redButton' : null)}}
</div>
</div>
@@ -1,36 +0,0 @@
<div class="item" style="padding-top: 10px">
<div class="item">
<div class="itemLabel">
Chamber Pressure:
</div>
<div class="itemContent">
{{:helper.displayBar(data.chamber_pressure, 0, 200, (data.chamber_pressure < 80) || (data.chamber_pressure > 120) ? 'bad' : (data.chamber_pressure < 95) || (data.chamber_pressure > 110) ? 'average' : 'good')}}
<div class="statusValue">
{{:helper.smoothRound(data.chamber_pressure)}} kPa
</div>
</div>
</div>
</div>
<div class="item" style="padding-top: 10px">
<div class="item">
<div class="itemContent" style="width: 100%">
{{:helper.link('Cycle to Exterior', 'arrow-circle-o-left', {'command' : 'cycle_ext'}, data.processing ? 'disabled' : null)}}
{{:helper.link('Cycle to Interior', 'arrow-circle-right', {'command' : 'cycle_int'}, data.processing ? 'disabled' : null)}}
</div>
<div class="itemContent" style="padding-top: 2px; width: 100%">
{{if data.interior_status.state == "open"}}
{{:helper.link('Force exterior door', 'exclamation-triangle', {'command' : 'force_ext'}, null, 'redButton')}}
{{else}}
{{:helper.link('Force exterior door', 'exclamation-triangle', {'command' : 'force_ext'}, null, data.processing ? 'yellowButton' : null)}}
{{/if}}
{{if data.exterior_status.state == "open"}}
{{:helper.link('Force interior door', 'exclamation-triangle', {'command' : 'force_int'}, null, 'redButton')}}
{{else}}
{{:helper.link('Force interior door', 'exclamation-triangle', {'command' : 'force_int'}, null, data.processing ? 'yellowButton' : null)}}
{{/if}}
</div>
</div>
<div class="item" style="padding-top: 10px; width: 100%">
{{:helper.link('Abort', 'ban', {'command' : 'abort'}, data.processing ? null : 'disabled', data.processing ? 'redButton' : null)}}
</div>
</div>
@@ -0,0 +1,93 @@
import { useBackend } from '../backend';
import { Box, Button, ProgressBar, LabeledList, Section } from '../components';
import { Window } from '../layouts';
// The minimum and maximum value on the progress bar before it overflow.
const MIN_BAR_VALUE = 0;
const MAX_BAR_VALUE = 1013;
/* Definition of pressure threshold. 95 - 110 is considered good. 80 - 95 and 110 - 120 is considered average.
Everything else bad.
*/
const getStatusColor = val => {
let statusColor = 'good';
const BAD_LOWER_THRESHOLD = 80;
const AVG_LOWER_THRESHOLD = 95;
const AVG_UPPER_THRESHOLD = 110;
const BAD_UPPER_THRESHOLD = 120;
if (val < BAD_LOWER_THRESHOLD) {
statusColor = 'bad';
} else if (val < AVG_LOWER_THRESHOLD) {
statusColor = 'average';
} else if (val > AVG_UPPER_THRESHOLD) {
statusColor = 'average';
} else if (val > BAD_UPPER_THRESHOLD) {
statusColor = 'bad';
}
return statusColor;
};
export const ExternalAirlockController = (props, context) => {
const { act, data } = useBackend(context);
const {
chamber_pressure,
exterior_status,
interior_status,
processing,
} = data;
return (
<Window>
<Window.Content>
<Section title="Information">
<LabeledList>
<LabeledList.Item label="Chamber Pressure">
<ProgressBar
color={getStatusColor(chamber_pressure)}
value={chamber_pressure}
minValue={MIN_BAR_VALUE}
maxValue={MAX_BAR_VALUE}>
{chamber_pressure} kPa
</ProgressBar>
</LabeledList.Item>
</LabeledList>
</Section>
<Section title="Actions">
<Box>
<Button
content={"Cycle to Exterior"}
icon={"arrow-circle-left"}
disabled={processing}
onClick={() => act("cycle_ext")} />
<Button
content={"Cycle to Interior"}
icon={"arrow-circle-right"}
disabled={processing}
onClick={() => act("cycle_int")} />
</Box>
<Box>
<Button
content={"Force Exterior Door"}
icon={"exclamation-triangle"}
color={interior_status === "open" ? "red" : processing ? "yellow": null}
onClick={() => act("force_ext")} />
<Button
content={"Force Interior Door"}
icon={"exclamation-triangle"}
color={interior_status === "open" ? "red" : processing ? "yellow": null}
onClick={() => act("force_int")} />
</Box>
<Box>
<Button
content={"Abort"}
icon={"ban"}
color={"red"}
disabled={!processing}
onClick={() => act("abort")} />
</Box>
</Section>
</Window.Content>
</Window>
);
};
File diff suppressed because one or more lines are too long