diff --git a/js/plugins/MinimapZoom.js b/js/plugins/MinimapZoom.js index cbbf6dc..6a48cdf 100644 --- a/js/plugins/MinimapZoom.js +++ b/js/plugins/MinimapZoom.js @@ -57,6 +57,9 @@ // Exit location data let exitLocations = []; + // Fog of war - exploration tracking + const EXPLORE_RADIUS = 5; // Tiles revealed around player + // Export minimap state for other plugins/systems to check window.isMinimapActive = function() { return minimapActive; @@ -96,6 +99,85 @@ _Game_Event_start.call(this); }; + //========================================================================= + // Exploration Tracking - Fog of War System + //========================================================================= + + // Initialize exploration data on Game_System + const _Game_System_initialize = Game_System.prototype.initialize; + Game_System.prototype.initialize = function() { + _Game_System_initialize.call(this); + this._exploredMaps = {}; + }; + + // Get explored tiles for current map + Game_System.prototype.getExploredTiles = function(mapId) { + if (!this._exploredMaps) { + this._exploredMaps = {}; + } + if (!this._exploredMaps[mapId]) { + this._exploredMaps[mapId] = {}; + } + return this._exploredMaps[mapId]; + }; + + // Mark a tile as explored + Game_System.prototype.exploreTile = function(mapId, x, y) { + const explored = this.getExploredTiles(mapId); + const key = x + ',' + y; + explored[key] = true; + }; + + // Check if a tile is explored + Game_System.prototype.isTileExplored = function(mapId, x, y) { + const explored = this.getExploredTiles(mapId); + const key = x + ',' + y; + return explored[key] === true; + }; + + // Reveal tiles around a position + Game_System.prototype.revealAroundPosition = function(mapId, centerX, centerY, radius) { + for (let dx = -radius; dx <= radius; dx++) { + for (let dy = -radius; dy <= radius; dy++) { + // Use circular radius + if (dx * dx + dy * dy <= radius * radius) { + const x = centerX + dx; + const y = centerY + dy; + if (x >= 0 && y >= 0 && x < $gameMap.width() && y < $gameMap.height()) { + this.exploreTile(mapId, x, y); + } + } + } + } + }; + + // Track player movement to reveal tiles + const _Game_Player_moveStraight = Game_Player.prototype.moveStraight; + Game_Player.prototype.moveStraight = function(d) { + _Game_Player_moveStraight.call(this, d); + if (this.isMovementSucceeded()) { + $gameSystem.revealAroundPosition($gameMap.mapId(), this.x, this.y, EXPLORE_RADIUS); + } + }; + + // Also reveal on map setup (when entering a new map or loading) + const _Game_Player_performTransfer = Game_Player.prototype.performTransfer; + Game_Player.prototype.performTransfer = function() { + _Game_Player_performTransfer.call(this); + if ($gameMap.mapId() > 0) { + $gameSystem.revealAroundPosition($gameMap.mapId(), this.x, this.y, EXPLORE_RADIUS); + } + }; + + // Reveal on game load as well + const _Scene_Map_start = Scene_Map.prototype.start; + Scene_Map.prototype.start = function() { + _Scene_Map_start.call(this); + if ($gameMap.mapId() > 0) { + $gameSystem.revealAroundPosition($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y, EXPLORE_RADIUS); + } + }; + //========================================================================= // Scene_Map - Handle minimap toggle //========================================================================= @@ -140,11 +222,17 @@ Scene_Map.prototype.collectExitLocations = function() { exitLocations = []; const rawExits = []; + const mapId = $gameMap.mapId(); - // Collect all transfer events + // Collect all transfer events (only from explored areas) for (const event of $gameMap.events()) { if (!event) continue; + // Only include exits in explored areas + if (!$gameSystem.isTileExplored(mapId, event.x, event.y)) { + continue; + } + const eventData = event.event(); if (!eventData) continue; @@ -995,6 +1083,11 @@ for (const event of $gameMap.events()) { if (!event) continue; + // Only show markers in explored areas + if (!$gameSystem.isTileExplored($gameMap.mapId(), event.x, event.y)) { + continue; + } + const ex = event.x * tileWidth + tileWidth / 2; const ey = event.y * tileHeight + tileHeight / 2; const ctx = bitmap.context; @@ -1029,6 +1122,48 @@ ctx.stroke(); } } + + // Draw fog of war over unexplored areas + this.drawFogOfWar(bitmap, mapWidth, mapHeight, tileWidth, tileHeight); + }; + + Scene_Map.prototype.drawFogOfWar = function(bitmap, mapWidth, mapHeight, tileWidth, tileHeight) { + const ctx = bitmap.context; + const mapId = $gameMap.mapId(); + + for (let y = 0; y < mapHeight; y++) { + for (let x = 0; x < mapWidth; x++) { + if (!$gameSystem.isTileExplored(mapId, x, y)) { + const px = x * tileWidth; + const py = y * tileHeight; + + // Draw dark fog + ctx.fillStyle = '#0a0806'; + ctx.fillRect(px, py, tileWidth, tileHeight); + + // Add some texture/noise to the fog + if ((x + y) % 3 === 0) { + ctx.fillStyle = 'rgba(20, 15, 10, 0.5)'; + ctx.fillRect(px, py, tileWidth, tileHeight); + } + } else { + // Check for partially explored edges (adjacent to unexplored) + const hasUnexploredNeighbor = + (x > 0 && !$gameSystem.isTileExplored(mapId, x - 1, y)) || + (x < mapWidth - 1 && !$gameSystem.isTileExplored(mapId, x + 1, y)) || + (y > 0 && !$gameSystem.isTileExplored(mapId, x, y - 1)) || + (y < mapHeight - 1 && !$gameSystem.isTileExplored(mapId, x, y + 1)); + + if (hasUnexploredNeighbor) { + // Draw subtle edge shadow + const px = x * tileWidth; + const py = y * tileHeight; + ctx.fillStyle = 'rgba(10, 8, 6, 0.3)'; + ctx.fillRect(px, py, tileWidth, tileHeight); + } + } + } + } }; // Check if an event is a locked door, chest, or barred gate