Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/components/game/Minimap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,24 @@
}

// Get entities from render state adapter (worker mode)
const worldAdapter = getRenderStateAdapter();
// CRITICAL: Access globalThis directly to bypass code-split bundle issues
// Each bundle may have its own copy of getRenderStateAdapter() with stale code
const ADAPTER_KEY = '__voidstrike_RenderStateWorldAdapter__';
const worldAdapter = (globalThis as any)[ADAPTER_KEY] ?? getRenderStateAdapter();

// Debug: log adapter state and identity to trace singleton issues
// Debug: log adapter state
const logKey = '_minimapDebugLogged';
const adapterCheckKey = '_minimapAdapterCheckCount';
if (!(window as any)[logKey]) {
// Count checks to avoid spam
(window as any)[adapterCheckKey] = ((window as any)[adapterCheckKey] ?? 0) + 1;
const checkCount = (window as any)[adapterCheckKey];

// Log every 30 frames (about 2 seconds at 15fps) until entities are found
if (checkCount % 30 === 1) {
const counts = worldAdapter.getEntityCounts();
// Check what's on globalThis
const globalKey = '__voidstrike_RenderStateWorldAdapter__';
const globalInstance = (globalThis as any)[globalKey];
console.log('[Minimap] Checking adapter state:', {
isReady: worldAdapter.isReady(),
updateCount: worldAdapter.getUpdateCount(),
const counts = worldAdapter?.getEntityCounts?.() ?? { units: 0, buildings: 0, resources: 0 };
console.log('[Minimap] Adapter state:', {
isReady: worldAdapter?.isReady?.() ?? false,
updateCount: worldAdapter?.getUpdateCount?.() ?? 0,
...counts,
globalThisHasKey: !!globalInstance,
globalThisUpdateCount: globalInstance?.getUpdateCount?.() ?? 'N/A',
sameInstance: worldAdapter === globalInstance,
fromGlobalThis: !!(globalThis as any)[ADAPTER_KEY],
});
}
}
Expand All @@ -196,8 +191,8 @@
}
}
for (const entity of resources) {
const transform = entity.get<{ x: number; y: number }>('Transform');

Check failure on line 194 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.
const resource = entity.get<{ resourceType: string }>('Resource');

Check failure on line 195 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.

if (!transform || !resource) continue;

Expand All @@ -213,10 +208,10 @@
// Draw buildings
const buildings = worldAdapter.getEntitiesWith('Transform', 'Building', 'Selectable', 'Health');
for (const entity of buildings) {
const transform = entity.get<{ x: number; y: number }>('Transform');

Check failure on line 211 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.
const building = entity.get<{ width: number; height: number; state: string; isComplete?: () => boolean }>('Building');

Check failure on line 212 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.
const selectable = entity.get<{ playerId: string }>('Selectable');

Check failure on line 213 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.
const health = entity.get<{ current: number; max: number }>('Health');

Check failure on line 214 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.

if (!transform || !building || !selectable || !health) continue;
if (health.current <= 0) continue;
Expand Down Expand Up @@ -251,9 +246,9 @@
// Draw units
const units = worldAdapter.getEntitiesWith('Transform', 'Unit', 'Selectable', 'Health');
for (const entity of units) {
const transform = entity.get<{ x: number; y: number }>('Transform');

Check failure on line 249 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.
const selectable = entity.get<{ playerId: string }>('Selectable');

Check failure on line 250 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.
const health = entity.get<{ current: number; max: number }>('Health');

Check failure on line 251 in src/components/game/Minimap.tsx

View workflow job for this annotation

GitHub Actions / type-check

Untyped function calls may not accept type arguments.

if (!transform || !selectable || !health) continue;
if (health.current <= 0) continue;
Expand Down Expand Up @@ -368,7 +363,9 @@
if (selectedIds.length === 0) return;

// Check if any selected are units (not buildings) using render state adapter
const worldAdapter = getRenderStateAdapter();
// Access globalThis directly to bypass code-split bundle issues
const ADAPTER_KEY = '__voidstrike_RenderStateWorldAdapter__';
const worldAdapter = (globalThis as any)[ADAPTER_KEY] ?? getRenderStateAdapter();
const hasUnits = selectedIds.some((id) => {
const entity = worldAdapter.getEntity(id);
return entity?.get('Unit') !== undefined;
Expand Down Expand Up @@ -455,7 +452,9 @@
const selectedIds = useGameStore.getState().selectedUnits;
if (selectedIds.length > 0) {
// Check if any selected are units (not buildings) using render state adapter
const worldAdapter = getRenderStateAdapter();
// Access globalThis directly to bypass code-split bundle issues
const ADAPTER_KEY = '__voidstrike_RenderStateWorldAdapter__';
const worldAdapter = (globalThis as any)[ADAPTER_KEY] ?? getRenderStateAdapter();
const hasUnits = selectedIds.some((id) => {
const entity = worldAdapter.getEntity(id);
return entity?.get('Unit') !== undefined;
Expand Down
Loading