fix: Remove viewport clipping from TerritoryLayer putImageData to fix missing territory colors on zoom out#165
Closed
El-Magico777 wants to merge 22 commits intov0.2.0from
Closed
fix: Remove viewport clipping from TerritoryLayer putImageData to fix missing territory colors on zoom out#165El-Magico777 wants to merge 22 commits intov0.2.0from
El-Magico777 wants to merge 22 commits intov0.2.0from
Conversation
- Tweaked research tree UI text and tooltip content (short vs detailed) - Updated tech tooltips with clearer unlock summaries and numbers - Refactored tech effects unlock logic and cleaned definitions
Adds a complete structure stacking system that allows players to build multiple instances of structures in a single tile. Stacking provides: - Increased HP (bonus per stacked instance) - Multiplied functionality (e.g., ×2 city = 2× population cap) STACKING MECHANICS: - Stack count is user-controlled (1-99) via +/- buttons in build menu - Each game starts fresh with stack count reset to 1 - Uses localStorage for in-game UI communication only (cleared on game start) - Stack count shown as ×N prefix in build menu display STACKABLE STRUCTURES (9 total): - City: ×N population cap increase - Port: ×N trade ship supply - Airfield: spawns N bombers - Hospital: ×N healing effect - Academy: ×N combat bonus - Research Lab: ×N research boost - Factory: ×N gold production bonus - Missile Silo: can launch N nukes before cooldown - SAM Launcher: fires N missiles per interception DEFENSE POST: Stacking intentionally disabled (single instance only) IMPLEMENTATION DETAILS: Core data model: - Added _stackCount field to UnitImpl for tracking stacked instances - Added _launchesRemaining field for missile silo multi-launch tracking - Added stackCount() and launchesRemaining() to Unit interface - Added fields to GameUpdates and GameView for client sync Stackable structure definitions (Upgradeables.ts): - Added STACKABLE_STRUCTURES set (9 structure types) - Added TECH_UPGRADEABLE_STRUCTURES set (SAM, Airfield only) - Added helper functions: isStackableStructure(), maxStackCount(), isTechUpgradeableStructure(), maxStructureTechLevel() Construction execution: - ConstructionExecution now separates stackCount from techLevel - Added computeStackCount() and computeTechLevel() methods - Added applyStackingIfNeeded() to set stack count and HP bonuses Structure-specific execution updates: - AirfieldExecution: spawns stackCount bombers, tracks upgrades - SAMLauncherExecution: fires stackCount missiles per interception - MissileSiloExecution: accepts stackCount param, allows N launches before cooldown via launchesRemaining tracking - DefensePostExecution: removed stacking support Client UI: - BuildMenu: shows ×N prefix for stacked structures - ControlPanel2: Stack ×N UI with +/- adjustment buttons - Transport: reads stack count and sends with build intent - LocalPersistantStats: clears stack count settings on game start
…ited SAM/Silo stacking - Fix structure stacking system to properly increment stackCount via setStackCount() - Update playerMaxStructureLevel() to return 99 for all stackable structures (SAM, Silo, Airfield) - Remove legacy cap of 3 from maxStructureLevel() for SAM and Silo - Implement launchesRemaining system for SAM (fire stackCount times before cooldown) - Fix SAM/Silo cooldown calculation to use effectiveMaxHealth() instead of base health - SAM range now uses playerMaxStructureTechLevel() (tech tier 1-3), not stack count - Display stack count instead of level for structure badges - Add SAM tech level as secondary indicator (similar to Airfield bomber level) - PlayerInfoOverlay and BuildMenu now show correct counts including stacked structures - Update unitsOwned() to use stackCount() for all stackable structures - Rename 'Upgrade Structures' button to 'Stack Structures'
…STACK_COUNT=25 and clamp in helpers (maxStackCount, maxStructureLevel, playerMaxStructureLevel)\n- Clamp ConstructionExecution desired stack, UnitImpl.setStackCount\n- Limit client intent payload and schema to 25 (Transport, Schemas)\n- Keeps UI controls honoring cap via shared helpers
- Support multiple simultaneous research priorities (Set-based) - Add category 'Prioritize' button to set all techs in category - Cross-category prioritization: selecting individual tech clears same-level techs from other categories - Category prioritization clears other categories but preserves existing priorities in selected category - Locked prioritized techs show gold background with lock icon - Research allocation: 60% split among available priorities, 40% to others - Priority prerequisites get 60% when priorities locked - Update PlayerView to expose full priorities Set
- Remove ScorchedEarth upgrade and all related code - Delete ScorchedEarthExecution and integration tests - Remove SCORCHED_EARTH from UpgradeType enum - Remove scorchedEarthActivationCost from Config - Remove Insurance system - Remove INSURANCE_REFUND message type - Remove insurance refund logic from UnitImpl - Remove structureInsuranceRefundNum/Den from Config - Remove ECONOMY_INSURANCE tech ID - Remove policy directive system (referenced non-existent Economy-3 tech) - Delete PolicyDirectiveSelectExecution, MarkPolicyDirectivesSeenExecution - Delete PolicyDirectives.ts definition file - Remove policy schemas, intents, handlers from Transport/ExecutionManager - Remove policy methods from Player interface and PlayerImpl - Remove policy logic from all TechEffects modifier functions - Remove policy notification from ResearchToggleButton - Move InternationalTrade upgrade to Land-1 tech (Road Network) - Remove unused tech IDs: ECONOMY_INTERNATIONAL_TRADE, ECONOMY_TBD_LEVEL4, TRADE_POLICY_FRAMEWORK - Remove unused upgrade types: WaterUpgrade1/2/3, AirUpgrade3, EconomyUpgrade1/2/3 All tests passing (46 suites, 276 tests)
The paratrooper option was not appearing in the radial menu even when Air-1 tech was researched and airfield was in range. Root cause: Both RadialMenu.shouldShowAirAttack() and ParatrooperAttackExecution.init() were checking for obsolete UpgradeType.AirUpgrade1 instead of UpgradeType.JetEngines. The Air-1 Early Air Power tech grants UpgradeType.JetEngines, not AirUpgrade1, so the check was always failing. Changed both files to check for JetEngines upgrade, which is the correct requirement for paratroopers. All tests pass (46 suites, 276 tests).
…mbing by default
BREAKING CHANGE: Auto-bombing is now enabled by default for all players
Changes:
- PlayerImpl: Changed _autoBombingEnabled default from false to true
* All players now have auto-bombing active by default
* Can still be overridden via radial menu manual targeting
- RadialMenu: Added bomber targeting action (Slot.Bomber)
* Shows airfield icon when right-clicking enemy land tiles
* Gating: requires airfield, land tile, enemy ownership, war status
* Range validation: checks bomber level and config range from all airfields
* Targets all structure types (City, DefensePost, SAMLauncher, etc.)
* Uses preferClosest=true for optimal targeting priority
* Icon: airfield icon (matches build menu consistency)
- BomberExecution: Fixed manual to auto fallback logic
* When manual targets exhausted, now clears bomberIntent via setBomberIntent(null)
* Ensures seamless switch back to auto-bombing mode
* Previously would get stuck when findTargetFromQueue returned null
- ControlPanel2: Completely removed Bombers tab
* Deleted tab UI rendering (button and content panel ~200 lines)
* Removed all bomber-specific state variables
* Removed bomber methods: _startAutoBombing, _stopAutoBombing,
_handleBomberTargetChange, populateBomberForm, _refreshBomberPlayerLists,
_getPlayersInAirfieldRange
* Removed bomber-related updated() hook logic
* Removed Bombers from activeTab type union and _changeTab signature
* Cleaned up residual references (comments, dead code)
* Kept sendBomberIntent() for radial integration
- UI/UX Improvements:
* Unified bomber control via radial menu (right-click context)
* Removed toggle complexity from control panel
* Airfield icon provides visual consistency with build menu
* Auto-bombing ensures bombers always active when at war
All tests pass (46 suites, 276 tests). TypeScript and ESLint clean.
Previously, disabled radial menu options were completely greyed out with a generic disabled icon, making it impossible to understand what options were available or why they were unavailable. Now there are three distinct visual states: 1. Active (unlocked and in range): Full color, full opacity, clickable 2. Out of range (unlocked but too far): Darkened version of the feature's color (preserves hue), 0.7 opacity 3. Not unlocked (feature not researched): Black and white (no color set), 0.7 opacity Changes: - Replaced swap-to-grey-icon with darkenColor() helper that preserves original hue when a color is set - When no color is set (not unlocked), uses dark grey fallback for black-and-white appearance - Increased disabled opacity from 0.5 to 0.7 for better icon visibility - Icons always remain visible (boat, airAttack, bomber, info, ally, peace icons set as defaults) - Removed unused disabledIcon import Result: Players can now see all radial menu options and understand their status at a glance - full color means ready to use, colored but dark means out of range, black and white means not yet unlocked.
- NameLayer: add war (sword) and neutral (dove) icons above player names, reusing diplomacy assets - Color: render war icon via CSS mask using SwordIcon.svg with exact warColor (#8B0000) to match radial menu; neutral uses existing dove image - Self-filter: hide alliance/war/neutral icons for the local player’s own name - Overlay: remove relation icons from PlayerInfoOverlay; show text-only relation (Allied/Neutral/Hostile) for clarity Rationale: - Provide consistent visual indicators for neutral and at-war states where only allied icon existed - Ensure color parity with radial menu (darker red for war) and avoid yellow tint - Reduce clutter by not showing diplomacy icons for self and keeping the overlay textual Notes: - Assets used: resources/images/SwordIcon.svg (masked to #8B0000), proprietary/images/dove.png; alliance remains resources/images/AllianceIcon.svg - No server or core changes; client-only UI update
- Remove Diplomacy from tab list and type definitions - Stub out renderDiplomacyTab method (now returns empty template) - Remove all Diplomacy tab UI code and event handlers Rationale: - Diplomacy relations are now displayed via NameLayer icons (allied/war/neutral) - No need for separate tab UI when visual indicators are on the map - Simplifies control panel and reduces clutter Changes: - Removed 'Diplomacy' from activeTab type union - Removed Diplomacy tab button from UI - Removed 180+ lines of diplomacy tab render logic - Kept method signature for compatibility but returns empty html
- War icon now 20% smaller for better visual balance - Use exact #8B0000 color via CSS mask (matches radial menu war button) - Only show diplomacy icons for Human/FakeHuman players (not regular bots) - Removed icon resize loop that caused flickering Changes: - NameLayer: war icon sized at 0.8x, uses CSS mask with #8B0000 - Added PlayerType check: isHumanOrFakeHuman filter for alliance/war/neutral icons - Import PlayerType from Game.ts for type checking - Simplified icon creation - stable sizing without constant updates
**Changes:**
1. **Removed Trade Tab**
- Eliminated separate Trade tab from Command Center UI
- Removed trade ship listing, construction queue, and embargo management UI
- Removed _renderTradeTab(), _computeTradeShipStatus(), embargo handlers
- Cleaned up associated Help Modal documentation
2. **Trade Demand Indicator Migration**
- Moved Trade Demand indicator to Build tab horizontal toolbar
- Now displays alongside Multi-Build and Stack Mode controls
- Compact design: ship icon + label + demand level (Very High/High/Medium/Low/Very Low)
- Hidden when player has no ports (not yet trading-enabled)
- Shows 'No Ships' state when no trade ships exist
3. **Trade Demand Calculation Fix**
- **Before:** Compared player's queue vs ALL players' ships globally (always showed 'Low')
- **After:** Compares player's queue vs ONLY their own ships (actually meaningful)
- New thresholds:
- Very High (red): queue > 2× ship count need ships urgently
- High (orange): queue > ship count could use more ships
- Medium (white): balanced capacity
- Low (green): 50%+ ships idle surplus capacity
- Very Low (blue): no routes waiting, ships available oversupply
4. **Tooltip Flicker Prevention**
- Added 2-second tooltip cache to prevent rapid re-renders
- Tooltip shows detailed stats: '15 routes waiting, 3/10 ships available'
- Cache only updates when actual values change (queue length, ship counts)
- Static tooltip positioning with pointer-events stabilization
5. **Build Menu Grid Redesign**
- Converted from flex rows to CSS Grid (4 columns × 3 rows)
- Reduced button height to 44px (from 50px) for denser layout
- Eliminated scrollbars - all 11 items fit in viewport
- Stack badges repositioned to top-right corner (blue badge: ×2, ×3, etc.)
- Icon sizing standardized to 24×24px
- Count badges moved to right side inline with layout
6. **Build Tab Toolbar Enhancement**
- Horizontal toolbar with consistent styling across Build/Attack tabs
- Multi-Build button: toggle mass-placement mode
- Stack Mode button: toggle structure stacking mode
- Stack control widget: compact +/- buttons with numeric display
- Trade Demand indicator: right-aligned in toolbar with spacer
- All controls use unified toolbar button styling (11px font, 4px padding)
7. **Architecture Notes**
- Trade Demand driven by cities (max population boost), territory, InternationalTrade upgrade
- Factories do NOT affect trade demand (only industrial production)
- Stacked cities count via effectiveUnits() (level 3 city = 3× effective units)
- Trade queue filled via gravity model: K × IP_A × IP_B / distance / world_IP
**Why:**
- Simplified UI - removed underutilized Trade tab
- Trade Demand now visible during building phase (Build tab) when most relevant
- Fixed misleading indicator that compared against global ship pool
- Players get actionable feedback: 'High' demand = build more ships
- Consistent toolbar UI pattern across all Command Center tabs
- Denser, scrollbar-free Build menu improves UX
… missing territory colors on zoom out ## Problem Territory colors were not rendering correctly when zooming out. Areas of the map that were outside the initial viewport would appear blank/transparent even though they had proper ownership data. This issue became more frequent and noticeable as users zoomed out to view larger portions of the map. ## Root Cause Introduced in commit 8361640 (Dec 9, 2025) as part of a dirty rect optimization. The renderLayer method was clipping the putImageData call to only update the intersection of: - The dirty rect (tiles that changed) - The visible viewport (what's currently on screen) This optimization prevented off-screen areas from being written to the canvas. While the ImageData buffer contained correct color information for all tiles, the canvas element only received updates for tiles within the viewport at the time they were painted. When users zoomed out, previously off-screen areas would become visible, but since putImageData was never called for those regions, the canvas still had blank/uninitialized data there. ## Solution Removed the viewport intersection logic from the putImageData call. Now the full dirty rect is applied to the canvas without viewport clipping: Before: \\\ ypescript // Intersect dirty rect with visible viewport const vx0 = Math.max(0, topLeft.x, this.dirtyRect.x0); const vy0 = Math.max(0, topLeft.y, this.dirtyRect.y0); \\\ After: \\\ ypescript // Apply the dirty rect directly without viewport clipping const x0 = Math.max(0, this.dirtyRect.x0); const y0 = Math.max(0, this.dirtyRect.y0); \\\ This ensures the canvas stays in sync with ImageData for all painted tiles, regardless of viewport position. The performance impact is minimal because: - We still use dirty rect tracking (only updating changed areas) - Modern browsers optimize putImageData efficiently - The final drawImage call already renders the full canvas ## Testing Verify by: 1. Starting a new game 2. Zooming out to view large portions of the map 3. All territory colors should now render correctly without blank areas
21 tasks
El-Magico777
added a commit
that referenced
this pull request
Dec 18, 2025
…ata to fix missing territory colors on zoom out
Collaborator
Author
|
merged in #169 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build on top of #158, #159, #160, #161 and #164!
Description:
Problem
Territory colors were not rendering correctly when zooming out. Areas of the map that were outside the initial viewport would appear blank/transparent even though they had proper ownership data. This issue became more frequent and noticeable as users zoomed out to view larger portions of the map.
Root Cause
Introduced in commit 8361640 (Dec 9, 2025) as part of a dirty rect optimization. The renderLayer method was clipping the putImageData call to only update the intersection of:
This optimization prevented off-screen areas from being written to the canvas. While the ImageData buffer contained correct color information for all tiles, the canvas element only received updates for tiles within the viewport at the time they were painted.
When users zoomed out, previously off-screen areas would become visible, but since putImageData was never called for those regions, the canvas still had blank/uninitialized data there.
Solution
Removed the viewport intersection logic from the putImageData call. Now the full dirty rect is applied to the canvas without viewport clipping:
Before:
\\ ypescript
// Intersect dirty rect with visible viewport
const vx0 = Math.max(0, topLeft.x, this.dirtyRect.x0);
const vy0 = Math.max(0, topLeft.y, this.dirtyRect.y0);
\\
After:
\\ ypescript
// Apply the dirty rect directly without viewport clipping
const x0 = Math.max(0, this.dirtyRect.x0);
const y0 = Math.max(0, this.dirtyRect.y0);
\\
This ensures the canvas stays in sync with ImageData for all painted tiles, regardless of viewport position. The performance impact is minimal because:
Testing
Verify by:
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
el_magico777