feat(app): add character location tracking and display
This commit is contained in:
@@ -8,7 +8,7 @@ import { loadWormholeSystems, saveWormholeSystem, deleteWormholeSystem } from '@
|
||||
import { System, Position, Connection as ConnectionType } from '@/lib/types';
|
||||
import { getSecurityColor } from '@/utils/securityColors';
|
||||
import { Header } from './Header';
|
||||
import { ListCharacters, StartESILogin, SetDestinationForAll, PostRouteForAllByNames } from 'wailsjs/go/main/App';
|
||||
import { ListCharacters, StartESILogin, SetDestinationForAll, PostRouteForAllByNames, GetCharacterLocations } from 'wailsjs/go/main/App';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { getSystemsRegions } from '@/utils/systemApi';
|
||||
|
||||
@@ -97,6 +97,7 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
type OffIndicator = { from: string; toRegion: string; count: number; color: string; angle: number; sampleTo?: string };
|
||||
const [offRegionIndicators, setOffRegionIndicators] = useState<OffIndicator[]>([]);
|
||||
const [meanInboundAngle, setMeanInboundAngle] = useState<Record<string, number>>({});
|
||||
const [charLocs, setCharLocs] = useState<Array<{ character_id: number; character_name: string; solar_system_name: string }>>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = async (e: KeyboardEvent) => {
|
||||
@@ -154,6 +155,24 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
setMeanInboundAngle(angleMap);
|
||||
}, [systems]);
|
||||
|
||||
// Poll character locations every 7s and store those in this region
|
||||
useEffect(() => {
|
||||
let timer: any;
|
||||
const tick = async () => {
|
||||
try {
|
||||
const locs = await GetCharacterLocations();
|
||||
const here = locs.filter(l => !!l.solar_system_name && systems.has(l.solar_system_name));
|
||||
setCharLocs(here.map(l => ({ character_id: l.character_id, character_name: l.character_name, solar_system_name: l.solar_system_name })));
|
||||
} catch (_) {
|
||||
// ignore
|
||||
} finally {
|
||||
timer = setTimeout(tick, 7000);
|
||||
}
|
||||
};
|
||||
tick();
|
||||
return () => { if (timer) clearTimeout(timer); };
|
||||
}, [systems]);
|
||||
|
||||
// Compute off-region indicators: dedupe per (from, toRegion), compute avg color, and angle via universe centroids
|
||||
useEffect(() => {
|
||||
const computeOffRegion = async () => {
|
||||
@@ -644,6 +663,19 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Character location markers */}
|
||||
{charLocs.map((c, idx) => {
|
||||
const pos = positions[c.solar_system_name];
|
||||
if (!pos) return null;
|
||||
const yoff = -18 - (idx % 3) * 10; // stagger small vertical offsets if multiple in same system
|
||||
return (
|
||||
<g key={`char-${c.character_id}-${idx}`} transform={`translate(${pos.x}, ${pos.y + yoff})`}>
|
||||
<circle r={4} fill="#00d1ff" stroke="#ffffff" strokeWidth={1} />
|
||||
<text x={6} y={3} fontSize={8} fill="#ffffff">{c.character_name}</text>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* Off-region indicators: labeled arrows pointing toward the destination region */}
|
||||
{offRegionIndicators.map((ind, idx) => {
|
||||
const pos = positions[ind.from];
|
||||
|
2
frontend/wailsjs/go/main/App.d.ts
vendored
2
frontend/wailsjs/go/main/App.d.ts
vendored
@@ -8,6 +8,8 @@ export function ESILoggedIn():Promise<boolean>;
|
||||
|
||||
export function ESILoginStatus():Promise<string>;
|
||||
|
||||
export function GetCharacterLocations():Promise<Array<main.CharacterLocation>>;
|
||||
|
||||
export function Greet(arg1:string):Promise<string>;
|
||||
|
||||
export function ListCharacters():Promise<Array<main.CharacterInfo>>;
|
||||
|
@@ -14,6 +14,10 @@ export function ESILoginStatus() {
|
||||
return window['go']['main']['App']['ESILoginStatus']();
|
||||
}
|
||||
|
||||
export function GetCharacterLocations() {
|
||||
return window['go']['main']['App']['GetCharacterLocations']();
|
||||
}
|
||||
|
||||
export function Greet(arg1) {
|
||||
return window['go']['main']['App']['Greet'](arg1);
|
||||
}
|
||||
|
@@ -14,6 +14,45 @@ export namespace main {
|
||||
this.character_name = source["character_name"];
|
||||
}
|
||||
}
|
||||
export class CharacterLocation {
|
||||
character_id: number;
|
||||
character_name: string;
|
||||
solar_system_id: number;
|
||||
solar_system_name: string;
|
||||
// Go type: time
|
||||
retrieved_at: any;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new CharacterLocation(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.character_id = source["character_id"];
|
||||
this.character_name = source["character_name"];
|
||||
this.solar_system_id = source["solar_system_id"];
|
||||
this.solar_system_name = source["solar_system_name"];
|
||||
this.retrieved_at = this.convertValues(source["retrieved_at"], null);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user