MV Help with minimap fog

Hi, I've developed a plugin that removes sections of an image to simulate 'clearing away' fog, and slowly reveal a minimap behind it.
Does anyone know how to save the revealed chunks? Right now it resets when I change overworld map a few times or try to save and load a game.
I've tried a lot of different methods, but I can't seem to figure it out.
Any help would be appreciated!

JavaScript:
/* RPG Maker MV - Minimap Reveal */

/* Configuration */
var minimapConfig = {
    pictureId0: 90,           // Picture ID for fog when Variable 43 is 0
    pictureId1: 91,           // Picture ID for fog when Variable 43 is 1
    revealSize: 6,            // Size of the revealed area in game tiles
    fogImage: 'MinimapHidden', // Name of the fog overlay image
    fogY: 10,                 // Y position for the fog
    fogOpacity: 250,          // Opacity of the fog
    fogX0: 690,               // X position for fog when Variable 43 is 0
    fogWidth0: 50,            // Width scale (percentage) for fog when Variable 43 is 0
    fogHeight0: 50,           // Height scale (percentage) for fog when Variable 43 is 0
    fogX1: 575,               // X position for fog when Variable 43 is 1
    fogWidth1: 100,           // Width scale (percentage) for fog when Variable 43 is 1
    fogHeight1: 100           // Height scale (percentage) for fog when Variable 43 is 1
};

var minimapRevealChunks = []; // Array to store revealed chunks

(function() {
    var _SceneMap_update = Scene_Map.prototype.update;

    Scene_Map.prototype.update = function() {
        _SceneMap_update.call(this);

        // Handle the minimap visibility only if Switch 83 is on
        if ($gameSwitches.value(83)) {
            if ($gameSwitches.value(3) && $gameMap.mapId() === 1) { // Only update on map 001
                handleFogDisplay();
                handleMinimapReveal();
            } else {
                clearFog(minimapConfig.pictureId0); // Remove fog if not on map 001 or if Switch 3 is off
                clearFog(minimapConfig.pictureId1); // Remove fog if not on map 001 or if Switch 3 is off
            }
        } else {
            // Clear all fog if Switch 83 is off
            clearFog(minimapConfig.pictureId0);
            clearFog(minimapConfig.pictureId1);
        }
    };

    function handleFogDisplay() {
        if ($gameVariables.value(43) === 0) {
            displayFog(minimapConfig.pictureId0, minimapConfig.fogX0, minimapConfig.fogY, minimapConfig.fogWidth0, minimapConfig.fogHeight0);
            clearFog(minimapConfig.pictureId1); // Ensure Picture 91 is cleared
        } else if ($gameVariables.value(43) === 1) {
            displayFog(minimapConfig.pictureId1, minimapConfig.fogX1, minimapConfig.fogY, minimapConfig.fogWidth1, minimapConfig.fogHeight1);
            clearFog(minimapConfig.pictureId0); // Ensure Picture 90 is cleared
        } else if ($gameVariables.value(43) > 1) {
            clearFog(minimapConfig.pictureId0); // Remove Picture 90
            clearFog(minimapConfig.pictureId1); // Remove Picture 91
        }
    }

    function handleMinimapReveal() {
        if ($gameSwitches.value(32)) { // Only reveal if Switch 32 is on
            updateMinimapReveal();
        } else {
            // Clear all fog images if Switch 32 is off
            clearFog(minimapConfig.pictureId0);
            clearFog(minimapConfig.pictureId1);
            minimapRevealChunks = []; // Clear revealed chunks when fog is off
        }
    }

    function displayFog(pictureId, x, y, width, height) {
        var fogImage = minimapConfig.fogImage;

        // Ensure the fog image is displayed with the specified Picture ID
        if (!$gameScreen.picture(pictureId)) {
            $gameScreen.showPicture(
                pictureId,
                fogImage,
                0,                                     // Upper-left origin
                x, y,                                  // X and Y coordinates
                width,                                 // Width scale (percentage)
                height,                                // Height scale (percentage)
                minimapConfig.fogOpacity,             // Opacity
                0                                       // No blend mode
            );
        }
    }

    function clearFog(pictureId) {
        $gameScreen.erasePicture(pictureId);
    }

    function updateMinimapReveal() {
        // Get player’s X and Y coordinates
        var playerX = $gamePlayer.x;
        var playerY = $gamePlayer.y;

        // Calculate reveal size in pixels based on game tiles
        var revealPixels = minimapConfig.revealSize * (236 / $dataMap.width); // Scaling based on 236px minimap width

        // Update the fog image to reveal chunks at the player’s position
        revealMinimapChunk(playerX, playerY, revealPixels);
    }

    function revealMinimapChunk(x, y, size) {
        var bitmap = ImageManager.loadPicture(minimapConfig.fogImage);

        // Clear a larger circular chunk of the fog around the player's position
        var context = bitmap._context;
        context.globalCompositeOperation = 'destination-out';  // Erase mode
        
        // Translate coordinates to fit the minimap scale
        var scaledX = Math.floor(x * (236 / $dataMap.width));
        var scaledY = Math.floor(y * (236 / $dataMap.height));

        // Create a larger circular reveal
        context.beginPath();
        context.arc(scaledX, scaledY, size, 0, 2 * Math.PI);  // Larger radius
        context.fill();

        bitmap._baseTexture.update();  // Update the texture

        // Store the revealed chunk to keep track of it
        minimapRevealChunks.push({ x: scaledX, y: scaledY, size: size });
    }

    // This method should be called to restore revealed chunks after loading the game
    function restoreRevealedChunks() {
        minimapRevealChunks.forEach(function(chunk) {
            var bitmap = ImageManager.loadPicture(minimapConfig.fogImage);
            var context = bitmap._context;

            context.globalCompositeOperation = 'destination-out'; // Erase mode

            // Redraw the previously revealed chunks
            context.beginPath();
            context.arc(chunk.x, chunk.y, chunk.size, 0, 2 * Math.PI); // Larger radius
            context.fill();

            bitmap._baseTexture.update(); // Update the texture
        });
    }

    // Call this function whenever the game is loaded to restore fog visibility
    var _DataManager_createGameObjects = DataManager.createGameObjects;
    DataManager.createGameObjects = function() {
        _DataManager_createGameObjects.call(this);
        restoreRevealedChunks(); // Restore revealed chunks on game load
    };

})();
You've aliased DataManager.createGameObjects() to add this restoreRevealedChunks() function to it - but where is that supposed to be getting any saved data from?

It references a minimapRevealChunks array which is never saved, it's just declared as a global variable and re-declared every time the game is run.

The easy way to do something like this would be to make minimapRevealChunks be a property of $gameSystem, which will cause it to be written to the save files - and it will also make your createGameObjects() addition irrelevant, the minimapRevealChunks array will be saved and loaded in its entirety automatically.
You've aliased DataManager.createGameObjects() to add this restoreRevealedChunks() function to it - but where is that supposed to be getting any saved data from?

It references a minimapRevealChunks array which is never saved, it's just declared as a global variable and re-declared every time the game is run.

The easy way to do something like this would be to make minimapRevealChunks be a property of $gameSystem, which will cause it to be written to the save files - and it will also make your createGameObjects() addition irrelevant, the minimapRevealChunks array will be saved and loaded in its entirety automatically.
I tried changing some things around according to your feedback, but still couldn't get it to work.
Could you be a bit more specific about what to change?
Thanks for trying
Sorry...you're coding that whole thing in JavaScript but you don't know what a property of an object means?

Or what, specifically, don't you understand from my recommendation?

Original thread: https://forums.rpgmakerweb.com/threads/help-with-minimap-fog.172758/