From 14f1879f152332714c9dc0636c68a113736cc1d3 Mon Sep 17 00:00:00 2001 From: dazedanon Date: Sun, 15 Feb 2026 12:25:30 -0600 Subject: [PATCH] Reload plugin for mail and other stuff --- www/js/plugins.js | 1 + www/js/plugins/DazedDataReload.js | 160 ++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 www/js/plugins/DazedDataReload.js diff --git a/www/js/plugins.js b/www/js/plugins.js index 40bc8bf..2cd636a 100644 --- a/www/js/plugins.js +++ b/www/js/plugins.js @@ -634,4 +634,5 @@ var $plugins = [ { name: "JsScript35Set", status: true, description: "", parameters: {} }, { name: "JsScript1Set", status: false, description: "", parameters: {} }, { name: "JsScript146Set", status: true, description: "", parameters: {} }, + { name: "DazedDataReload", status: true, description: "[Dazed] F5 hot-reload PSData/RDData/GameSetting + refresh mail cache", parameters: {} }, ]; diff --git a/www/js/plugins/DazedDataReload.js b/www/js/plugins/DazedDataReload.js new file mode 100644 index 0000000..0fc273d --- /dev/null +++ b/www/js/plugins/DazedDataReload.js @@ -0,0 +1,160 @@ +/*: + * @plugindesc [Dazed Translations] Hot-reload PSData/RDData/GameSetting JSON and refresh cached save data. Press F5 in-game. + * @author DazedTranslations + * + * @help + * Press F9 while in-game to: + * 1. Reload Nupu_PSData.json, RdData.json, and Nupu_GameSetting.json from disk + * 2. Refresh all mail text in $gameSystem.AllMailList from updated PSData + * 3. Reset the MemoryDatas cache so it rebuilds from updated PSData + * 4. Show a confirmation message on screen + * + * This allows translation changes to take effect on existing saves + * without starting a new game or restarting the application. + */ + +(function() { + 'use strict'; + + var RELOAD_KEY = 120; // F9 + + // ========================================================================= + // 1. Reload a JSON data file from disk (synchronous for reliability) + // ========================================================================= + function reloadDataFile(globalName, src) { + var xhr = new XMLHttpRequest(); + var url = 'data/' + src; + xhr.open('GET', url, false); // synchronous + xhr.overrideMimeType('application/json'); + xhr.send(); + if (xhr.status < 400) { + window[globalName] = JSON.parse(xhr.responseText); + DataManager.onLoad(window[globalName]); + return true; + } + return false; + } + + // ========================================================================= + // 2. Refresh mail text in save data from updated PSData + // ========================================================================= + function refreshMailData() { + if (!$gameSystem || !$gameSystem.AllMailList) return 0; + if (!$Nupu_PSData || !$Nupu_PSData.MailDatas) return 0; + + var updated = 0; + for (var i = 0; i < $gameSystem.AllMailList.length; i++) { + var savedMail = $gameSystem.AllMailList[i]; + if (savedMail.ToolNo == null || savedMail.ToolNo < 0) continue; + + // Find matching PSData entry by ToolNo + for (var j = 0; j < $Nupu_PSData.MailDatas.length; j++) { + var srcMail = $Nupu_PSData.MailDatas[j]; + if (srcMail.No === savedMail.ToolNo) { + // Update translatable text fields + savedMail.ChrStr = srcMail.Name; + savedMail.MTitle = srcMail.Title; + savedMail.MNaiyo = srcMail.MailText; + + // Update picture descriptions if present + if (srcMail.PicDatas && savedMail.PicData) { + for (var k = 0; k < srcMail.PicDatas.length && k < savedMail.PicData.length; k++) { + savedMail.PicData[k].PicDesc = srcMail.PicDatas[k].PicDesc; + } + } + updated++; + break; + } + } + } + return updated; + } + + // ========================================================================= + // 3. Reset MemoryDatas cache so it rebuilds from fresh PSData + // ========================================================================= + function resetMemoryCache() { + // MemoryDatas is a module-level var in JsScript122Set.js + // Setting it to null forces SetMemoryDatas() to rebuild it + if (typeof MemoryDatas !== 'undefined') { + MemoryDatas = null; + } + } + + // ========================================================================= + // 4. Show on-screen notification + // ========================================================================= + function showReloadNotification(mailCount) { + var msg = '[DazedTranslations] Data reloaded!'; + if (mailCount > 0) { + msg += ' Updated ' + mailCount + ' mail(s) in save.'; + } + // Use the map's display message if available + if (typeof SceneManager._scene !== 'undefined' && SceneManager._scene._mapNameWindow) { + // Fallback: just use console + a brief window text + } + console.log(msg); + // Show a brief HUD message using a sprite + var scene = SceneManager._scene; + if (scene) { + var sprite = new Sprite(new Bitmap(Graphics.width, 40)); + sprite.bitmap.fontSize = 18; + sprite.bitmap.textColor = '#00ff88'; + sprite.bitmap.outlineColor = '#000000'; + sprite.bitmap.outlineWidth = 4; + sprite.bitmap.drawText(msg, 10, 5, Graphics.width - 20, 30, 'left'); + sprite.y = 10; + sprite.opacity = 255; + scene.addChild(sprite); + + // Fade out after 3 seconds + var frames = 0; + var fadeInterval = setInterval(function() { + frames++; + if (frames > 180) { // 3 seconds at 60fps + sprite.opacity -= 5; + if (sprite.opacity <= 0) { + scene.removeChild(sprite); + clearInterval(fadeInterval); + } + } + }, 1000 / 60); + } + } + + // ========================================================================= + // 5. Main reload function + // ========================================================================= + function performDataReload() { + console.log('[DazedTranslations] Reloading data files...'); + + // Reload all three data files + var ok1 = reloadDataFile('$Nupu_PSData', 'Nupu_PSData.json'); + var ok2 = reloadDataFile('$RDData', 'RdData.json'); + var ok3 = reloadDataFile('$Nupu_GameSetting', 'Nupu_GameSetting.json'); + + console.log('[DazedTranslations] PSData: ' + (ok1 ? 'OK' : 'FAIL') + + ', RDData: ' + (ok2 ? 'OK' : 'FAIL') + + ', GameSetting: ' + (ok3 ? 'OK' : 'FAIL')); + + // Refresh cached data in save + var mailCount = refreshMailData(); + resetMemoryCache(); + + showReloadNotification(mailCount); + } + + // ========================================================================= + // 6. Hook into the key input system + // ========================================================================= + var _SceneManager_onKeyDown = SceneManager.onKeyDown; + SceneManager.onKeyDown = function(event) { + if (event.keyCode === RELOAD_KEY) { + event.preventDefault(); + performDataReload(); + return; + } + _SceneManager_onKeyDown.call(this, event); + }; + +})();