Skip to content

Add combat development sandboxes and fix rendering defensive code#32

Merged
Linkatplug merged 17 commits intocopilot/refactor-defensesystem-damagefrom
copilot/make-draw-enemy-resistance-proof
Feb 14, 2026
Merged

Add combat development sandboxes and fix rendering defensive code#32
Linkatplug merged 17 commits intocopilot/refactor-defensesystem-damagefrom
copilot/make-draw-enemy-resistance-proof

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

Problem

Created professional combat testing environments and hardened rendering code against missing data:

  1. RenderSystem crash: drawEnemyResistanceIndicator accessed undefined baseResistances properties
  2. Debug log spam: CollisionSystem flooded console with per-frame DEBUG logs
  3. No combat sandbox: Needed isolated testing environment without waves/UI/audio

Changes

Defensive rendering (RenderSystem.js)

// Before: direct access crashes on missing fields
defense.shield.baseResistances[type]

// After: safe fallback chain
const layerData = defense[layerName];
const baseRes = layerData.baseResistances || layerData.resistances || {};
const bonusRes = layerData.bonusResistances || {};
const base = baseRes[type] || 0;
const bonus = bonusRes[type] || 0;

Debug log gating (CollisionSystem.js)

  • Added COLLISION_DEBUG = false flag at file top
  • Wrapped all 21 debug logs in if (COLLISION_DEBUG) conditionals
  • Console clean by default, debugging available via flag toggle

Combat sandboxes (dev/)

Created three testing environments:

test-combat-sandbox.html - Manual system instantiation

  • World + individual systems (no Game class)
  • Full control over update loop and spawning

combat-sandbox-clean.html - Pure manual architecture

  • No Game class, manual World/systems/player creation
  • Explicit system.update() calls in custom loop

combat-sandbox.html - Game class override (recommended)

const game = new Game();
game.startGame();

// Override update to run only combat systems
game.update = function(deltaTime) {
    deltaTime = Math.min(deltaTime, 0.1);
    
    this.systems.movement.update(deltaTime);
    this.systems.ai.update(deltaTime);
    this.systems.combat.update(deltaTime);
    this.systems.defense.update(deltaTime);
    this.systems.collision.update(deltaTime);
    
    this.world.processPendingRemovals();
};

Benefits of override approach:

  • Uses real Game systems/world/player (identical behavior to main game)
  • No core file modifications
  • WaveSystem/WeatherSystem/UISystem don't run (not called in override)
  • Manual spawn controls via game.systems.spawner.spawnEnemy()

Supporting fixes

  • Enemy firing cadence audit (already cooldown-gated, no changes needed)
  • DefenseSystem wiring: world.defenseSystem = systems.defense
  • GameState instantiation with minimal stats object
  • Enemy spawn positions clamped to canvas bounds
  • deltaTime clamping: Math.min(deltaTime, 0.1) prevents teleporting

Architecture decisions

Sandbox approach: Override game.update() rather than disable individual systems

  • Cleaner: single override point vs nullifying multiple system methods
  • Safer: systems remain intact, just not called
  • Maintainable: clear what runs vs what doesn't

No core modifications: All sandbox logic contained in dev/*.html files

  • Game.js, all systems, data files unchanged
  • Main game (index.html) continues working identically
  • Sandboxes can be deleted without affecting production code

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Linkatplug Linkatplug marked this pull request as ready for review February 14, 2026 19:26
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix drawEnemyResistanceIndicator for missing resistance fields Prevent crashes in drawEnemyResistanceIndicator from undefined resistance fields Feb 14, 2026
Copilot AI requested a review from Linkatplug February 14, 2026 19:30
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Prevent crashes in drawEnemyResistanceIndicator from undefined resistance fields Gate collision debug logs behind COLLISION_DEBUG flag Feb 14, 2026
Copilot AI changed the title Gate collision debug logs behind COLLISION_DEBUG flag Audit enemy firing cadence - confirm cooldown-based rate limiting Feb 14, 2026
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Audit enemy firing cadence - confirm cooldown-based rate limiting Add Combat Dev Sandbox for isolated combat testing Feb 14, 2026
Copilot AI changed the title Add Combat Dev Sandbox for isolated combat testing Fix entity removal in Combat Dev Sandbox game loop Feb 14, 2026
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Defensive rendering, debug gating, and isolated combat sandbox Harden production systems and add isolated combat sandbox Feb 14, 2026
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Harden production systems and add isolated combat sandbox Harden systems against undefined data and add isolated combat sandbox Feb 14, 2026
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Harden systems against undefined data and add isolated combat sandbox Harden defense rendering, gate debug spam, add isolated combat sandbox Feb 14, 2026
Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Harden defense rendering, gate debug spam, add isolated combat sandbox Make defense rendering resilient, gate debug logs, create combat dev sandboxes Feb 14, 2026
… combat sandbox

Co-authored-by: Linkatplug <36280686+Linkatplug@users.noreply.github.com>
Copilot AI changed the title Make defense rendering resilient, gate debug logs, create combat dev sandboxes Add combat development sandboxes and fix rendering resilience Feb 14, 2026
Copilot AI changed the title Add combat development sandboxes and fix rendering resilience Add combat development sandboxes and fix rendering defensive code Feb 14, 2026
@Linkatplug Linkatplug merged commit 8e609e7 into copilot/refactor-defensesystem-damage Feb 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants