From 3ba84da40a05eeab6c066ec323fae6f99696f899 Mon Sep 17 00:00:00 2001
From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com>
Date: Wed, 11 Sep 2024 22:13:00 +0100
Subject: [PATCH] Revert "[Port] Crew monitoring console sorting (#11363)"
This reverts commit 7429631f4bab55e54e24e055bf3b960549462378.
---
tgui/packages/tgui/constants.js | 1 -
tgui/packages/tgui/interfaces/CrewConsole.js | 139 ++++++++++
tgui/packages/tgui/interfaces/CrewConsole.tsx | 258 ------------------
3 files changed, 139 insertions(+), 259 deletions(-)
create mode 100644 tgui/packages/tgui/interfaces/CrewConsole.js
delete mode 100644 tgui/packages/tgui/interfaces/CrewConsole.tsx
diff --git a/tgui/packages/tgui/constants.js b/tgui/packages/tgui/constants.js
index 182bcd0634c7a..4caf607c13261 100644
--- a/tgui/packages/tgui/constants.js
+++ b/tgui/packages/tgui/constants.js
@@ -20,7 +20,6 @@ export const COLORS = {
science: '#9b59b6',
engineering: '#f1c40f',
cargo: '#f39c12',
- service: '#7cc46a',
centcom: '#00c100',
other: '#c38312',
},
diff --git a/tgui/packages/tgui/interfaces/CrewConsole.js b/tgui/packages/tgui/interfaces/CrewConsole.js
new file mode 100644
index 0000000000000..bf72fad4e327a
--- /dev/null
+++ b/tgui/packages/tgui/interfaces/CrewConsole.js
@@ -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 (
+
+ {value}
+
+ );
+};
+
+export const CrewConsole = () => {
+ return (
+
+
+
+
+
+ );
+};
+
+const CrewTable = (props, context) => {
+ const { act, data } = useBackend(context);
+ const sensors = sortBy((s) => s.ijob)(data.sensors ?? []);
+ return (
+
+
+ Name
+
+
+ Vitals
+
+ Position
+ {!!data.link_allowed && (
+
+ Tracking
+
+ )}
+
+ {sensors.map((sensor) => (
+
+ ))}
+
+ );
+};
+
+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 (
+
+
+ {name}
+ {assignment !== undefined ? ` (${assignment})` : ''}
+
+
+ {life_status ? : }
+
+
+ {oxydam !== undefined ? (
+
+
+ {'/'}
+
+ {'/'}
+
+ {'/'}
+
+
+ ) : life_status ? (
+ 'Alive'
+ ) : (
+ 'Dead'
+ )}
+
+ {area !== undefined ? area : 'N/A'}
+ {!!link_allowed && (
+
+
+ )}
+
+ );
+};
diff --git a/tgui/packages/tgui/interfaces/CrewConsole.tsx b/tgui/packages/tgui/interfaces/CrewConsole.tsx
deleted file mode 100644
index 192eac007d4f6..0000000000000
--- a/tgui/packages/tgui/interfaces/CrewConsole.tsx
+++ /dev/null
@@ -1,258 +0,0 @@
-import { Box, Button, Icon, Input, Section, Table } from '../components';
-import { BooleanLike } from 'common/react';
-import { createSearch } from 'common/string';
-import { useBackend, useLocalState } from '../backend';
-import { COLORS } from '../constants';
-import { Window } from '../layouts';
-
-const HEALTH_COLOR_BY_LEVEL = ['#17d568', '#c4cf2d', '#e67e22', '#ed5100', '#e74c3c', '#801308'];
-
-const SORT_NAMES = {
- ijob: 'Job',
- name: 'Name',
- area: 'Position',
- health: 'Vitals',
-};
-
-const STAT_LIVING = 0;
-const STAT_DEAD = 4;
-
-const SORT_OPTIONS = ['health', 'ijob', 'name', 'area'];
-
-const jobIsHead = (jobId: number) => jobId % 10 === 0;
-
-const jobToColor = (jobId: number) => {
- if (jobId === 0) {
- 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 >= 60 && jobId < 200) {
- return COLORS.department.service;
- }
- if (jobId >= 200 && jobId < 230) {
- return COLORS.department.centcom;
- }
- return COLORS.department.other;
-};
-
-const statToIcon = (life_status: number) => {
- switch (life_status) {
- case STAT_LIVING:
- return 'heart';
- case STAT_DEAD:
- return 'skull';
- }
- return 'heartbeat';
-};
-
-const healthSort = (a: CrewSensor, b: CrewSensor) => {
- if (a.life_status > b.life_status) return -1;
- if (a.life_status < b.life_status) return 1;
- if (a.health < b.health) return -1;
- if (a.health > b.health) return 1;
- return 0;
-};
-
-const areaSort = (a: CrewSensor, b: CrewSensor) => {
- a.area ??= '~';
- b.area ??= '~';
- if (a.area < b.area) return -1;
- if (a.area > b.area) return 1;
- return 0;
-};
-
-const healthToAttribute = (oxy: number, tox: number, burn: number, brute: number, attributeList: string[]) => {
- const healthSum = oxy + tox + burn + brute;
- const level = Math.min(Math.max(Math.ceil(healthSum / 25), 0), 5);
- return attributeList[level];
-};
-
-type HealthStatProps = {
- type: string;
- value: number;
-};
-
-const HealthStat = (props: HealthStatProps) => {
- const { type, value } = props;
- return (
-
- {value}
-
- );
-};
-
-export const CrewConsole = () => {
- return (
-
-
-
-
-
- );
-};
-
-type CrewSensor = {
- name: string;
- assignment: string | undefined;
- ijob: number;
- life_status: number;
- oxydam: number;
- toxdam: number;
- burndam: number;
- brutedam: number;
- area: string | undefined;
- health: number;
- can_track: BooleanLike;
- ref: string;
-};
-
-type CrewConsoleData = {
- sensors: CrewSensor[];
- link_allowed: BooleanLike;
-};
-
-const CrewTable = (props, context) => {
- const { data } = useBackend(context);
- const { sensors } = data;
-
- const [sortAsc, setSortAsc] = useLocalState(context, 'sortAsc', true);
- const [searchQuery, setSearchQuery] = useLocalState(context, 'searchQuery', '');
- const [sortBy, setSortBy] = useLocalState(context, 'sortBy', SORT_OPTIONS[0]);
-
- const cycleSortBy = () => {
- let idx = SORT_OPTIONS.indexOf(sortBy) + 1;
- if (idx === SORT_OPTIONS.length) idx = 0;
- setSortBy(SORT_OPTIONS[idx]);
- };
-
- const nameSearch = createSearch(searchQuery, (crew: CrewSensor) => crew.name);
-
- const sorted = sensors.filter(nameSearch).sort((a, b) => {
- switch (sortBy) {
- case 'name':
- return sortAsc ? +(a.name > b.name) : +(b.name > a.name);
- case 'ijob':
- return sortAsc ? a.ijob - b.ijob : b.ijob - a.ijob;
- case 'health':
- return sortAsc ? healthSort(a, b) : healthSort(b, a);
- case 'area':
- return sortAsc ? areaSort(a, b) : areaSort(b, a);
- default:
- return 0;
- }
- });
-
- return (
-
- );
-};
-
-type CrewTableEntryProps = {
- sensor_data: CrewSensor;
-};
-
-const CrewTableEntry = (props: CrewTableEntryProps, 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 (
-
-
- {name}
- {assignment !== undefined ? ` (${assignment})` : ''}
-
-
- {oxydam !== undefined ? (
-
- ) : life_status !== STAT_DEAD ? (
-
- ) : (
-
- )}
-
-
- {oxydam !== undefined ? (
-
-
- {'/'}
-
- {'/'}
-
- {'/'}
-
-
- ) : life_status !== STAT_DEAD ? (
- 'Alive'
- ) : (
- 'Dead'
- )}
-
- {area !== '~' && area !== undefined ? area : }
- {!!link_allowed && (
-
-
-
- )}
-
- );
-};