Skip to content
Draft
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,18 @@
<build-menu></build-menu>
<win-modal></win-modal>
<game-starting-modal></game-starting-modal>
<!-- Top HUD: mirrors bottom HUD grid layout -->
<div
class="flex flex-col items-end fixed top-0 right-0 min-[1200px]:top-4 min-[1200px]:right-4 z-1000 gap-2"
class="fixed top-0 left-0 w-full z-[1000] flex flex-col pointer-events-none lg:grid lg:grid-cols-[1fr_500px_1fr] lg:items-start min-[1200px]:px-4"
style="
padding-top: env(safe-area-inset-top);
padding-left: env(safe-area-inset-left);
padding-right: env(safe-area-inset-right);
"
>
<game-right-sidebar></game-right-sidebar>
<replay-panel></replay-panel>
<div class="lg:col-start-3 flex flex-col items-end pointer-events-auto">
<game-menu></game-menu>
</div>
</div>
<settings-modal></settings-modal>
<player-panel></player-panel>
Expand All @@ -342,11 +349,8 @@
<alert-frame></alert-frame>
<chat-modal></chat-modal>
<multi-tab-modal></multi-tab-modal>
<game-left-sidebar></game-left-sidebar>
<performance-overlay></performance-overlay>
<player-info-overlay></player-info-overlay>
<leader-board></leader-board>
<team-stats></team-stats>
<heads-up-message></heads-up-message>

