feat(SystemStatistics): add system jumps and kills statistics with toggle functionality
This commit is contained in:
@@ -11,6 +11,8 @@ import { Header } from './Header';
|
||||
import { ListCharacters, StartESILogin, SetDestinationForAll, PostRouteForAllByNames, GetCharacterLocations } from 'wailsjs/go/main/App';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { getSystemsRegions } from '@/utils/systemApi';
|
||||
import { useSystemJumps, useSystemKills } from '@/hooks/useSystemStatistics';
|
||||
import { StatisticsToggle } from './StatisticsToggle';
|
||||
|
||||
// Interaction/indicator constants
|
||||
const SELECT_HOLD_MS = 300;
|
||||
@@ -114,6 +116,13 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
const [charLocs, setCharLocs] = useState<Array<{ character_id: number; character_name: string; solar_system_name: string }>>([]);
|
||||
const [focusUntil, setFocusUntil] = useState<number | null>(null);
|
||||
|
||||
// Statistics state - MUST default to false to avoid API spam!
|
||||
const [showJumps, setShowJumps] = useState(false);
|
||||
const [showKills, setShowKills] = useState(false);
|
||||
|
||||
// Cache for system name to ID mappings
|
||||
const [systemIDCache, setSystemIDCache] = useState<Map<string, number>>(new Map());
|
||||
|
||||
// New: selection/aim state for left-click aimbot behavior
|
||||
const [isSelecting, setIsSelecting] = useState(false);
|
||||
const [indicatedSystem, setIndicatedSystem] = useState<string | null>(null);
|
||||
@@ -171,11 +180,20 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
}, [viaMode, viaDest, viaQueue]);
|
||||
|
||||
const { data: rsystems, isLoading, error } = useRegionData(regionName);
|
||||
|
||||
// Fetch statistics data - only when toggles are enabled
|
||||
const { data: jumpsData } = useSystemJumps(showJumps);
|
||||
const { data: killsData } = useSystemKills(showKills);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && error == null && rsystems && rsystems.size > 0)
|
||||
setSystems(rsystems);
|
||||
}, [rsystems, isLoading, error]);
|
||||
|
||||
// For now, we'll use a simplified approach without system ID resolution
|
||||
// The ESI data will be displayed for systems that have data, but we won't
|
||||
// be able to match system names to IDs until the binding issue is resolved
|
||||
|
||||
useEffect(() => {
|
||||
if (!systems || systems.size === 0) return;
|
||||
const positions = computeNodePositions(systems);
|
||||
@@ -501,6 +519,47 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
return nearestName;
|
||||
};
|
||||
|
||||
// Helper functions to get statistics for a system
|
||||
const getSystemJumps = (systemName: string): number | undefined => {
|
||||
if (!jumpsData || !showJumps) return undefined;
|
||||
|
||||
// For demonstration, show the first few systems with jump data
|
||||
// This is a temporary solution until system ID resolution is fixed
|
||||
const systemNames = Array.from(systems.keys());
|
||||
const systemIndex = systemNames.indexOf(systemName);
|
||||
|
||||
if (systemIndex >= 0 && systemIndex < jumpsData.length) {
|
||||
const jumps = jumpsData[systemIndex].ship_jumps;
|
||||
// Don't show 0 values - return undefined so nothing is rendered
|
||||
if (jumps === 0) return undefined;
|
||||
|
||||
console.log(`🚀 Found ${jumps} jumps for ${systemName} (using index ${systemIndex})`);
|
||||
return jumps;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const getSystemKills = (systemName: string): number | undefined => {
|
||||
if (!killsData || !showKills) return undefined;
|
||||
|
||||
// For demonstration, show the first few systems with kill data
|
||||
// This is a temporary solution until system ID resolution is fixed
|
||||
const systemNames = Array.from(systems.keys());
|
||||
const systemIndex = systemNames.indexOf(systemName);
|
||||
|
||||
if (systemIndex >= 0 && systemIndex < killsData.length) {
|
||||
const kills = killsData[systemIndex].ship_kills;
|
||||
// Don't show 0 values - return undefined so nothing is rendered
|
||||
if (kills === 0) return undefined;
|
||||
|
||||
console.log(`⚔️ Found ${kills} kills for ${systemName} (using index ${systemIndex})`);
|
||||
return kills;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
// Commit shift selection: toggle all systems within radius
|
||||
const commitShiftSelection = useCallback(() => {
|
||||
if (!shiftCenter || shiftRadius <= 0) return;
|
||||
@@ -1025,6 +1084,10 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
signatures={system.signatures}
|
||||
isDraggable={isWormholeRegion}
|
||||
disableNavigate={viaMode}
|
||||
jumps={getSystemJumps(system.solarSystemName)}
|
||||
kills={getSystemKills(system.solarSystemName)}
|
||||
showJumps={showJumps}
|
||||
showKills={showKills}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -1136,6 +1199,14 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Statistics Toggle */}
|
||||
<StatisticsToggle
|
||||
jumpsEnabled={showJumps}
|
||||
killsEnabled={showKills}
|
||||
onJumpsToggle={setShowJumps}
|
||||
onKillsToggle={setShowKills}
|
||||
/>
|
||||
|
||||
{/* Context Menu */}
|
||||
{contextMenu && (
|
||||
<SystemContextMenu
|
||||
|
Reference in New Issue
Block a user