fix(forge): hide the persistent launcher icon

- Default the MZ launcher off and override saved visibility settings
- Detach the MV launcher while preserving configured shortcuts
- Add regression coverage for generated MV and MZ plugins
- Enable core dialogue extraction and first-line speaker detection
- Disable optional script and plugin extraction by default
This commit is contained in:
DazedAnon 2026-07-26 13:53:12 -05:00
parent f7aac8bba5
commit 71618c23b9
4 changed files with 83 additions and 8 deletions

View file

@ -85,7 +85,7 @@ LEAVE = False
# Config (Default)
# FIRSTLINESPEAKERS: Guess speaker from first line.
FIRSTLINESPEAKERS = False
FIRSTLINESPEAKERS = True
# INLINE401SPEAKERS: Extract speaker from "Name「dialogue」" inline format on 401 lines.
INLINE401SPEAKERS = False
# FACENAME101: Map face name -> speaker.
@ -148,13 +148,13 @@ TLSYSTEMSWITCHES = False
JOIN408 = False
# Dialogue / Scroll / Choices (Main Codes)
CODE101 = False
CODE401 = False
CODE405 = False
CODE102 = False
CODE101 = True
CODE401 = True
CODE405 = True
CODE102 = True
# Optional
CODE408 = False
CODE408 = True
# Variables
CODE122 = False
@ -162,8 +162,8 @@ CODE122_VAR_MIN = 0
CODE122_VAR_MAX = 2000
# Plugins / Scripts
CODE355655 = True
CODE357 = True
CODE355655 = False
CODE357 = False
CODE657 = False
CODE356 = False
CODE320 = False

View file

@ -0,0 +1,43 @@
#!/usr/bin/env python3
"""Tests for install-time Forge plugin customization."""
from __future__ import annotations
import os
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
os.chdir(ROOT)
sys.path.insert(0, str(ROOT))
from util.forge.config import prepare_forge_js # noqa: E402
class ForgeConfigTests(unittest.TestCase):
def test_modern_mz_hides_launcher_and_keeps_shortcut(self):
output = prepare_forge_js(
"MZ",
cfg={"forgeHotkey": "F9", "uiScale": "auto"},
)
self.assertIn("favorites:{},showLauncher:!1,quickSaveSlot:1", output)
self.assertIn("config.showLauncher = false;", output)
self.assertIn("keyStr:`f9`", output)
self.assertIn("saved.toggle_ui", output)
def test_legacy_mv_omits_launcher_and_keeps_shortcut(self):
output = prepare_forge_js(
"MV",
cfg={"forgeHotkey": "F9", "uiScale": "auto"},
)
self.assertNotIn("rootEl.appendChild(launcher);", output)
self.assertIn("Floating launcher disabled", output)
self.assertIn('window.Forge._hotkey = "F9";', output)
self.assertIn("if (key === (API._hotkey || 'F10'))", output)
if __name__ == "__main__":
unittest.main()

View file

@ -150,6 +150,18 @@ def _patch_forge_runtime(forge_text: str, hotkey: str, ui_scale: str, engine: st
return forge_text
def _remove_legacy_launcher(forge_text: str) -> str:
"""Keep legacy Forge shortcut-only by leaving its launcher detached."""
marker = " rootEl.appendChild(launcher);"
if forge_text.count(marker) != 1:
raise ValueError("Could not disable legacy Forge launcher")
return forge_text.replace(
marker,
" // Floating launcher disabled; use the configured Forge shortcut.",
1,
)
def is_legacy_forge_plugin(text: str) -> bool:
"""True for pre-rewrite Forge_MV/MZ plugins with RPG Maker @param blocks."""
return "@param Hotkey" in text or "@param hotkey" in text
@ -171,6 +183,7 @@ def prepare_forge_js(engine: str, source: Path | None = None, cfg: dict | None =
text = _patch_forge_ui_scale_default(text, str(ui_scale), engine)
text = _patch_forge_mtc_defaults(text, hotkey, str(ui_scale))
text = _patch_forge_runtime(text, hotkey, str(ui_scale), engine)
text = _remove_legacy_launcher(text)
return text

View file

@ -22,6 +22,9 @@ _MODIFIER_ALIASES = {
_TOGGLE_UI_KEYSTR_RE = re.compile(
r"(id:`toggle_ui`,name:`Toggle Cheat UI`,desc:`Show/Hide the cheat panel`,keyStr:`)[^`]+(`)"
)
_SHOW_LAUNCHER_DEFAULT_RE = re.compile(
r"(favorites:\{\},showLauncher:)![01](,quickSaveSlot:1)"
)
def forge_key_str(hotkey: str) -> str:
@ -80,6 +83,13 @@ def _bootstrap_js(hotkey: str, ui_scale: str) -> str:
saved.toggle_ui = Object.assign({{}}, saved.toggle_ui, {{ keyStr: toggleKey, enabled: true }});
localStorage.setItem("forge:shortcuts", JSON.stringify(saved));
}} catch (e) {{}}
// The keyboard shortcut is always available, so keep the floating launcher
// hidden even when an older Forge install saved it as enabled.
try {{
var config = JSON.parse(localStorage.getItem("forge:config") || "{{}}");
config.showLauncher = false;
localStorage.setItem("forge:config", JSON.stringify(config));
}} catch (e) {{}}
function resolveUiScale(v) {{
if (v !== "auto" && v != null && String(v).trim() !== "") {{
var n = parseFloat(v);
@ -133,6 +143,14 @@ def _patch_toggle_ui_default(text: str, hotkey: str) -> str:
return text
def _disable_launcher_default(text: str) -> str:
"""Hide modern Forge's floating launcher; the toggle shortcut remains active."""
text, n = _SHOW_LAUNCHER_DEFAULT_RE.subn(r"\g<1>!1\2", text, count=1)
if n == 0:
raise ValueError("Could not disable modern Forge launcher default")
return text
def _patch_keycode_reads(text: str) -> str:
"""Route Forge shortcut key reads through the keyCode polyfill."""
replacements = [
@ -162,6 +180,7 @@ def apply_modern_forge_patches(text: str, hotkey: str, ui_scale: str) -> str:
"""Inject Dazed hotkey / UI-scale bootstrap and harden shortcut handling."""
text = _strip_existing_bootstrap(text)
text = _patch_toggle_ui_default(text, hotkey)
text = _disable_launcher_default(text)
text = _patch_keycode_reads(text)
bootstrap = _bootstrap_js(hotkey, ui_scale)
match = re.search(r"\*/\s*\n", text)