Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[Port] Crew monitoring console sorting" #11476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tgui/packages/tgui/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const COLORS = {
science: '#9b59b6',
engineering: '#f1c40f',
cargo: '#f39c12',
service: '#7cc46a',
centcom: '#00c100',
other: '#c38312',
},
Expand Down
139 changes: 139 additions & 0 deletions tgui/packages/tgui/interfaces/CrewConsole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { useBackend } from '../backend';
import { Box, Button, ColorBox, Section, Table } from '../components';
import { COLORS } from '../constants';
import { Window } from '../layouts';
import { sortBy } from 'common/collections';

export const HEALTH_COLOR_BY_LEVEL = ['#17d568', '#2ecc71', '#e67e22', '#ed5100', '#e74c3c', '#ed2814'];

export const jobIsHead = (jobId) => jobId % 10 === 0;

export const jobToColor = (jobId) => {
if (jobId >= 0 && jobId < 10) {
return COLORS.department.captain;
}
if (jobId >= 10 && jobId < 20) {
return COLORS.department.security;
}
if (jobId >= 20 && jobId < 30) {
return COLORS.department.medbay;
}
if (jobId >= 30 && jobId < 40) {
return COLORS.department.science;
}
if (jobId >= 40 && jobId < 50) {
return COLORS.department.engineering;
}
if (jobId >= 50 && jobId < 60) {
return COLORS.department.cargo;
}
if (jobId >= 200 && jobId < 230) {
return COLORS.department.centcom;
}
if (jobId === -1) {
return null;
}
return COLORS.department.other;
};

export const healthToColor = (oxy, tox, burn, brute) => {
const healthSum = oxy + tox + burn + brute;
const level = Math.min(Math.max(Math.ceil(healthSum / 25), 0), 5);
return HEALTH_COLOR_BY_LEVEL[level];
};

export const HealthStat = (props) => {
const { type, value } = props;
return (
<Box inline width={2} color={COLORS.damageType[type]} textAlign="center">
{value}
</Box>
);
};

export const CrewConsole = () => {
return (
<Window width={800} height={600}>
<Window.Content scrollable>
<Section minHeight="540px">
<CrewTable />
</Section>
</Window.Content>
</Window>
);
};

const CrewTable = (props, context) => {
const { act, data } = useBackend(context);
const sensors = sortBy((s) => s.ijob)(data.sensors ?? []);
return (
<Table>
<Table.Row>
<Table.Cell bold>Name</Table.Cell>
<Table.Cell bold collapsing />
<Table.Cell bold collapsing textAlign="center">
Vitals
</Table.Cell>
<Table.Cell bold>Position</Table.Cell>
{!!data.link_allowed && (
<Table.Cell bold collapsing>
Tracking
</Table.Cell>
)}
</Table.Row>
{sensors.map((sensor) => (
<CrewTableEntry sensor_data={sensor} key={sensor.ref} />
))}
</Table>
);
};

const CrewTableEntry = (props, context) => {
const { act, data } = useBackend(context);
const { link_allowed } = data;
const { sensor_data } = props;
const { name, assignment, ijob, life_status, oxydam, toxdam, burndam, brutedam, area, can_track } = sensor_data;

return (
<Table.Row>
<Table.Cell bold={jobIsHead(ijob)} color={jobToColor(ijob)}>
{name}
{assignment !== undefined ? ` (${assignment})` : ''}
</Table.Cell>
<Table.Cell collapsing textAlign="center">
{life_status ? <ColorBox color={healthToColor(oxydam, toxdam, burndam, brutedam)} /> : <ColorBox color={'#ed2814'} />}
</Table.Cell>
<Table.Cell collapsing textAlign="center">
{oxydam !== undefined ? (
<Box inline>
<HealthStat type="oxy" value={oxydam} />
{'/'}
<HealthStat type="toxin" value={toxdam} />
{'/'}
<HealthStat type="burn" value={burndam} />
{'/'}
<HealthStat type="brute" value={brutedam} />
</Box>
) : life_status ? (
'Alive'
) : (
'Dead'
)}
</Table.Cell>
<Table.Cell>{area !== undefined ? area : 'N/A'}</Table.Cell>
{!!link_allowed && (
<Table.Cell collapsing>
<Button
content="Track"
disabled={!can_track}
onClick={() =>
act('select_person', {
name: name,
})
}
/>
</Table.Cell>
)}
</Table.Row>
);
};
Loading
Loading