From 49bd6008930a9d997406d5d6ce63db9bd99830cf Mon Sep 17 00:00:00 2001 From: PaulMullen Date: Tue, 28 May 2024 08:10:39 +0100 Subject: [PATCH] added rank sorting for marines --- tgui/packages/tgui/interfaces/Orbit/index.tsx | 33 ++++++++++++++++--- tgui/packages/tgui/interfaces/Orbit/types.ts | 3 ++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/tgui/packages/tgui/interfaces/Orbit/index.tsx b/tgui/packages/tgui/interfaces/Orbit/index.tsx index 00dcfcd7a1c2..bc440e733939 100644 --- a/tgui/packages/tgui/interfaces/Orbit/index.tsx +++ b/tgui/packages/tgui/interfaces/Orbit/index.tsx @@ -23,9 +23,10 @@ import { } from './helpers'; import { buildSquadObservable, + groupSorter, type Observable, type OrbitData, - SquadObservable, + splitter, } from './types'; type search = { @@ -107,7 +108,7 @@ const ObservableSearch = () => { color={auto_observe ? 'good' : 'transparent'} icon={auto_observe ? 'toggle-on' : 'toggle-off'} onClick={() => act('toggle_auto_observe')} - tooltip={`Toggle Full Observe. When active, you'll see the UI / full inventory of whoever you're orbiting. Neat!`} + tooltip={`Toggle Full Observe. When active, you'll see the UI / full inventory of whoever you're orbiting.`} tooltipPosition="bottom-start" /> @@ -178,11 +179,31 @@ const marineSplitter = (members: Array) => { return squads; }; +const rankList = [ + 'Rifleman', + 'Spotter', + 'Hospital Corpsman', + 'Combat Technician', + 'Smartgunner', + 'Weapons Specialist', + 'Fireteam Leader', + 'Squad Leader', +]; +const marineSort = (a: Observable, b: Observable) => { + const a_index = rankList.findIndex((str) => a.job?.includes(str)) ?? 0; + const b_index = rankList.findIndex((str) => b.job?.includes(str)) ?? 0; + if (a_index === b_index) { + return a.full_name.localeCompare(b.full_name); + } + return a_index > b_index ? -1 : 1; +}; + const GroupedObservable = (props: { readonly color?: string; readonly section: Array; readonly title: string; - readonly splitter: (members: Array) => Array; + readonly splitter: splitter; + readonly sorter?: groupSorter; }) => { const { color, section = [], title } = props; @@ -219,7 +240,7 @@ const GroupedObservable = (props: { ))} @@ -269,6 +290,7 @@ const ObservableContent = () => { section={marines} title="Marines" splitter={marineSplitter} + sorter={marineSort} /> {displayHealth && } + {!!icon && ( + + )} {capitalizeFirst(getDisplayName(full_name, nickname))} {!!orbiters && ( <> diff --git a/tgui/packages/tgui/interfaces/Orbit/types.ts b/tgui/packages/tgui/interfaces/Orbit/types.ts index 5dab18dfb30a..8318a91f1c89 100644 --- a/tgui/packages/tgui/interfaces/Orbit/types.ts +++ b/tgui/packages/tgui/interfaces/Orbit/types.ts @@ -57,3 +57,6 @@ export const buildSquadObservable: ( title: title, }; }; + +export type splitter = (members: Array) => Array; +export type groupSorter = (a: Observable, b: Observable) => number;