<!-- Scripts -->
Expand Down
54 changes: 7 additions & 47 deletions src/client/graphics/GameRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import { DynamicUILayer } from "./layers/DynamicUILayer";
import { EmojiTable } from "./layers/EmojiTable";
import { EventsDisplay } from "./layers/EventsDisplay";
import { FxLayer } from "./layers/FxLayer";
import { GameLeftSidebar } from "./layers/GameLeftSidebar";
import { GameRightSidebar } from "./layers/GameRightSidebar";
import { GameMenu } from "./layers/GameMenu";
import { HeadsUpMessage } from "./layers/HeadsUpMessage";
import { ImmunityTimer } from "./layers/ImmunityTimer";
import { InGamePromo } from "./layers/InGamePromo";
import { Layer } from "./layers/Layer";
import { Leaderboard } from "./layers/Leaderboard";
import { MainRadialMenu } from "./layers/MainRadialMenu";
import { MultiTabModal } from "./layers/MultiTabModal";
import { NameLayer } from "./layers/NameLayer";
Expand All @@ -33,13 +31,11 @@ import { PerformanceOverlay } from "./layers/PerformanceOverlay";
import { PlayerInfoOverlay } from "./layers/PlayerInfoOverlay";
import { PlayerPanel } from "./layers/PlayerPanel";
import { RailroadLayer } from "./layers/RailroadLayer";
import { ReplayPanel } from "./layers/ReplayPanel";
import { SAMRadiusLayer } from "./layers/SAMRadiusLayer";
import { SettingsModal } from "./layers/SettingsModal";
import { SpawnTimer } from "./layers/SpawnTimer";
import { StructureIconsLayer } from "./layers/StructureIconsLayer";
import { StructureLayer } from "./layers/StructureLayer";
import { TeamStats } from "./layers/TeamStats";
import { TerrainLayer } from "./layers/TerrainLayer";
import { TerritoryLayer } from "./layers/TerritoryLayer";
import { UILayer } from "./layers/UILayer";
Expand Down Expand Up @@ -88,28 +84,12 @@ export function createRenderer(
buildMenu.uiState = uiState;
buildMenu.transformHandler = transformHandler;

const leaderboard = document.querySelector("leader-board") as Leaderboard;
if (!leaderboard || !(leaderboard instanceof Leaderboard)) {
console.error("LeaderBoard element not found in the DOM");
const gameMenu = document.querySelector("game-menu") as GameMenu;
if (!gameMenu || !(gameMenu instanceof GameMenu)) {
console.error("GameMenu element not found in the DOM");
}
leaderboard.eventBus = eventBus;
leaderboard.game = game;

const gameLeftSidebar = document.querySelector(
"game-left-sidebar",
) as GameLeftSidebar;
if (!gameLeftSidebar || !(gameLeftSidebar instanceof GameLeftSidebar)) {
console.error("GameLeftSidebar element not found in the DOM");
}
gameLeftSidebar.game = game;
gameLeftSidebar.eventBus = eventBus;

const teamStats = document.querySelector("team-stats") as TeamStats;
if (!teamStats || !(teamStats instanceof TeamStats)) {
console.error("TeamStats element not found in the DOM");
}
teamStats.eventBus = eventBus;
teamStats.game = game;
gameMenu.game = game;
gameMenu.eventBus = eventBus;
Comment on lines +88 to +92
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Stop after failed game-menu lookup to avoid null dereference.

The current guard only logs, but code still assigns gameMenu.game/gameMenu.eventBus. If the element is missing or wrong type, this will throw.

Proposed fix
   const gameMenu = document.querySelector("game-menu") as GameMenu;
   if (!gameMenu || !(gameMenu instanceof GameMenu)) {
-    console.error("GameMenu element not found in the DOM");
+    throw new Error("GameMenu element not found in the DOM");
   }
   gameMenu.game = game;
   gameMenu.eventBus = eventBus;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!gameMenu || !(gameMenu instanceof GameMenu)) {
console.error("GameMenu element not found in the DOM");
}
leaderboard.eventBus = eventBus;
leaderboard.game = game;
const gameLeftSidebar = document.querySelector(
"game-left-sidebar",
) as GameLeftSidebar;
if (!gameLeftSidebar || !(gameLeftSidebar instanceof GameLeftSidebar)) {
console.error("GameLeftSidebar element not found in the DOM");
}
gameLeftSidebar.game = game;
gameLeftSidebar.eventBus = eventBus;
const teamStats = document.querySelector("team-stats") as TeamStats;
if (!teamStats || !(teamStats instanceof TeamStats)) {
console.error("TeamStats element not found in the DOM");
}
teamStats.eventBus = eventBus;
teamStats.game = game;
gameMenu.game = game;
gameMenu.eventBus = eventBus;
const gameMenu = document.querySelector("game-menu") as GameMenu;
if (!gameMenu || !(gameMenu instanceof GameMenu)) {
throw new Error("GameMenu element not found in the DOM");
}
gameMenu.game = game;
gameMenu.eventBus = eventBus;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/graphics/GameRenderer.ts` around lines 88 - 92, The code logs when
the queried gameMenu is missing/wrong type but continues and dereferences it;
update the guard in GameRenderer so after checking "if (!gameMenu || !(gameMenu
instanceof GameMenu))" you exit early (return or throw) to avoid null
dereference instead of just logging, ensuring subsequent assignments to
gameMenu.game and gameMenu.eventBus only run when gameMenu is a valid GameMenu
instance.


const controlPanel = document.querySelector("control-panel") as ControlPanel;
if (!(controlPanel instanceof ControlPanel)) {
Expand Down Expand Up @@ -163,22 +143,6 @@ export function createRenderer(
winModal.eventBus = eventBus;
winModal.game = game;

const replayPanel = document.querySelector("replay-panel") as ReplayPanel;
if (!(replayPanel instanceof ReplayPanel)) {
console.error("replay panel not found");
}
replayPanel.eventBus = eventBus;
replayPanel.game = game;

const gameRightSidebar = document.querySelector(
"game-right-sidebar",
) as GameRightSidebar;
if (!(gameRightSidebar instanceof GameRightSidebar)) {
console.error("Game Right bar not found");
}
gameRightSidebar.game = game;
gameRightSidebar.eventBus = eventBus;

const settingsModal = document.querySelector(
"settings-modal",
) as SettingsModal;
Expand Down Expand Up @@ -304,16 +268,12 @@ export function createRenderer(
),
spawnTimer,
immunityTimer,
leaderboard,
gameLeftSidebar,
gameMenu,
unitDisplay,
gameRightSidebar,
controlPanel,
playerInfo,
winModal,
replayPanel,
settingsModal,
teamStats,
playerPanel,
headsUpMessage,
multiTabModal,
Expand Down
205 changes: 0 additions & 205 deletions src/client/graphics/layers/GameLeftSidebar.ts

This file was deleted.

Loading
Loading