mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-30 07:27:57 +01:00
AI TGUI-ing
This commit is contained in:
@@ -37,71 +37,78 @@
|
||||
overlays.Cut()
|
||||
|
||||
/obj/item/aicard/attack_self(mob/user)
|
||||
ui_interact(user)
|
||||
tgui_interact(user)
|
||||
|
||||
|
||||
/obj/item/aicard/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = GLOB.inventory_state)
|
||||
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
/obj/item/aicard/tgui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = TRUE, 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, "aicard.tmpl", "[name]", 600, 400, state = state)
|
||||
ui = new(user, src, ui_key, "AICard", "[name]", 600, 394, master_ui, state)
|
||||
ui.open()
|
||||
ui.set_auto_update(1)
|
||||
|
||||
|
||||
/obj/item/aicard/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.inventory_state)
|
||||
/obj/item/aicard/tgui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.inventory_state)
|
||||
var/data[0]
|
||||
|
||||
var/mob/living/silicon/ai/AI = locate() in src
|
||||
if(istype(AI))
|
||||
data["has_ai"] = 1
|
||||
data["has_ai"] = TRUE
|
||||
data["name"] = AI.name
|
||||
data["hardware_integrity"] = ((AI.health + 100) / 2)
|
||||
data["integrity"] = ((AI.health + 100) / 2)
|
||||
data["radio"] = !AI.aiRadio.disabledAi
|
||||
data["wireless"] = !AI.control_disabled
|
||||
data["operational"] = AI.stat != DEAD
|
||||
data["flushing"] = flush
|
||||
|
||||
var/laws[0]
|
||||
for(var/datum/ai_law/AL in AI.laws.all_laws())
|
||||
laws[++laws.len] = list("index" = AL.get_index(), "law" = sanitize(AL.law))
|
||||
for(var/datum/ai_law/law in AI.laws.all_laws())
|
||||
if(law in AI.laws.ion_laws) // If we're an ion law, give it an ion index code
|
||||
laws.Add(ionnum() + ". " + law.law)
|
||||
else
|
||||
laws.Add(num2text(law.get_index()) + ". " + law.law)
|
||||
data["laws"] = laws
|
||||
data["has_laws"] = laws.len
|
||||
data["has_laws"] = length(AI.laws.all_laws())
|
||||
|
||||
else
|
||||
data["has_ai"] = FALSE // If this isn't passed to tgui, it won't show there isn't a AI in the card.
|
||||
|
||||
return data
|
||||
|
||||
|
||||
/obj/item/aicard/Topic(href, href_list, nowindow, state)
|
||||
/obj/item/aicard/tgui_act(action, params)
|
||||
if(..())
|
||||
return 1
|
||||
return
|
||||
|
||||
var/mob/living/silicon/ai/AI = locate() in src
|
||||
if(!istype(AI))
|
||||
return 1
|
||||
return
|
||||
|
||||
var/user = usr
|
||||
|
||||
if(href_list["wipe"])
|
||||
var/confirm = alert("Are you sure you want to wipe this card's memory? This cannot be undone once started.", "Confirm Wipe", "Yes", "No")
|
||||
if(confirm == "Yes" && (CanUseTopic(user, state) == STATUS_INTERACTIVE))
|
||||
switch(action)
|
||||
if("wipe")
|
||||
msg_admin_attack("[key_name_admin(user)] wiped [key_name_admin(AI)] with \the [src].", ATKLOG_FEW)
|
||||
add_attack_logs(user, AI, "Wiped with [src].")
|
||||
flush = 1
|
||||
AI.suiciding = 1
|
||||
to_chat(AI, "Your core files are being wiped!")
|
||||
while(AI && AI.stat != DEAD)
|
||||
AI.adjustOxyLoss(2)
|
||||
sleep(10)
|
||||
flush = 0
|
||||
INVOKE_ASYNC(src, .proc/wipe_ai)
|
||||
|
||||
if(href_list["radio"])
|
||||
AI.aiRadio.disabledAi = text2num(href_list["radio"])
|
||||
to_chat(AI, "<span class='warning'>Your Subspace Transceiver has been [AI.aiRadio.disabledAi ? "disabled" : "enabled"]!</span>")
|
||||
to_chat(user, "<span class='notice'>You [AI.aiRadio.disabledAi ? "disable" : "enable"] the AI's Subspace Transceiver.</span>")
|
||||
if("radio")
|
||||
AI.aiRadio.disabledAi = !AI.aiRadio.disabledAi
|
||||
to_chat(AI, "<span class='warning'>Your Subspace Transceiver has been [AI.aiRadio.disabledAi ? "disabled" : "enabled"]!</span>")
|
||||
to_chat(user, "<span class='notice'>You [AI.aiRadio.disabledAi ? "disable" : "enable"] the AI's Subspace Transceiver.</span>")
|
||||
|
||||
if(href_list["wireless"])
|
||||
AI.control_disabled = text2num(href_list["wireless"])
|
||||
to_chat(AI, "<span class='warning'>Your wireless interface has been [AI.control_disabled ? "disabled" : "enabled"]!</span>")
|
||||
to_chat(user, "<span class='notice'>You [AI.control_disabled ? "disable" : "enable"] the AI's wireless interface.</span>")
|
||||
update_icon()
|
||||
if("wireless")
|
||||
AI.control_disabled = !AI.control_disabled
|
||||
to_chat(AI, "<span class='warning'>Your wireless interface has been [AI.control_disabled ? "disabled" : "enabled"]!</span>")
|
||||
to_chat(user, "<span class='notice'>You [AI.control_disabled ? "disable" : "enable"] the AI's wireless interface.</span>")
|
||||
update_icon()
|
||||
|
||||
return 1
|
||||
return TRUE
|
||||
|
||||
/obj/item/aicard/proc/wipe_ai()
|
||||
var/mob/living/silicon/ai/AI = locate() in src
|
||||
flush = TRUE
|
||||
AI.suiciding = TRUE
|
||||
to_chat(AI, "Your core files are being wiped!")
|
||||
while(AI && AI.stat != DEAD)
|
||||
AI.adjustOxyLoss(2)
|
||||
sleep(10)
|
||||
flush = FALSE
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { useBackend } from "../backend";
|
||||
import { Button, ProgressBar, LabeledList, Box, Section } from "../components";
|
||||
import { Window } from "../layouts";
|
||||
|
||||
export const AICard = (props, context) => {
|
||||
const { act, data } = useBackend(context);
|
||||
if (data.has_ai === 0) {
|
||||
return (
|
||||
<Window>
|
||||
<Window.Content>
|
||||
<Section title="Stored AI">
|
||||
<Box>
|
||||
<h3>No AI detected.</h3>
|
||||
</Box>
|
||||
</Section>
|
||||
</Window.Content>
|
||||
</Window>
|
||||
);
|
||||
} else {
|
||||
|
||||
let integrityColor = null; // Handles changing color of the integrity bar
|
||||
if (data.integrity >= 75) { integrityColor = 'green'; }
|
||||
else if (data.integrity >= 25) { integrityColor = 'yellow'; }
|
||||
else { integrityColor = 'red'; }
|
||||
|
||||
return (
|
||||
<Window resizable scrollable>
|
||||
<Window.Content>
|
||||
<Section title="Stored AI">
|
||||
<Box bold display="inline-block">
|
||||
<h3>{data.name}</h3>
|
||||
</Box>
|
||||
<Box>
|
||||
<LabeledList>
|
||||
<LabeledList.Item label="Integrity">
|
||||
<ProgressBar
|
||||
color={integrityColor}
|
||||
value={data.integrity/100} />
|
||||
</LabeledList.Item>
|
||||
</LabeledList>
|
||||
</Box>
|
||||
<Box color="red">
|
||||
<h2>{data.flushing === 1 ? "Wipe of AI in progress..." : ""}</h2>
|
||||
</Box> {/* Can't use true above because of the character limit*/}
|
||||
</Section>
|
||||
|
||||
<Section title="Laws">
|
||||
<Box>
|
||||
{data.laws.map((value, key) => (
|
||||
<Box key={key} display="inline-block">
|
||||
{value}
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
</Section>
|
||||
|
||||
<Section title="Actions">
|
||||
<LabeledList>
|
||||
<LabeledList.Item label="Wireless Activity">
|
||||
<Button
|
||||
icon={data.wireless ? "check" : "times"}
|
||||
content={data.wireless ? "Enabled" : "Disabled"}
|
||||
color={data.wireless ? "green" : "red"}
|
||||
onClick={() => act("wireless")} />
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Subspace Transceiver">
|
||||
<Button
|
||||
icon={data.radio ? "check" : "times"}
|
||||
content={data.radio ? "Enabled" : "Disabled"}
|
||||
color={data.radio ? "green" : "red"}
|
||||
onClick={() => act("radio")} />
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Wipe">
|
||||
<Button.Confirm
|
||||
icon="trash-alt"
|
||||
confirmIcon="trash-alt"
|
||||
disabled={data.flushing || data.integrity === 0}
|
||||
confirmColor="red"
|
||||
content="Wipe AI"
|
||||
onClick={() => act("wipe")} />
|
||||
</LabeledList.Item>
|
||||
</LabeledList>
|
||||
</Section>
|
||||
</Window.Content>
|
||||
</Window>
|
||||
);
|
||||
}
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user