Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"files": "Dockerfile",
"options": {
"plugins": []
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
}
],
Expand Down
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@swc/core": "^1.13.3",
"@swc/jest": "^0.2.39",
"@total-typescript/ts-reset": "^0.6.1",

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.

💡 Verification agent

🧩 Analysis chain

Wire up ts-reset early or via tsconfig types.

@total-typescript/ts-reset only works if imported first or added to tsconfig "types".

Run:


🏁 Script executed:

#!/bin/bash
# Option A: direct import at app entry (should be first import)
rg -nP '^\s*import\s+["\']@total-typescript/ts-reset["\']' -g '!**/node_modules/**' -C2

# Option B: tsconfig types entry
fd -a tsconfig*.json | xargs -I{} rg -nP '"types"\s*:\s*\[[^\]]*"@total-typescript/ts-reset"[^\]]*\]' {}

Length of output: 68


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== A) Search for any mention of @total-typescript/ts-reset =="
rg -n --hidden --no-ignore -S "@total-typescript/ts-reset" -g '!*node_modules*' || true

echo
echo "== B) Search for import lines that import ts-reset =="
rg -n --hidden --no-ignore -S "import.*@total-typescript/ts-reset" -g '!*node_modules*' -C2 || true

echo
echo "== C) Check tsconfig*.json files for compilerOptions.types =="
files=$(fd -a tsconfig*.json || true)
if [ -z "$files" ]; then
  files=$(find . -type f -name 'tsconfig*.json' 2>/dev/null || true)
fi

if [ -z "$files" ]; then
  echo "No tsconfig*.json files found."
  exit 0
fi

for f in $files; do
  echo
  echo "=== $f ==="
  python - <<PY
import json,sys
f="$f"
try:
    j=json.load(open(f))
except Exception as e:
    print(f"{f}: json parse error: {e}")
    sys.exit(0)
co = j.get("compilerOptions",{}) or {}
types = co.get("types")
if isinstance(types, list) and "@total-typescript/ts-reset" in types:
    print(f"{f}: contains @total-typescript/ts-reset in compilerOptions.types")
else:
    print(f"{f}: does NOT contain @total-typescript/ts-reset")
ext = j.get("extends")
if ext:
    print(f"{f}: extends -> {ext}")
PY
done

Length of output: 825


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== SEARCH: any mention of @total-typescript/ts-reset =="
rg -n --hidden --no-ignore -S "@total-typescript/ts-reset" --glob '!**/node_modules/**' --glob '!.git/**' || echo "No matches found."

echo
echo "== SEARCH: direct import or require lines =="
rg -n --hidden --no-ignore -S "^\s*(import\s+['\"]@total-typescript/ts-reset['\"]|require\(['\"]@total-typescript/ts-reset['\"]\))" --glob '!**/node_modules/**' --glob '!.git/**' -C2 || echo "No direct import/require found."

echo
echo "== FIND: tsconfig*.json files =="
tsfiles=$(find . -type f -name 'tsconfig*.json' -print 2>/dev/null || true)
if [ -z "$tsfiles" ]; then
  echo "No tsconfig*.json files found."
  exit 0
fi

for f in $tsfiles; do
  echo
  echo "=== $f ==="
  echo "--- head (first 200 lines) ---"
  sed -n '1,200p' "$f" || true
  echo "--- contains literal @total-typescript/ts-reset? ---"
  rg -n "@total-typescript/ts-reset" "$f" || echo "not found"
  echo "--- types array (if any) ---"
  rg -n '"types"\s*:\s*\[[^\]]*\]' "$f" -n -C1 || echo "no types array found"
done

Length of output: 1843


