From d7e71fb1d9aa789c1ff81a3893efd9bda29b8f1a Mon Sep 17 00:00:00 2001 From: Kashargul Date: Sat, 21 Sep 2024 20:06:06 +0200 Subject: [PATCH] some component stuff --- code/modules/admin/modify_robot.dm | 13 ++- .../ModifyRobotTabs/ModifyRobotComponent.tsx | 86 +++++++++++++++++-- .../tgui/interfaces/ModifyRobot/types.ts | 8 +- 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/code/modules/admin/modify_robot.dm b/code/modules/admin/modify_robot.dm index 3c1682f40e..1ffcf78be2 100644 --- a/code/modules/admin/modify_robot.dm +++ b/code/modules/admin/modify_robot.dm @@ -84,7 +84,7 @@ .["target"]["availalbe_channels"] = availalbe_channels // Components .["target"]["components"] = get_components() - .["cell"] = target.cell?.name + .["cell"] = list("name" = target.cell?.name, "charge" = target.cell?.charge, "maxcharge" = target.cell?.maxcharge) .["cell_options"] = get_cells() // Access .["id_icon"] = icon2html(target.idcard, user, sourceonly=TRUE) @@ -368,6 +368,17 @@ if(istype(C, /datum/robot_component/cell)) target.cell = null return TRUE + if("adjust_cell_charge") + target.cell.charge = text2num(params["charge"]) + return TRUE + if("adjust_brute") + var/datum/robot_component/C = locate(params["component"]) + C.brute_damage = text2num(params["damage"]) + return TRUE + if("adjust_electronics") + var/datum/robot_component/C = locate(params["component"]) + C.electronics_damage = text2num(params["damage"]) + return TRUE if("add_access") target.idcard.access += text2num(params["access"]) return TRUE diff --git a/tgui/packages/tgui/interfaces/ModifyRobot/ModifyRobotTabs/ModifyRobotComponent.tsx b/tgui/packages/tgui/interfaces/ModifyRobot/ModifyRobotTabs/ModifyRobotComponent.tsx index 4450c6009c..8423630acd 100644 --- a/tgui/packages/tgui/interfaces/ModifyRobot/ModifyRobotTabs/ModifyRobotComponent.tsx +++ b/tgui/packages/tgui/interfaces/ModifyRobot/ModifyRobotTabs/ModifyRobotComponent.tsx @@ -1,9 +1,11 @@ +import { toFixed } from 'common/math'; import { capitalize } from 'common/string'; import { useState } from 'react'; import { useBackend } from 'tgui/backend'; import { Box, Button, + Collapsible, Divider, Dropdown, Flex, @@ -11,24 +13,26 @@ import { Image, Input, Section, + Slider, Stack, } from 'tgui/components'; import { NoSpriteWarning } from '../components'; import { prepareSearch } from '../functions'; -import { Cell, Component, Target } from '../types'; +import { Cell, Component, InstalledCell, Target } from '../types'; export const ModifyRobotComponent = (props: { target: Target; - cell: string | null; + cell: InstalledCell; cells: Record; }) => { + const { act } = useBackend(); const { target, cell, cells } = props; const [searchComponentReplaceText, setSearchComponentReplaceText] = useState(''); const [searchComponentRemoveText, setSearchComponentRemoveText] = useState(''); - const [selectedCell, setSelectedCell] = useState(cell || ''); + const [selectedCell, setSelectedCell] = useState(cell.name || ''); const cell_options = Object.keys(cells) as Array; return ( @@ -46,7 +50,7 @@ export const ModifyRobotComponent = (props: { buttonIcon="arrows-spin" celltype={cells[selectedCell]?.path} selected_cell={selectedCell} - cell={cell || undefined} + cell={cell.name || undefined} /> @@ -65,13 +69,32 @@ export const ModifyRobotComponent = (props: {
Current cell:{' '} - {cell ? ( - capitalize(cell) + {cell.name ? ( + capitalize(cell.name) ) : ( No cell installed! )} + toFixed(value, 2)} + disabled={!cell.charge} + minValue={0} + maxValue={100} + value={((cell.charge || 0) / (cell.maxcharge || 1)) * 100} + onChange={(e, value) => + act('adjust_cell_charge', { + charge: (value / 100) * (cell.maxcharge || 0), + }) + } + > + + Current charge + + {cell.charge} + +
+
+ + {target.components.map((component, i) => { + return ( + + + act('adjust_brute', { + component: component.ref, + damage: value, + }) + } + > + + Brute damage + + {component.brute_damage} + + + + act('adjust_electronics', { + component: component.ref, + damage: value, + }) + } + > + + Electronics damage + + + {component.electronics_damage} + + + + + ); + })} + +
diff --git a/tgui/packages/tgui/interfaces/ModifyRobot/types.ts b/tgui/packages/tgui/interfaces/ModifyRobot/types.ts index 02b840948b..d5bb7aeadf 100644 --- a/tgui/packages/tgui/interfaces/ModifyRobot/types.ts +++ b/tgui/packages/tgui/interfaces/ModifyRobot/types.ts @@ -5,7 +5,7 @@ export type Data = { target: Target | null; all_robots: DropdownEntry[]; model_options: string[] | null; - cell: string | null; + cell: InstalledCell; cell_options: Record; id_icon: string; access_options: Access[] | undefined; @@ -98,6 +98,12 @@ export type PKA = { max_capacity: number; }; +export type InstalledCell = { + name: string | null; + charge: number | null; + maxcharge: number | null; +}; + export type Cell = { path: string; charge: number;