feat(web): add localStorage browser/editor modal and arrow-key modal navigation

Adds an in-browser LocalStorage Browser & Editor modal with live hot-reload for plugin configs and scripts, consolidates file importing into the Storage modal, and forwards arrow keys while Plugin Hub text inputs are focused.

### Storage Browser & Editor
- `index.html`:
  - Added `#btn-storage` in `#rs-footer` and the `#storage-modal` split-pane browser/editor UI with key filtering, `+ New` script/key creation, `Download`, `Delete`, `Save`, and `Save & Reload`.
  - Moved `#script-upload` into `#storage-modal` as `#storage-import` (`Import File`), auto-selecting imported `2006scape_script_*` files and refreshing the sidebar and live runtime.
- `WebLauncher.java`:
  - Registered `window.scapeReloadStorage` via `registerStorageReload()` to invoke `PluginManager.reloadStorage()` on the client thread.

### Input Handling
- `RSApplet.java`:
  - Queued Left (`1`) and Right (`2`) arrow keys into `charQueue` when `PluginPanelUI.isSearchFocused()` is true.
This commit is contained in:
Dark98 committed 2026-12-02 18:25:43 +00:00
1 parent e57315b785
commit 2dfee296e4
3 files changed
+408 -12

No files matched your search

@@ -717,7 +717,7 @@ public class RSApplet implements Runnable {
if (ch > 0 && ch < 128) {
keyArray[ch] = 1;
}
if (ch > 4) {
if (ch > 4 || ((ch == 1 || ch == 2) && PluginPanelUI.isSearchFocused())) {
charQueue[writeIndex] = ch;
writeIndex = (writeIndex + 1) & 0x7f;
}
@@ -114,6 +114,12 @@ public final class WebLauncher {
setStatusBadge("WS Port " + (overrideWsPort > 0 ? overrideWsPort : (ClientSettings.SERVER_WORLD == 1 ? 44594 : 44596 + ClientSettings.SERVER_WORLD)));
Game game = new Game();
registerHdToggle(enabled -> game.setHD317Enabled(enabled));
registerStorageReload(() -> {
PluginManager pm = PluginManager.get();
if (pm != null) {
pm.reloadStorage();
}
});
Game.server = ClientSettings.SERVER_IP;
if ("true".equalsIgnoreCase(getSavedOption("autoLogin"))) {
String u = getSavedOption("username");
@@ -162,6 +168,14 @@ public final class WebLauncher {
@JSBody(params = {"cb"}, script = "window.scapeSetHd317 = cb;")
private static native void registerHdToggle(HdToggleCallback cb);
@JSFunctor
public interface StorageReloadCallback extends JSObject {
void onReload();
}
@JSBody(params = {"cb"}, script = "window.scapeReloadStorage = cb;")
private static native void registerStorageReload(StorageReloadCallback cb);
@JSBody(params = {"enabled"}, script =
"try {\n" +
" if (!window.localStorage) return;\n" +
+393 -11
View File
@@ -306,6 +306,157 @@
color: #fff3d6;
font-weight: 600;
}
#storage-modal {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.72);
display: none;
align-items: center;
justify-content: center;
z-index: 210;
padding: 12px;
}
#storage-modal.open { display: flex; }
.storage-card {
width: min(860px, 100%);
height: min(620px, 92dvh);
display: flex;
flex-direction: column;
background: #1d1a14;
border: 1px solid #594b34;
border-radius: 6px;
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.75);
color: #d8cfa8;
font-size: 13px;
overflow: hidden;
}
.storage-body {
flex: 1;
min-height: 0;
display: flex;
flex-direction: row;
}
.storage-sidebar {
width: 260px;
max-width: 42%;
border-right: 1px solid #3c3428;
display: flex;
flex-direction: column;
background: #171410;
}
.storage-toolbar {
display: flex;
gap: 6px;
padding: 8px;
border-bottom: 1px solid #2e2820;
}
.storage-toolbar input {
flex: 1;
min-width: 0;
background: #110f0c;
color: #eee2c0;
border: 1px solid #4e4230;
border-radius: 3px;
padding: 4px 7px;
font-size: 12px;
}
.storage-toolbar button, .storage-editor-bar button {
background: #2b251c;
color: #e6d5a8;
border: 1px solid #4e4230;
border-radius: 3px;
padding: 4px 8px;
cursor: pointer;
font-size: 11px;
white-space: nowrap;
}
.storage-list {
flex: 1;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.storage-item {
padding: 7px 10px;
border-bottom: 1px solid #252019;
cursor: pointer;
display: flex;
flex-direction: column;
gap: 2px;
}
.storage-item:hover { background: #262119; }
.storage-item.active {
background: #332a1d;
border-left: 3px solid #f3c65f;
padding-left: 7px;
}
.storage-item-name {
color: #f0dfad;
font-weight: 600;
font-size: 12px;
word-break: break-all;
}
.storage-item-meta {
display: flex;
justify-content: space-between;
font-size: 10px;
color: #9e9170;
}
.storage-editor {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
padding: 8px 10px;
gap: 8px;
}
.storage-editor-bar {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.storage-key-input {
flex: 1;
min-width: 140px;
background: #110f0c;
color: #f3c65f;
border: 1px solid #4e4230;
border-radius: 3px;
padding: 5px 8px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
#storage-textarea {
flex: 1;
width: 100%;
min-height: 160px;
resize: none;
background: #110f0c;
color: #e9e0c6;
border: 1px solid #4e4230;
border-radius: 4px;
padding: 8px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.45;
tab-size: 4;
}
#storage-status {
font-size: 11px;
color: #a99b76;
margin-right: auto;
}
@media (max-width: 640px) {
.storage-body { flex-direction: column; }
.storage-sidebar {
width: 100%;
max-width: 100%;
height: 36%;
border-right: 0;
border-bottom: 1px solid #3c3428;
}
.storage-toolbar input, .storage-key-input, #storage-textarea { font-size: 14px; }
}
</style>
</head>
<body>
@@ -339,8 +490,7 @@
<div>
<a id="btn-options" href="javascript:void(0)" title="Configure auto-login, server, and graphics">Options</a>
|
<label for="script-upload" title="Import .script / .bsh / .java into browser storage">Import Script</label>
<input id="script-upload" type="file" accept=".script,.bsh,.java" multiple style="display:none" />
<a id="btn-storage" href="javascript:void(0)" title="Browse and edit browser localStorage (plugin configs, scripts, options)">Storage</a>
</div>
<div class="legal">
RuneScape is a registered trademark of Jagex Limited in the United Kingdom and other countries.<br />
@@ -422,6 +572,41 @@
</form>
</div>
<div id="storage-modal">
<div class="storage-card">
<div class="options-header">
<span>LocalStorage Browser &amp; Editor</span>
<button id="storage-close" type="button">&times;</button>
</div>
<div class="storage-body">
<div class="storage-sidebar">
<div class="storage-toolbar">
<input id="storage-filter" type="text" placeholder="Filter keys..." />
<button id="storage-new" type="button" title="Create new script or storage key">+ New</button>
<button id="storage-refresh" type="button" title="Refresh key list">&#x21bb;</button>
</div>
<div id="storage-list" class="storage-list"></div>
</div>
<div class="storage-editor">
<div class="storage-editor-bar">
<input id="storage-key" class="storage-key-input" type="text" placeholder="Select or enter localStorage key..." />
<button id="storage-download" type="button">Download</button>
<button id="storage-delete" type="button">Delete</button>
</div>
<textarea id="storage-textarea" spellcheck="false" placeholder="Select a file from localStorage or click + New..."></textarea>
</div>
</div>
<div class="options-footer">
<span id="storage-status">Ready</span>
<button id="storage-import" type="button" title="Import .script / .bsh / .java into browser storage">Import File</button>
<input id="script-upload" type="file" accept=".script,.bsh,.java" multiple style="display:none" />
<button id="storage-cancel" type="button">Close</button>
<button id="storage-save" type="button">Save</button>
<button id="storage-save-reload" type="button" class="primary">Save &amp; Reload</button>
</div>
</div>
</div>
<!-- Web Audio + Cache Preloader (must run synchronously before client.js main()) -->
<script src="libfluidsynth-2.3.0.js"></script>
<script src="js-synthesizer.min.js"></script>
@@ -685,15 +870,7 @@
cb(results[0], results[1], results[2], results[3], results[4], results[5]);
};
// Script import handler into localStorage virtual FS
document.getElementById('script-upload').addEventListener('change', async (ev) => {
for (const file of ev.target.files) {
const text = await file.text();
localStorage.setItem('2006scape_script_' + file.name, text);
console.log('[2006Scape-Web] Imported script:', file.name);
}
ev.target.value = '';
});
// Script import handler moved into Storage modal below
window.scapeInitNavbar = function(visible, mainMenuUrl, worldMapUrl, manualUrl, rulesUrl) {
const nav = document.getElementById('rs-navbar');
@@ -811,6 +988,211 @@
});
})();
(function() {
const modal = document.getElementById('storage-modal');
const btnOpen = document.getElementById('btn-storage');
const btnClose = document.getElementById('storage-close');
const btnCancel = document.getElementById('storage-cancel');
const btnRefresh = document.getElementById('storage-refresh');
const btnNew = document.getElementById('storage-new');
const btnSave = document.getElementById('storage-save');
const btnSaveReload = document.getElementById('storage-save-reload');
const btnDelete = document.getElementById('storage-delete');
const btnDownload = document.getElementById('storage-download');
const filterEl = document.getElementById('storage-filter');
const listEl = document.getElementById('storage-list');
const keyEl = document.getElementById('storage-key');
const textEl = document.getElementById('storage-textarea');
const statusEl = document.getElementById('storage-status');
let selectedKey = '';
function formatBytes(len) {
return len < 1024 ? (len + ' B') : ((len / 1024).toFixed(1) + ' KB');
}
function classifyKey(k) {
if (k === '2006scape_plugin_settings') return { label: 'Plugin Config', rank: 0, title: 'plugin_config.ini (2006scape_plugin_settings)' };
if (k === '2006scape_web_options') return { label: 'Web Options', rank: 1, title: k };
if (k.startsWith('2006scape_script_')) return { label: 'Script/Plugin', rank: 2, title: k.slice('2006scape_script_'.length) };
return { label: 'Storage', rank: 3, title: k };
}
function getSortedKeys() {
const filter = (filterEl.value || '').trim().toLowerCase();
const keys = [];
for (let i = 0; i < localStorage.length; i++) {
const k = localStorage.key(i);
if (k && (!filter || k.toLowerCase().includes(filter))) {
keys.push(k);
}
}
keys.sort((a, b) => {
const ca = classifyKey(a);
const cb = classifyKey(b);
if (ca.rank !== cb.rank) return ca.rank - cb.rank;
return a.localeCompare(b);
});
return keys;
}
function renderList() {
const keys = getSortedKeys();
listEl.innerHTML = '';
if (keys.length === 0) {
const empty = document.createElement('div');
empty.style.cssText = 'padding:12px;color:#8a7f63;font-size:12px;';
empty.textContent = 'No matching localStorage keys.';
listEl.appendChild(empty);
return;
}
for (const k of keys) {
const val = localStorage.getItem(k) || '';
const info = classifyKey(k);
const row = document.createElement('div');
row.className = 'storage-item' + (k === selectedKey ? ' active' : '');
const nameDiv = document.createElement('div');
nameDiv.className = 'storage-item-name';
nameDiv.textContent = info.title;
const metaDiv = document.createElement('div');
metaDiv.className = 'storage-item-meta';
const typeSpan = document.createElement('span');
typeSpan.textContent = info.label;
const sizeSpan = document.createElement('span');
sizeSpan.textContent = formatBytes(val.length);
metaDiv.appendChild(typeSpan);
metaDiv.appendChild(sizeSpan);
row.appendChild(nameDiv);
row.appendChild(metaDiv);
row.addEventListener('click', () => selectKey(k));
listEl.appendChild(row);
}
}
function selectKey(k) {
selectedKey = k;
keyEl.value = k;
const val = localStorage.getItem(k);
textEl.value = val !== null ? val : '';
statusEl.textContent = val !== null ? ('Loaded ' + k + ' (' + formatBytes(val.length) + ')') : 'New key';
renderList();
}
function saveCurrent(applyLive) {
const k = (keyEl.value || '').trim();
if (!k) {
statusEl.textContent = 'Enter a key name first.';
return false;
}
const val = textEl.value;
localStorage.setItem(k, val);
selectedKey = k;
renderList();
if (applyLive && (k === '2006scape_plugin_settings' || k.startsWith('2006scape_script_')) && typeof window.scapeReloadStorage === 'function') {
window.scapeReloadStorage();
statusEl.textContent = 'Saved & hot-reloaded: ' + k;
} else {
statusEl.textContent = 'Saved ' + k + ' (' + formatBytes(val.length) + ')';
}
return true;
}
if (btnOpen) btnOpen.addEventListener('click', () => {
const keys = getSortedKeys();
if (!selectedKey && keys.length > 0) selectedKey = keys[0];
if (selectedKey && localStorage.getItem(selectedKey) !== null) {
selectKey(selectedKey);
} else {
renderList();
}
modal.classList.add('open');
});
if (btnClose) btnClose.addEventListener('click', () => modal.classList.remove('open'));
if (btnCancel) btnCancel.addEventListener('click', () => modal.classList.remove('open'));
if (modal) modal.addEventListener('click', (e) => { if (e.target === modal) modal.classList.remove('open'); });
if (filterEl) filterEl.addEventListener('input', renderList);
if (btnRefresh) btnRefresh.addEventListener('click', () => {
renderList();
if (selectedKey && localStorage.getItem(selectedKey) !== null) selectKey(selectedKey);
});
if (btnNew) btnNew.addEventListener('click', () => {
const name = window.prompt('New script filename (e.g. MyPlugin.java / MyScript.script) or full localStorage key:', 'MyScript.script');
if (!name || !name.trim()) return;
const trimmed = name.trim();
const fullKey = (trimmed.startsWith('2006scape_') || !/\.(script|bsh|java)$/i.test(trimmed))
? trimmed
: ('2006scape_script_' + trimmed);
selectedKey = fullKey;
keyEl.value = fullKey;
if (localStorage.getItem(fullKey) !== null) {
textEl.value = localStorage.getItem(fullKey);
} else if (fullKey.startsWith('2006scape_script_')) {
textEl.value = '// @name New Script\n// @type script\n// @version 1.0.0\n\nvoid onStart(PluginContext c) {\n ctx = c;\n}\n';
} else {
textEl.value = '';
}
statusEl.textContent = 'Editing ' + fullKey + ' (unsaved)';
renderList();
});
if (btnSave) btnSave.addEventListener('click', () => saveCurrent(true));
if (btnSaveReload) btnSaveReload.addEventListener('click', () => {
if (saveCurrent(false)) window.location.reload();
});
if (btnDelete) btnDelete.addEventListener('click', () => {
const k = (keyEl.value || '').trim();
if (!k) return;
if (!window.confirm('Delete localStorage key "' + k + '"?')) return;
localStorage.removeItem(k);
if (selectedKey === k) selectedKey = '';
keyEl.value = '';
textEl.value = '';
renderList();
if ((k === '2006scape_plugin_settings' || k.startsWith('2006scape_script_')) && typeof window.scapeReloadStorage === 'function') {
window.scapeReloadStorage();
}
statusEl.textContent = 'Deleted ' + k;
});
if (btnDownload) btnDownload.addEventListener('click', () => {
const k = (keyEl.value || '').trim() || 'storage_export.txt';
const fileName = k === '2006scape_plugin_settings' ? 'plugin_config.ini'
: (k.startsWith('2006scape_script_') ? k.slice('2006scape_script_'.length) : (k + '.txt'));
const blob = new Blob([textEl.value], { type: 'text/plain;charset=utf-8' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = fileName;
a.click();
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
});
const btnImport = document.getElementById('storage-import');
const scriptUpload = document.getElementById('script-upload');
if (btnImport && scriptUpload) {
btnImport.addEventListener('click', () => scriptUpload.click());
scriptUpload.addEventListener('change', async (ev) => {
let count = 0;
let lastKey = '';
for (const file of ev.target.files) {
const text = await file.text();
lastKey = '2006scape_script_' + file.name;
localStorage.setItem(lastKey, text);
console.log('[2006Scape-Web] Imported script:', file.name);
count++;
}
ev.target.value = '';
if (count > 0) {
if (typeof window.scapeReloadStorage === 'function') {
window.scapeReloadStorage();
}
if (lastKey) {
selectedKey = lastKey;
keyEl.value = lastKey;
textEl.value = localStorage.getItem(lastKey) || '';
}
renderList();
statusEl.textContent = 'Imported ' + count + ' script(s) & reloaded';
}
});
}
})();
function updateCachedStageSize() {
const s = document.getElementById('stage');
const nav = document.getElementById('rs-navbar');