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];
|
||||
|
Reference in New Issue
Block a user