Wire up @total-typescript/ts-reset — import first or add to tsconfig types

  • Observed: no import of "@total-typescript/ts-reset" in the repo; tsconfig.json (root) has no "types"; tsconfig.jest.json has "types": ["jest","node"] and extends ./tsconfig.json.
  • Action (pick one):
    • Import it as the very first runtime import in your app entry (e.g. add at top of src/index.ts or src/main.ts): import '@total-typescript/ts-reset';
    • Or add "@total-typescript/ts-reset" to compilerOptions.types in tsconfig.json — and also add it to tsconfig.jest.json (it currently overrides types), or remove the override so the base applies.
  • Files to change: tsconfig.json, tsconfig.jest.json, and your app entry file.
🤖 Prompt for AI Agents
In package.json around line 35, the repo added the dependency
"@total-typescript/ts-reset" but it's not wired in; either import it as the
first runtime import in your app entry (e.g., add import
'@total-typescript/ts-reset'; at the very top of src/index.ts or src/main.ts) or
register it in TypeScript config by adding "@total-typescript/ts-reset" to
compilerOptions.types in tsconfig.json and also ensure tsconfig.jest.json either
includes that type or stops overriding types (or add it there as well); update
tsconfig.json, tsconfig.jest.json, and the app entry file accordingly so the
reset is applied at runtime or compile-time.

"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"@types/benchmark": "^2.1.5",
"@types/chai": "^4.3.17",
"@types/d3": "^7.4.3",
Expand Down
4 changes: 3 additions & 1 deletion src/client/graphics/GameRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { PlayerPanel } from "./layers/PlayerPanel";
import { RailroadLayer } from "./layers/RailroadLayer";
import { RedrawGraphicsEvent } from "../InputHandler";
import { ReplayPanel } from "./layers/ReplayPanel";
import { SAMRadiusLayer } from "./layers/SAMRadiusLayer";
import { SettingsModal } from "./layers/SettingsModal";
import { SpawnAd } from "./layers/SpawnAd";
import { SpawnTimer } from "./layers/SpawnTimer";
Expand Down Expand Up @@ -199,6 +200,7 @@ export function createRenderer(
headsUpMessage.game = game;

const structureLayer = new StructureLayer(game, eventBus, transformHandler);
const samRadiusLayer = new SAMRadiusLayer(game, eventBus, transformHandler);

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

SAMRadiusLayer is never rendered (not added to layers).

You construct samRadiusLayer but don’t include it in layers, so the radius never shows.

Add it just before UILayer so it draws beneath UI but above FX/units as desired:

   new UnitLayer(game, eventBus, transformHandler),
   new FxLayer(game),
+  samRadiusLayer,
   new UILayer(game, eventBus),

If you prefer the radii under units, place it before UnitLayer instead.

Also applies to: 235-245

🤖 Prompt for AI Agents
In src/client/graphics/GameRenderer.ts around line 203 (and similarly for the
block at 235-245), you instantiate samRadiusLayer but never add it to the
renderer layers array so it never gets drawn; insert the samRadiusLayer into the
layers list just before the UILayer creation so it renders beneath UI but above
FX/units (or, if you want radii beneath units, insert it before the UnitLayer
instead). Ensure the layers array/order is updated accordingly and remove any
unused local variable warnings if needed.


const fpsDisplay = document.querySelector("fps-display") as FPSDisplay;
if (!(fpsDisplay instanceof FPSDisplay)) {
Expand Down Expand Up @@ -235,10 +237,10 @@ export function createRenderer(
new TerritoryLayer(game, eventBus, transformHandler, userSettings),
new RailroadLayer(game),
structureLayer,
new StructureIconsLayer(game, eventBus, transformHandler),
new UnitLayer(game, eventBus, transformHandler),
new FxLayer(game),
new UILayer(game, eventBus),
new StructureIconsLayer(game, eventBus, transformHandler),
new NameLayer(game, transformHandler, eventBus),
eventsDisplay,
chatDisplay,
Expand Down
141 changes: 141 additions & 0 deletions src/client/graphics/layers/SAMRadiusLayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import type { GameView, UnitView } from "../../../core/game/GameView";
import type { EventBus } from "../../../core/EventBus";
import { GameUpdateType } from "../../../core/game/GameUpdates";
import { Layer } from "./Layer";
import { TransformHandler } from "../TransformHandler";
import { UnitType } from "../../../core/game/Game";

/**
* Layer responsible for rendering SAM launcher defense radiuses
*/
export class SAMRadiusLayer implements Layer {
private readonly canvas: HTMLCanvasElement;
private readonly context: CanvasRenderingContext2D;
private readonly samLaunchers: Set<number> = new Set(); // Track SAM launcher IDs
private needsRedraw = true;

constructor(
private readonly game: GameView,
private readonly eventBus: EventBus,
private readonly transformHandler: TransformHandler,
) {
this.canvas = document.createElement("canvas");
const ctx = this.canvas.getContext("2d");
if (!ctx) {
throw new Error("2d context not supported");
}
this.context = ctx;
this.canvas.width = this.game.width();
this.canvas.height = this.game.height();
}

init() {
// Listen for game updates to detect SAM launcher changes
this.redraw();
}

shouldTransform(): boolean {
return true;
}

tick() {
// Check for updates to SAM launchers
const updates = this.game.updatesSinceLastTick();
const unitUpdates = updates?.[GameUpdateType.Unit];

if (unitUpdates) {
let hasChanges = false;

for (const update of unitUpdates) {
const unit = this.game.unit(update.id);
if (unit && unit.type() === UnitType.SAMLauncher) {
const wasTracked = this.samLaunchers.has(update.id);
const shouldTrack = unit.isActive();

if (wasTracked && !shouldTrack) {
// SAM was destroyed
this.samLaunchers.delete(update.id);
hasChanges = true;
} else if (!wasTracked && shouldTrack) {
// New SAM was built
this.samLaunchers.add(update.id);
hasChanges = true;
}
}
}

if (hasChanges) {
this.needsRedraw = true;
}
}

// Redraw if transform changed or if we need to redraw
if (this.transformHandler.hasChanged() || this.needsRedraw) {
this.redraw();
this.needsRedraw = false;
}
}

renderLayer(context: CanvasRenderingContext2D) {
context.drawImage(
this.canvas,
-this.game.width() / 2,
-this.game.height() / 2,
this.game.width(),
this.game.height(),
);
}

redraw() {
// Clear the canvas
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

// Get all active SAM launchers
const samLaunchers = this.game.units(UnitType.SAMLauncher).filter((unit) => unit.isActive());

// Update our tracking set
this.samLaunchers.clear();
samLaunchers.forEach((sam) => this.samLaunchers.add(sam.id()));

// Draw radius for each SAM launcher
for (const sam of samLaunchers) {
this.drawSAMRadius(sam);
}
}

private drawSAMRadius(sam: UnitView) {
const samTile = sam.tile();
const centerX = this.game.x(samTile);
const centerY = this.game.y(samTile);
const radius = this.game.config().defaultSamRange(); // 70 pixels

// Set up the drawing style
this.context.save();

// Create a contrasting color that will be visible against any background
// Use a bright, highly visible color with good opacity
this.context.strokeStyle = "rgba(255, 255, 0, 0.9)"; // Bright yellow with high opacity
this.context.fillStyle = "rgba(255, 255, 0, 0.15)"; // Light yellow fill with more visibility
this.context.lineWidth = 3; // Thicker line for better visibility
this.context.setLineDash([8, 4]); // Larger dashed line for better visibility

// Draw the circle
this.context.beginPath();
this.context.arc(centerX, centerY, radius, 0, 2 * Math.PI);

// Fill first (very light), then stroke (more visible)
this.context.fill();
this.context.stroke();

// Also add a secondary inner ring for extra visibility
this.context.strokeStyle = "rgba(255, 255, 0, 0.6)";
this.context.lineWidth = 1;
this.context.setLineDash([4, 4]);

this.context.beginPath();
this.context.arc(centerX, centerY, radius - 5, 0, 2 * Math.PI);
this.context.stroke();

this.context.restore();
}
}