Triforce v0.8.5

A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-28 10:54:41 -06:00
parent 2df08c751e
commit b527e29adb
203 changed files with 18821 additions and 2051 deletions

View File

@@ -208,3 +208,47 @@ body.kb .cp-sv.held.kf { outline: 4px double var(--gold-hi) !important; box-shad
.ehpack .ehp-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, rgb(var(--gold-low-rgb)), rgb(var(--gold-hi-rgb))); box-shadow: 0 0 10px rgba(var(--gold-glow-rgb), .6); transition: width .4s; }
#s-home.nopic .ehpack { top: 192px; }
@media (prefers-reduced-motion: reduce) { .evilhd, .evilhd * { transition: none !important; } }
/* ((Triforce, 11-25) the Randomizer page (rando.js): the settings list on the left, the seed card on the right, the focused row's tip under the list */
#s-rando .settabs { flex-wrap: wrap; width: 800px; row-gap: 8px; }
#s-rando .rset { top: 246px !important; max-height: 520px !important; overflow-y: auto; padding-right: 12px; }
/* the right column: the seed card, then the focused setting's whole description under it (scrolling when long) */
.rside { position: absolute; right: 64px; top: 246px; bottom: 24px; width: 330px; display: flex; flex-direction: column; gap: 16px; }
/* (relative, not static: the box's inner line (.fbox::before) is drawn inside the card, not around the whole column) */
.rside .rcard { position: relative; top: auto; right: auto; flex: 0 0 auto; }
.rcard h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rcard .rseedt { color: var(--gold-hi); }
.rcard .rsmall { margin: 14px 0 0; font-size: 12.5px; color: var(--text3); }
.rcard .rline { margin: 10px 0 14px; font-size: 13px; color: var(--text2); min-height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rbar { height: 6px; background: rgba(255, 255, 255, .06); outline: 1px solid rgba(var(--gold-rgb), .25); overflow: hidden; }
.rbar i { display: block; height: 100%; background: var(--gold); transition: width .3s; }
.rbar.busy i { width: 30%; animation: rbarrun 1.2s ease-in-out infinite; }
@keyframes rbarrun { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
/* (the box stays put; its text scrolls inside it, the box's inner line with the box) */
.rtip { flex: 0 1 auto; min-height: 0; overflow: hidden; font-size: 13.5px; line-height: 1.5; color: var(--text2); display: none; }
.rtip.on { display: flex; flex-direction: column; }
.rtip .rtipin { overflow-y: auto; min-height: 0; padding: 16px 20px; }
.rtip b { display: block; font-size: 15px; color: var(--text); margin-bottom: 6px; }
.rtip p { margin: 0; white-space: pre-line; }
.rtipin::-webkit-scrollbar { width: 6px; } .rtipin::-webkit-scrollbar-thumb { background: rgba(var(--gold-rgb), .35); }
/* the randomizer's pickers: each option's description whole, wrapped; the list scrolls when long */
.sheet:has(.ropts) { width: 720px; }
.rintro { margin-top: 8px; font-size: 14px; line-height: 1.5; color: var(--text2); max-height: 140px; overflow-y: auto; padding-right: 8px; white-space: pre-line; }
.ropts { margin-top: 16px; max-height: 400px; overflow-y: auto; padding-right: 8px; }
.ropts .opt:first-of-type { margin-top: 0; }
.ropt { align-items: start; }
.ropt > div { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; }
.ropt .rdesc { display: block; margin-top: 4px; font-size: 13.5px; line-height: 1.45; color: var(--text2); white-space: pre-line; }
.ropt em { font-style: normal; font-size: 12px; font-weight: 600; color: #ff8a92; margin-left: 10px; }
.ropt.dim b { opacity: .7; }
.ropts::-webkit-scrollbar, .rintro::-webkit-scrollbar { width: 6px; } .ropts::-webkit-scrollbar-thumb, .rintro::-webkit-scrollbar-thumb { background: rgba(var(--gold-rgb), .35); }
.rnote { margin-top: 14px !important; }
.rseeds .mod { grid-template-columns: 22px 1fr auto !important; }
.rseeds .rmi { width: 12px; height: 12px; transform: rotate(45deg); outline: 1px solid rgba(var(--gold-rgb), .5); background: transparent; margin-left: 4px; }
.rseeds .rmi.on { background: var(--emerald, #5fd38a); outline-color: transparent; }
.rin { position: static !important; width: 100% !important; margin-top: 16px; }
.rsacts { flex-wrap: wrap; row-gap: 12px; }
.rcard .rproblem { margin: 0 0 14px; font-size: 13px; line-height: 1.45; color: #ff8a92; max-height: 112px; overflow: auto; }
.rseeds .rsn { min-width: 0; } .rseeds .rsn b, .rseeds .rsn span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet h3 .mcount { font-family: inherit; font-size: 15px; font-weight: 600; color: var(--text3); }
.rbad { color: #ff8a92 !important; }

View File

@@ -3,7 +3,7 @@
page -> launcher {t:'ready'} {t:'win', a:'min'|'max'|'close'} {t:'pick', kind:'file'|'folder'} {t:'drop', files:[file:// on Linux]}
{t:'cmd', c:<name>, ...args} (build, stop, retry, play, update, playold, showgame, open, lang, folder, setting,
saves.import, saves.export, saves.open, mods.*, bench, benchstop, benchapply,
saves.import, saves.export, saves.open, mods.*, rando.* (rando.js), bench, benchstop, benchapply,
report, sound, color, workback, ...)
launcher -> page {t:'hello', chrome, os} {t:'state', ...parts} {t:'go', s} {t:'check', st, name, msg}
{t:'work', ...} {t:'log', lines} {t:'toast', html} {t:'sfx', id} {t:'bench', ...} {t:'max', on}
@@ -11,7 +11,8 @@
Without a launcher (a plain browser) demo.js answers instead, so the design can be looked at anywhere. */
'use strict';
const $ = (s, r = document) => r.querySelector(s), $$ = (s, r = document) => [...r.querySelectorAll(s)];
const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
// ((Triforce, 11-26) the single quote too: a value inside url('...') in a style attribute (a GameBanana picture) cannot end it)
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
/* ---------------- the window this page lives in ---------------- */
const HOST = window.chrome && window.chrome.webview ? 'win' : (window.external && typeof window.external.sendMessage === 'function' ? 'linux' : null);
@@ -234,9 +235,9 @@ document.addEventListener('pointerdown', e => {
});
/* ---------------- screens ---------------- */
const MAIN = ['home', 'mods', 'saves', 'settings'];
const MAIN = ['home', 'mods', 'rando', 'saves', 'settings'];
const FIRST_RUN = ['welcome', 'reveal', 'done'];
const MUSIC = { welcome: null, reveal: 'saria', work: 'temple', done: 'itemget', home: 'fairy', saves: 'fairy', mods: 'fairy', settings: 'fairy', bench: 'fairy', brun: null, playing: null };
const MUSIC = { welcome: null, reveal: 'saria', work: 'temple', done: 'itemget', home: 'fairy', saves: 'fairy', mods: 'fairy', rando: 'fairy', settings: 'fairy', bench: 'fairy', brun: null, playing: null };
let screen = null;
function go(name) {
if (name === screen || !$('#s-' + name)) return;
@@ -254,6 +255,7 @@ function go(name) {
setFocus($('#' + $('#s-' + name).dataset.first) || focusables()[0], false);
if (name === 'mods' && !S.mods.loaded) cmd('mods.list', { tab: S.mods.tab, q: '' });
if (name === 'saves') cmd('saves.list');
if (name === 'rando') cmd('rando.open');
cmd('screen', { s: name });
}
function afterOneShot(name) { if (name === 'itemget' && (MUSIC[screen] === 'fairy' || screen === 'done')) music('fairy'); }
@@ -277,6 +279,7 @@ function setFocus(el, sound) {
const letGo = focused && focused.id === 'cpSv' && focused.classList.contains('held'); // (the colour square lets go when focus leaves it)
if (letGo) focused.classList.remove('held');
focused = el; el.classList.add('kf');
if (typeof randoFocus === 'function') randoFocus(el); // (the Randomizer page's tip line: rando.js)
if (letGo || el.id === 'cpSv') colorMsg();
if (el.tagName === 'INPUT') el.focus(); else if (document.activeElement && document.activeElement.tagName === 'INPUT') document.activeElement.blur();
if (document.body.classList.contains('kb')) el.scrollIntoView({ block: 'nearest' });
@@ -343,7 +346,7 @@ function back() {
function tab(d) {
if (!MAIN.includes(screen) && screen !== 'bench') return;
const i = MAIN.indexOf(screen === 'bench' ? 'settings' : screen);
sfx(d < 0 ? 'tab_l' : 'tab_r'); go(MAIN[(i + d + 4) % 4]);
sfx(d < 0 ? 'tab_l' : 'tab_r'); go(MAIN[(i + d + MAIN.length) % MAIN.length]);
}
let toastT = 0;
function toast(html) {
@@ -371,6 +374,7 @@ const ACTIONS = {
evilhd: () => { const r = evilRow(); if (!r) return; r.v = +r.v === 1 ? 0 : 1; drawEvilHd(); cmd('gopt.value', { key: 'evil_hd', value: r.v }); },
bringin: () => openSaveFlow('import'),
copyout: () => openSaveFlow('export'),
benchstop: () => cmd('benchstop'), // ((Triforce, 11-26) the run screen's Esc / B: its data-back named this, which was no action)
opt: (a, el) => { $$('.opt', el.parentElement).forEach(o => o.classList.toggle('sel', o === el)); },
row: (id) => settingRow(id),
choose: (id) => cmd('choose', { id }),
@@ -386,6 +390,8 @@ function closeSheet(quiet) {
if (!$('#sheetBg').classList.contains('open')) return;
$('#sheetBg').classList.remove('open'); if (!quiet) sfx('close');
if (sheetReturn && document.contains(sheetReturn) && visible(sheetReturn)) { focused = null; setFocus(sheetReturn); }
// (the row it opened from is gone, drawn anew meanwhile: the screen's first place, never a button of the closed sheet)
else if (screen && $('#s-' + screen)) { focused = null; setFocus($('#' + $('#s-' + screen).dataset.first) || focusables()[0]); }
}
function openVol() { $('#vol').classList.add('open'); sfx('open'); setFocus($('[data-vol="music"]')); }
function closeVol(quiet) { if (!$('#vol').classList.contains('open')) return; $('#vol').classList.remove('open'); if (!quiet) sfx('close'); setFocus($('#spk')); }
@@ -513,7 +519,7 @@ function drawHome() {
$('#playBtn').classList.toggle('off', !!h.off);
$('#hLinks').innerHTML = (h.links || []).map(l => l.act ? `<span class="lnk" data-f data-act="${esc(l.act)}">${l.html}</span>` : `<span>${l.html}</span>`).join('');
const url = picUrl(f);
['#homeImg', '#homePic', '#savesImg', '#modsImg', '#setImg', '#playImg', '#benchImg'].forEach(s => $(s).style.backgroundImage = url);
['#homeImg', '#homePic', '#savesImg', '#modsImg', '#randoImg', '#setImg', '#playImg', '#benchImg'].forEach(s => $(s).style.backgroundImage = url);
$('#s-home').classList.toggle('nopic', !f);
$('#hCap').textContent = f ? `${f.label} · ${f.last ? 'your last save · ' : ''}picture from the game` : '';
$('#strip').innerHTML = files.map((x, i) => `<div class="f${i === S.cur ? ' on' : ''}" data-f data-act="file:${i}" id="f${i}"><img src="${esc(x.pic)}" alt=""><small>${esc(x.label)}</small></div>`).join('');
@@ -589,6 +595,10 @@ function gameRows(tab) {
}
function pct(r) { return r.hi > r.lo ? Math.round((r.v - r.lo) / (r.hi - r.lo) * 1000) / 10 : 0; }
function drawSettings() {
// ((Triforce, 11-26) a game-option slider being dragged, or whose value is on its way, is not drawn over: every state
// message drew the page anew, the dragged slider was gone from under the pointer, and the value at that moment was the one kept)
if (S.gDrag || S.gSend) { S.gPending = true; return; }
S.gPending = false;
const tabs = [{ id: 'launcher', name: 'Launcher' }].concat(S.gameopts && S.gameopts.tabs || []);
if (!tabs.some(t => t.id === S.settab)) S.settab = 'launcher';
const keep = focused && focused.id;
@@ -611,20 +621,36 @@ function gStep(el, v) {
v = Math.max(lo, Math.min(hi, lo + Math.round((v - lo) / st) * st));
el.dataset.v = v; const p = hi > lo ? (v - lo) / (hi - lo) * 100 : 0;
el.querySelector('i').style.width = p + '%'; el.querySelector('u').style.left = p + '%';
const lab = el.parentElement.querySelector('.gval'); if (lab) lab.textContent = String(v);
// (the randomizer's multiples show as 1.5x: rando.js rNum)
const lab = el.parentElement.querySelector('.gval'); if (lab) lab.textContent = el.dataset.times ? (v / +el.dataset.times).toFixed(2).replace(/\.?0+$/, '') + '\u00d7' : String(v);
return v;
}
let gSendT = 0;
function gSend(el) { clearTimeout(gSendT); gSendT = setTimeout(() => cmd('gopt.value', { key: el.dataset.gkey, value: +el.dataset.v }), 350); }
let gSendT = 0, gSendEl = null;
// (the randomizer's page waits while a value is on its way (S.rSend) or a slider is held (S.rDrag), then draws: rando.js drawRando.
// Another slider's value on its way goes at once, so none is lost)
const gKey = el => el.dataset.rkey ? 'r:' + el.dataset.rkey : 'g:' + el.dataset.gkey;
function gFire() {
const el = gSendEl; gSendEl = null; clearTimeout(gSendT); if (!el) return;
if (el.dataset.rkey) { S.rSend = false; cmd('rando.set', { id: el.dataset.rkey, value: +el.dataset.v }); } else { S.gSend = false; cmd('gopt.value', { key: el.dataset.gkey, value: +el.dataset.v }); }
}
function gSend(el) {
if (gSendEl && gKey(gSendEl) !== gKey(el)) gFire();
clearTimeout(gSendT); gSendEl = el;
if (el.dataset.rkey) S.rSend = true; else S.gSend = true;
gSendT = setTimeout(gFire, 350);
}
document.addEventListener('pointerdown', e => {
const s = e.target.closest('.slider[data-gkey]'); if (!s || s.closest('.off')) return;
const s = e.target.closest('.slider[data-gkey], .slider[data-rkey]'); if (!s || s.closest('.off')) return;
e.preventDefault(); setFocus(s, true);
const mv = ev => { const b = s.getBoundingClientRect(); gStep(s, +s.dataset.lo + (ev.clientX - b.left) / b.width * (+s.dataset.hi - +s.dataset.lo)); };
if (s.dataset.rkey) S.rDrag = true; else S.gDrag = true;
// (held by the slider, so letting go outside the window still ends the drag; a move with no button down ends it too)
try { s.setPointerCapture(e.pointerId); } catch (x) { }
const up = () => { removeEventListener('pointermove', mv); removeEventListener('pointerup', up); removeEventListener('pointercancel', up); S.rDrag = false; S.gDrag = false; sfx('cursor'); gSend(s); };
const mv = ev => { if (!ev.buttons) return up(); const b = s.getBoundingClientRect(); if (b.width > 0) gStep(s, +s.dataset.lo + (ev.clientX - b.left) / b.width * (+s.dataset.hi - +s.dataset.lo)); };
mv(e);
const up = () => { removeEventListener('pointermove', mv); removeEventListener('pointerup', up); sfx('cursor'); gSend(s); };
addEventListener('pointermove', mv); addEventListener('pointerup', up);
addEventListener('pointermove', mv); addEventListener('pointerup', up); addEventListener('pointercancel', up);
});
function gNudge(d) { if (!focused || !focused.dataset.gkey || focused.closest('.off')) return false; gStep(focused, +focused.dataset.v + d * (+focused.dataset.step || 1)); sfx('cursor'); gSend(focused); return true; }
function gNudge(d) { if (!focused || !(focused.dataset.gkey || focused.dataset.rkey) || focused.closest('.off')) return false; gStep(focused, +focused.dataset.v + d * (+focused.dataset.step || 1)); sfx('cursor'); gSend(focused); return true; }
function settingRow(id) { cmd('setting', { id }); }
// (the list is asked for each time the page opens, so it shows what is true now: Steam, shortcuts, the game folder)
new MutationObserver(() => { if ($('#s-settings').classList.contains('on')) cmd('settings.list'); }).observe($('#s-settings'), { attributes: true, attributeFilter: ['class'] });
@@ -855,6 +881,9 @@ onHost(m => {
if (!had.music && S.media.music && screen) { const want = MUSIC[screen]; curTrack = null; music(want === 'itemget' ? 'fairy' : want); }
}
drawPill(); drawHome(); drawReveal(); drawSaves(); drawSettings(); if (m.mods) drawMods(); nowPlaying();
if (m.rando && m.rando.schema) S.randoSchema = m.rando.schema; // (OOTRR's settings come once; the rows every time)
if (m.randoMade) S.rtab = 'seeds';
if ((m.rando || m.randoMade) && typeof drawRando === 'function') drawRando();
if (m.done) { $('#doneEb').textContent = S.done.eb || ''; $('#doneLead').textContent = S.done.lead || ''; }
break;
}
@@ -879,7 +908,7 @@ document.addEventListener('keydown', e => {
const ca = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, 1], ArrowDown: [0, -1] }[k];
if (ca && colorNudge(ca[0], ca[1])) { } // (the colour picker's square and hue take the arrows first)
else if (focused && focused.dataset.vol && (k === 'ArrowLeft' || k === 'ArrowRight')) { setVol(focused.dataset.vol, S.sound[focused.dataset.vol] + (k === 'ArrowLeft' ? -.05 : .05)); sfx('cursor'); }
else if (focused && focused.dataset.gkey && (k === 'ArrowLeft' || k === 'ArrowRight')) gNudge(k === 'ArrowLeft' ? -1 : 1);
else if (focused && (focused.dataset.gkey || focused.dataset.rkey) && (k === 'ArrowLeft' || k === 'ArrowRight')) gNudge(k === 'ArrowLeft' ? -1 : 1);
else if (k === 'ArrowLeft') move(-1, 0); else if (k === 'ArrowRight') move(1, 0);
else if (k === 'ArrowUp') move(0, -1); else if (k === 'ArrowDown') move(0, 1);
else if (k === 'Enter' || k === ' ') activate(focused);

View File

@@ -107,8 +107,40 @@
}
}, 100);
}
// ((Triforce, 11-25) the Randomizer page: a few of OOTRR's settings, sample seeds, a pretend download and seed)
const RS = { have: false, frac: 0, busy: false, seeds: [{ id: 'Randomizer K7QW2MPA', seed: 'K7QW2MPA', on: true, sub: 'On · made 24 Nov 2026, 21:10 · OOTRR 0.8.2', settings: 'OOTRR1-AMAQAJQBAETQCAJ', spoiler: true, cos: '' }],
seed: 'R4TN8XQE', cos: { music: 'off', sfx: 'off', colors: 'off', title: true }, preset: 'default',
v: { open_forest: 'closed', zora_fountain: 'closed', shuffle_songs: 'off', shuffle_smallkeys: 'dungeon', bridge: 'vanilla', bridge_rewards: 9, skip_ganon_trials: false, trials: 6, starting_hearts: 3, starting_items: [], enemy_damage: 100, no_heart_drops: false } };
const RSCHEMA = { prefix: 'OOTRR1-', groups: [{ id: 'world', label: 'World', tip: 'How the world starts.' }, { id: 'shuffle', label: 'Shuffles', tip: '' }, { id: 'keys', label: 'Keys', tip: '' }, { id: 'goal', label: 'Goals', tip: '' }, { id: 'starting', label: 'Starting items', tip: '' }, { id: 'difficulty', label: 'Difficulty', tip: 'All off unless you turn them on.' }],
presets: [{ id: 'default', name: 'Default', tip: 'OOTRR\'s defaults.' }, { id: 'easy', name: 'Easy', tip: 'Keys are removed, the world is mostly open and the goals are short.' }, { id: 'keysanity', name: 'Keysanity', tip: 'Keys anywhere.' }],
settings: [
{ id: 'open_forest', label: 'Kokiri Forest', group: 'world', kind: 'choice', tip: 'Whether Mido lets you out of the forest from the start.', choices: [{ id: 'open', label: 'Open', tip: '' }, { id: 'closed', label: 'Closed', tip: '' }] },
{ id: 'zora_fountain', label: "Zora's Fountain", group: 'world', kind: 'choice', tip: 'Whether King Zora starts moved aside.', choices: [{ id: 'closed', label: 'Closed', tip: '' }, { id: 'adult', label: 'Open for adult', tip: '' }, { id: 'open', label: 'Open', tip: '' }] },
{ id: 'shuffle_songs', label: 'Songs', group: 'shuffle', kind: 'choice', tip: 'Where the songs are taught.', choices: [{ id: 'off', label: 'Vanilla', tip: '' }, { id: 'own', label: 'Among the song teachers', tip: '' }, { id: 'anywhere', label: 'Anywhere', tip: '' }] },
{ id: 'shuffle_smallkeys', label: 'Small keys', group: 'keys', kind: 'choice', tip: 'Where small keys can be.', choices: [{ id: 'remove', label: 'Removed', tip: '' }, { id: 'vanilla', label: 'Vanilla', tip: '' }, { id: 'dungeon', label: 'Own dungeon', tip: '' }, { id: 'keysanity', label: 'Anywhere', tip: '' }] },
{ id: 'bridge', label: 'Rainbow Bridge', group: 'goal', kind: 'choice', tip: 'What opens the bridge to Ganon\'s Castle.', choices: [{ id: 'open', label: 'Open', tip: '' }, { id: 'vanilla', label: 'Vanilla', tip: '' }, { id: 'dungeons', label: 'Dungeon rewards', tip: '' }] },
{ id: 'bridge_rewards', label: 'Rewards for the bridge', group: 'goal', kind: 'number', tip: 'How many Stones and Medallions open the bridge.', min: 0, max: 9, step: 1 },
{ id: 'skip_ganon_trials', label: "Skip Ganon's Trials", group: 'goal', kind: 'toggle', tip: 'The barrier is down from the start.' },
{ id: 'trials', label: 'Trials to clear', group: 'goal', kind: 'number', tip: 'How many of the six trials count.', min: 0, max: 6, step: 1 },
{ id: 'starting_hearts', label: 'Starting hearts', group: 'starting', kind: 'number', tip: 'Hearts at the start of a new game.', min: 1, max: 20, step: 1 },
{ id: 'starting_items', label: 'Starting items', group: 'starting', kind: 'multi', tip: 'Items you begin the game with.', choices: [{ id: 'ocarina', label: 'Ocarina', tip: '' }, { id: 'bow', label: 'Bow', tip: '' }, { id: 'hookshot', label: 'Hookshot', tip: '' }, { id: 'hover_boots', label: 'Hover Boots', tip: '' }] },
{ id: 'enemy_damage', label: 'Enemy damage', group: 'difficulty', kind: 'number', tip: 'How hard enemies hit, from 0.5x to 5x.', min: 50, max: 500, step: 25, times: 100 },
{ id: 'no_heart_drops', label: 'No heart drops', group: 'difficulty', kind: 'toggle', tip: 'Enemies and grass drop no hearts.' },
] };
function rshow(x, v) { return x.kind === 'toggle' ? (v ? 'On' : 'Off') : x.kind === 'choice' ? (x.choices.find(c => c.id === v) || {}).label : x.kind === 'multi' ? (v.length ? v.map(i => (x.choices.find(c => c.id === i) || {}).label).join(', ') : 'None') : String(v); }
function rando(withSchema) {
const rows = {};
for (const x of RSCHEMA.settings) {
const hide = (x.id === 'bridge_rewards' && RS.v.bridge !== 'dungeons') || (x.id === 'trials' && RS.v.skip_ganon_trials);
rows[x.id] = { st: hide ? 'hidden' : 'open', v: RS.v[x.id], show: rshow(x, RS.v[x.id]) };
}
const r = { tool: { have: RS.have, version: '0.8.2', size: '4.5 MB', busy: RS.busy && !RS.have, frac: RS.frac, line: RS.busy ? 'Downloading, ' + Math.round(RS.frac * 100) + ' %' : '' },
game: true, busy: RS.have && RS.busy, line: RS.line || '', seed: RS.seed, cos: RS.cos, preset: RS.preset, changed: RS.preset ? 0 : 3, rows, seeds: RS.seeds, note: '' };
if (withSchema) r.schema = RSCHEMA;
emit({ t: 'state', rando: r });
}
window.DEMO = {
jumps: [['welcome', 'First run: welcome'], ['reveal', 'First run: game found'], ['build', 'First run: building'], ['fail', 'Build failed'], ['done', 'First run: ready'], ['home', 'Home'], ['update', 'Home with an update ready'], ['saves', 'Saves'], ['mods', 'Mods'], ['settings', 'Settings'], ['bench', 'Benchmark']],
jumps: [['welcome', 'First run: welcome'], ['reveal', 'First run: game found'], ['build', 'First run: building'], ['fail', 'Build failed'], ['done', 'First run: ready'], ['home', 'Home'], ['update', 'Home with an update ready'], ['saves', 'Saves'], ['mods', 'Mods'], ['rando', 'Randomizer'], ['settings', 'Settings'], ['bench', 'Benchmark']],
jump(j, fn) {
out = fn; clearInterval(st.timer);
if (j === 'welcome') { emit({ t: 'state', media: { art: false, music: false, sfx: true } }); emit({ t: 'go', s: 'welcome' }); }
@@ -161,6 +193,36 @@
else if (c === 'texpackstop') { clearInterval(st.packTimer); st.pack.busy = false; st.pack.have = 'partial'; emit({ t: 'toast', html: 'Download stopped · it goes on where it stopped next time' }); emit(home()); }
else if (c === 'setting' && m.id === 'uninstall') emit({ t: 'ask', title: 'Uninstall Triforce?', html: '<p>Removes the launcher, its tools and the built game.</p><p>Your saves and mods stay in a backup folder.</p>', reply: 'uninstall', buttons: [{ id: 'no', label: 'Keep it' }, { id: 'yes', label: 'Uninstall', main: true }] });
else if (c === 'setting') emit({ t: 'toast', html: m.id + ' <span style="color:var(--text3)">· the launcher does this</span>' });
else if (c === 'rando.open') rando(true);
else if (c === 'rando.install' || c === 'rando.install.go') { RS.busy = true; clearInterval(st.packTimer); st.packTimer = setInterval(() => { RS.frac = Math.min(1, RS.frac + .1); if (RS.frac >= 1) { clearInterval(st.packTimer); RS.have = true; RS.busy = false; emit({ t: 'toast', html: '<b>&#9670;</b> The randomizer is ready · OOTRR 0.8.2', sfx: 'success' }); } rando(RS.have); }, 150); }
else if (c === 'rando.set') { RS.v[m.id] = m.value; RS.preset = null; rando(); }
else if (c === 'rando.pick') { RS.v[m.ctx] = m.id; RS.preset = null; rando(); }
else if (c === 'rando.preset.pick') { RS.preset = m.id; rando(); }
else if (c === 'rando.cos.pick') { RS.cos[m.ctx] = m.id; rando(); }
else if (c === 'rando.cos') { RS.cos.title = m.value === 'on'; rando(); }
else if (c === 'rando.seed') { RS.seed = m.text; rando(); }
else if (c === 'rando.reseed') { RS.seed = Math.random().toString(36).slice(2, 10).toUpperCase(); rando(); }
else if (c === 'rando.decode') { RS.preset = null; emit({ t: 'toast', html: 'Settings taken from the string', sfx: 'success' }); rando(); }
else if (c === 'rando.make') {
RS.busy = true; const lines = ['Placing the items', 'Writing the seed’s game files', 'Title logo: written', 'changed 156 of 236 placed chests']; let i = 0; clearInterval(st.packTimer);
st.packTimer = setInterval(() => {
RS.line = lines[i++];
if (i > lines.length) {
clearInterval(st.packTimer); RS.busy = false; RS.line = ''; RS.seeds.forEach(x => { x.on = false; x.sub = x.sub.replace(/^On/, 'Off'); });
RS.seeds.unshift({ id: 'Randomizer ' + RS.seed, seed: RS.seed, on: true, sub: 'On · made just now · OOTRR 0.8.2', settings: 'OOTRR1-AMAQ', spoiler: true, cos: '' });
emit({ t: 'toast', html: '<b>&#9670;</b> Seed <b>' + RS.seed + '</b> is on · start a <b>new game</b> in an empty file', sfx: 'success' });
RS.seed = Math.random().toString(36).slice(2, 10).toUpperCase(); emit({ t: 'state', randoMade: 1 });
}
rando();
}, 700);
rando();
}
else if (c === 'rando.stop') { clearInterval(st.packTimer); RS.busy = false; RS.line = ''; emit({ t: 'toast', html: 'Stopped · no seed was made' }); rando(); }
else if (c === 'rando.use') { RS.seeds.forEach(x => { x.on = x.id === m.id; x.sub = x.sub.replace(/^(On|Off)/, x.on ? 'On' : 'Off'); }); rando(); }
else if (c === 'rando.off') { RS.seeds.forEach(x => { x.on = false; x.sub = x.sub.replace(/^On/, 'Off'); }); rando(); }
else if (c === 'rando.remove') { RS.seeds = RS.seeds.filter(x => x.id !== m.id); rando(); }
else if (c === 'rando.spoiler') emit({ t: 'ask', title: 'Open the spoiler log?', html: '<p>It lists where every item of this seed is, and one way through the game. Open it only if you want to know.</p>', reply: 'rando.spoiler.go', buttons: [{ id: 'no', label: 'Keep it closed' }, { id: 'go', label: 'Open it', main: true }], ctx: m.id });
else if (c.startsWith('rando.')) emit({ t: 'toast', html: c + ' <span style="color:var(--text3)">· the launcher does this</span>' });
else if (c === 'bench') bench();
else if (c === 'benchstop') { clearInterval(st.timer); emit({ t: 'bench', phase: 'stopped' }); }
else if (c === 'benchapply') { emit({ t: 'go', s: 'settings' }); emit({ t: 'toast', html: '<b>&#9670;</b> Applied · they take effect the next time you play', sfx: 'success' }); }

View File

@@ -76,7 +76,7 @@
</section>
<!-- ============ SAVES ============ -->
<section class="screen" id="s-saves" data-first="sc0" data-back="home" data-tab="2">
<section class="screen" id="s-saves" data-first="sc0" data-back="home" data-tab="3">
<div class="scene"><div class="img" id="savesImg" style="filter:blur(26px) saturate(1.1) brightness(.5)"></div><div class="grade"></div><div class="grain"></div></div>
<div style="position:absolute;left:64px;top:96px"><div class="cont" style="position:static;width:auto"><div class="eb" id="savesEb"></div><h1 style="font-size:54px">Your files</h1></div></div>
<div class="sgrid" id="sgrid"></div>
@@ -96,8 +96,17 @@
<div class="modnote" id="modNote"></div>
</section>
<!-- ============ RANDOMIZER (rando.js; launcher/App/Backend.Randomizer.cs) ============ -->
<section class="screen" id="s-rando" data-first="rt-0" data-back="home" data-tab="2">
<div class="scene"><div class="img" id="randoImg" style="filter:blur(26px) saturate(1.1) brightness(.45)"></div><div class="grade"></div><div class="grain"></div></div>
<div style="position:absolute;left:64px;top:96px"><div class="cont" style="position:static;width:auto"><div class="eb" id="randoEb">Shuffle the items &#183; every seed can be finished</div><h1 style="font-size:54px">Randomizer</h1></div></div>
<div class="settabs" id="randoTabs"></div>
<div class="set rset" id="rando"></div>
<div class="rside"><div class="benchcard fbox rcard" id="randoCard"></div><div class="rtip fbox" id="randoTip"></div></div>
</section>
<!-- ============ SETTINGS ============ -->
<section class="screen" id="s-settings" data-first="row0" data-back="home" data-tab="3">
<section class="screen" id="s-settings" data-first="row0" data-back="home" data-tab="4">
<div class="scene"><div class="img" id="setImg" style="filter:blur(26px) saturate(1.1) brightness(.45)"></div><div class="grade"></div><div class="grain"></div></div>
<div style="position:absolute;left:64px;top:96px"><div class="cont" style="position:static;width:auto"><div class="eb" id="setEb">The launcher and your game</div><h1 style="font-size:54px">Settings</h1></div></div>
<div class="settabs" id="setTabs"></div>
@@ -116,7 +125,7 @@
</section>
<!-- ============ BENCHMARK RESULTS ============ -->
<section class="screen" id="s-bench" data-first="applyBtn" data-back="settings" data-tab="3">
<section class="screen" id="s-bench" data-first="applyBtn" data-back="settings" data-tab="4">
<div class="scene"><div class="img" id="benchImg" style="filter:blur(26px) saturate(1.1) brightness(.5)"></div><div class="grade"></div><div class="grain"></div></div>
<div style="position:absolute;left:64px;top:96px"><div class="cont" style="position:static;width:auto"><div class="eb" id="benchEb"></div><h1 style="font-size:54px">Your best settings</h1></div></div>
<div class="bench"><div><div class="places" id="places"></div>
@@ -129,7 +138,7 @@
<!-- ============ shared: the bar, the sound panel, the sheet ============ -->
<div class="bar" id="bar"><div class="brand flair"><div class="mark"></div><span>Triforce</span></div>
<div class="nav" id="nav"><a data-f data-go="home">Play</a><a data-f data-go="mods">Mods</a><a data-f data-go="saves">Saves</a><a data-f data-go="settings">Settings</a></div>
<div class="nav" id="nav"><a data-f data-go="home">Play</a><a data-f data-go="mods">Mods</a><a data-f data-go="rando">Randomizer</a><a data-f data-go="saves">Saves</a><a data-f data-go="settings">Settings</a></div>
<div class="grow"></div><div class="state" id="pill"></div>
<div class="spk on" id="spk" data-f data-act="vol"><svg viewBox="0 0 24 24"><path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M15.5 9a4.5 4.5 0 0 1 0 6M18 6.5a8 8 0 0 1 0 11"/></svg></div>
<div class="wc"><span data-act="win:min"><svg viewBox="0 0 12 12"><path d="M1 6.5h10"/></svg></span><span data-act="win:max"><svg viewBox="0 0 12 12"><rect x="1.5" y="1.5" width="9" height="9"/></svg></span><span data-act="win:close"><svg viewBox="0 0 12 12"><path d="M1.5 1.5l9 9M10.5 1.5l-9 9"/></svg></span></div></div>
@@ -148,4 +157,5 @@
<div id="jump"></div>
<script src="demo.js"></script>
<script src="app.js"></script>
<script src="rando.js"></script>
</body></html>

202
launcher/ui/rando.js Normal file
View File

@@ -0,0 +1,202 @@
/* ((Triforce, 11-25) The Randomizer page: OOTRR's seeds (launcher/App/Backend.Randomizer.cs). The launcher sends state.rando:
tool {have, version, size, busy, frac, line}, game, busy, line, seed, cos {music, sfx, colors, title}, preset, changed,
rows {<id>: {st: open|held|hidden, v, show, max?, why?}}, seeds [{id, seed, on, sub, settings, spoiler, cos}], note,
schema {prefix, groups [{id,label,tip}], presets [{id,name,tip}], settings [{id,label,group,kind,tip,tag,unsupported,choices?,min?,max?,step?}]}
(the schema once per OOTRR release; the rows each time). Tabs: New seed, OOTRR's own groups, Your seeds. Everything this page
changes goes back as rando.* commands; the launcher answers with the state again. Uses app.js's $, S, ACTIONS, cmd, sheets. */
'use strict';
S.rtab = 'new';
const RCOS = {
music: { label: 'Music', opts: [['off', 'Off', 'The game\'s own music where it always plays'], ['grouped', 'Shuffled within its kind', 'Area themes trade with area themes, fanfares with fanfares'], ['anywhere', 'Shuffled anywhere', 'Any track can play anywhere']] },
sfx: { label: 'Sound effects', opts: [['off', 'Off', 'Every sound as it comes'], ['grouped', 'Shuffled within its kind', 'Sounds trade with sounds of the same kind'], ['anywhere', 'Shuffled anywhere', 'Any sound can stand for any other']] },
colors: { label: 'Colors', opts: [['off', 'Off', 'Tunics and gear in their own colors'], ['random', 'Random', 'Tunics, gauntlets and trails in colors drawn from the seed']] },
};
function rSchema() { return S.randoSchema || null; }
/* a number as the row shows it: a multiple (OOTRR's "times") as 1.5x, else the number */
function rNum(x, v) { return x && x.times ? (v / x.times).toFixed(2).replace(/\.?0+$/, '') + '\u00d7' : String(v); }
function rSetting(id) { const s = rSchema(); return s ? s.settings.find(x => x.id === id) : null; }
/* a description as OOTRR wrote it, its paragraphs kept (shown with white-space: pre-line) */
function rTip(s) { return esc(String(s || '').replace(/\r/g, '').replace(/[ \t]+/g, ' ').replace(/ *\n */g, '\n').replace(/\n{3,}/g, '\n\n').trim()); }
function drawRandoTabs() {
const s = rSchema(), r = S.rando || {};
const tabs = [{ id: 'new', name: 'New seed' }].concat(r.tool && r.tool.have && s ? s.groups.map(g => ({ id: 'g:' + g.id, name: g.label })) : [])
.concat({ id: 'seeds', name: 'Your seeds' + (r.seeds && r.seeds.length ? ' · ' + r.seeds.length : '') });
if (!tabs.some(t => t.id === S.rtab)) S.rtab = 'new';
$('#randoTabs').innerHTML = tabs.map((t, i) => `<span data-f data-act="rtab:${esc(t.id)}" id="rt-${i}" class="${t.id === S.rtab ? 'on' : ''}">${esc(t.name)}</span>`).join('');
const on = tabs.findIndex(t => t.id === S.rtab);
$('#s-rando').dataset.first = 'rt-' + Math.max(0, on);
}
function rRow(id, label, value, act, em, tip, cls) {
return `<div class="row-set${cls ? ' ' + cls : ''}" data-f data-act="${esc(act)}" id="rr-${esc(id)}" data-tip="${tip || ''}"><b>${esc(label)}</b><span>${esc(value)}</span><em>${esc(em)}</em></div>`;
}
function drawRandoNew(r) {
const s = rSchema();
// (OOTRR is there but its settings could not be read: said, with a way to try again)
if (r.tool && r.tool.have && !s && r.schemaError) return `<p class="gnote rnote rbad">OOTRR's settings could not be read: ${esc(r.schemaError)}</p>` +
rRow('retry', 'Read them again', 'Ask OOTRR for its settings once more', 'rando.open', 'Try again', rTip('If it keeps failing, the launcher\'s log says more (Settings, Log folder).'));
if (r.tool && r.tool.have && !s) return '<p class="gnote">Reading OOTRR\'s settings…</p>';
if (!r.tool || !r.tool.have || !s) return `<p class="gnote">${r.tool && r.tool.busy ? 'Getting the randomizer…' : 'Get the randomizer to choose its settings. It is a download of ' + esc(r.tool ? r.tool.size : '5 MB') + ', once.'}</p>`;
const preset = s.presets.find(p => p.id === r.preset);
const cos = r.cos || {};
const cosShow = k => (RCOS[k].opts.find(o => o[0] === cos[k]) || RCOS[k].opts[0])[1];
return '<h4>Settings</h4>' +
rRow('preset', 'Preset', preset ? preset.name : 'Custom · ' + (r.changed || 0) + ' changed from OOTRR\'s defaults', 'rpreset', 'Change', rTip(preset ? preset.tip : 'Your own choice of settings: every tab above shows them.')) +
rRow('string', 'Settings string', 'Paste one to play the same settings as someone else', 'rpaste', 'Paste', rTip('A settings string (it starts with ' + (s.prefix || 'OOTRR1-') + ') sets every setting at once. Your seeds give theirs: Your seeds, then a seed, then Copy settings string.')) +
'<h4>Seed</h4>' +
rRow('seed', 'Seed', r.seed || '(a random one)', 'rseedtext', 'Change', rTip('The same seed with the same settings and OOTRR version makes the same game on every PC: share both for a race.')) +
rRow('reseed', 'New random seed', 'Draw another seed text', 'rando.reseed', 'Draw', rTip('Eight letters and digits, drawn at random.')) +
'<h4>Cosmetics</h4>' +
['music', 'sfx', 'colors'].map(k => rRow('cos-' + k, RCOS[k].label, cosShow(k), 'rcos:' + k, 'Change', rTip(RCOS[k].opts.map(o => o[1] + ': ' + o[2]).join('. ')))).join('') +
rRow('cos-title', 'Title screen', cos.title === false ? 'As it comes' : 'Says Randomizer under the logo', 'rcostitle', cos.title === false ? 'Turn on' : 'Turn off', rTip('OOTRR writes a Randomizer line under the game\'s logo, so a seed is easy to tell from the plain game.')) +
'<h4>About</h4>' +
rRow('about', 'OOTRR ' + r.tool.version, 'The Ocarina of Time Remake Randomizer, by its own team · free software (GPL-3.0)', 'rando.page', 'Its page', rTip('Triforce runs OOTRR\'s own program. Its logic comes from the OoT Randomizer for the N64 game. Report a seed that cannot be finished on its page.'));
}
function drawRandoGroup(r, group) {
const s = rSchema(); if (!s || !r.rows) return '';
const list = s.settings.filter(x => x.group === group && r.rows[x.id] && r.rows[x.id].st !== 'hidden');
if (!list.length) return '<p class="gnote">Nothing to set here with the settings as they are.</p>';
const g = s.groups.find(x => x.id === group);
return (g && g.tip ? `<p class="gnote">${esc(g.tip)}</p>` : '') + list.map(x => {
const row = r.rows[x.id], held = row.st === 'held', soon = !!x.unsupported;
const tip = rTip(x.tip + (held ? ' (' + row.why + ')' : '') + (soon ? ' (OOTRR\'s build does not apply this one yet.)' : ''));
const cls = held || soon || (x.noOn && !row.v) ? 'off' : '';
if (x.kind === 'number' && !held && !soon) {
const hi = row.max != null ? row.max : x.max, v = Math.min(+row.v, hi), p = hi > x.min ? (v - x.min) / (hi - x.min) * 100 : 0;
return `<div class="row-set gs" style="cursor:default" data-tip="${tip}"><b>${esc(x.label)}</b><div class="rng"><div class="slider" data-f data-rkey="${esc(x.id)}" data-lo="${x.min}" data-hi="${hi}" data-step="${x.step || 1}" data-v="${v}"${x.times ? ` data-times="${x.times}"` : ''} id="rr-${esc(x.id)}" data-tip="${tip}"><i style="width:${p}%"></i><u style="left:${p}%"></u></div><span class="gval">${esc(rNum(x, v))}</span></div><em></em></div>`;
}
const em = held ? 'Held' : soon ? 'Not yet' : x.kind === 'toggle' ? (row.v ? 'Turn off' : 'Turn on') : 'Change';
const act = held || soon || (x.noOn && !row.v) ? 'rnone' : x.kind === 'toggle' ? 'rtog:' + x.id : x.kind === 'multi' ? 'rmulti:' + x.id : 'rchoice:' + x.id;
return rRow(x.id, x.label, row.show, act, em, tip, cls);
}).join('');
}
function drawRandoSeeds(r) {
const seeds = r.seeds || [];
if (!seeds.length) return `<p class="gnote">${r.game ? 'No seeds yet. Make one on New seed: it goes into your mods folder, on.' : esc(r.note || '')}</p>`;
return '<div class="rseeds">' + seeds.map((x, i) => `<div class="mod" data-f data-act="rseed:${i}" id="rs${i}" data-tip="${rTip(x.cos ? 'Cosmetics: ' + x.cos : '')}"><div class="mi rmi${x.on ? ' on' : ''}"></div>` +
`<div class="rsn"><b>Seed ${esc(x.seed)}</b><span>${esc(x.sub)}</span></div>${x.on ? '<em class="inst">&#9670; On</em>' : '<em class="offm">Off</em>'}</div>`).join('') + '</div>';
}
function drawRandoCard(r) {
const t = r.tool || {}, card = $('#randoCard');
if (!t.have) {
const pct = Math.round((t.frac || 0) * 100);
card.innerHTML = '<h3>Get the randomizer</h3><p>OOTRR shuffles where the items are, and makes sure every seed can be finished. Triforce downloads its program once (' + esc(t.size || '') + ') and checks it before it runs.</p>' +
(t.busy ? `<div class="rbar"><i style="width:${pct}%"></i></div><p class="rline">${esc(t.line || 'Downloading')}</p>`
: `<div class="play sm" style="width:100%;font-size:23px;height:52px" data-f id="randoGet" data-act="rando.install">Download</div>`);
return;
}
const s = rSchema(), preset = s && s.presets.find(p => p.id === r.preset);
card.innerHTML = `<h3>Seed <span class="rseedt">${esc(r.seed || '')}</span></h3>` +
`<p>${esc(preset ? preset.name : 'Custom settings')} · ${r.changed || 0} changed from OOTRR's defaults</p>` +
(r.busy ? `<div class="rbar busy"><i></i></div><p class="rline">${esc(r.line || 'Working')}</p><div class="qbtn" style="width:100%" data-f id="randoStop" data-act="rando.stop">Stop</div>`
: (r.problem ? `<p class="rproblem">OOTRR cannot make these settings yet: ${esc(r.problem)}</p>` : '') +
`<div class="play sm${r.game && s && !r.problem ? '' : ' off'}" style="width:100%;font-size:23px;height:52px" data-f id="randoMake" data-act="rando.make" data-big>Make the seed</div>`) +
`<p class="rsmall">It goes into your mods folder, on, with your other seeds off. Start a new game in an empty file to play it.</p>` +
((r.seeds || []).some(x => x.on) ? `<p class="rsmall"><span class="lnk" data-f data-act="rando.off" id="randoOff">Turn every seed off</span> to play the game as it comes.</p>` : '');
}
function drawRando() {
const r = S.rando; if (!r) return;
// (a slider being dragged, or one whose value is on its way, is not drawn over: the launcher's answer draws the page then)
if (S.rDrag || S.rSend) { S.rPending = true; return; }
S.rPending = false;
drawRandoTabs();
const keep = focused && focused.id;
const body = S.rtab === 'new' ? drawRandoNew(r) : S.rtab === 'seeds' ? drawRandoSeeds(r) : drawRandoGroup(r, S.rtab.slice(2));
$('#rando').innerHTML = body + (r.note && S.rtab !== 'seeds' ? `<p class="gnote rnote">${esc(r.note)}</p>` : '');
drawRandoCard(r);
$('#randoEb').textContent = r.tool && r.tool.have ? 'OOTRR ' + r.tool.version + ' · every seed can be finished' : 'Shuffle the items · every seed can be finished';
if (keep && $('#' + keep) && screen === 'rando') { focused = null; setFocus($('#' + keep)); }
else if (screen === 'rando' && (!focused || !document.contains(focused))) { focused = null; setFocus($('#' + $('#s-rando').dataset.first)); }
}
/* the focused row's tip, under the list (mouse, keyboard and controller alike) */
function randoFocus(el) {
const box = $('#randoTip'); if (!box) return;
const tip = el && el.closest && el.closest('#s-rando') ? (el.dataset.tip || (el.closest('[data-tip]') || {}).dataset?.tip || '') : null;
if (tip == null) return;
// (data-tip comes back as plain text, the attribute's escaping undone: it is escaped again here, as OOTRR's words and a seed's
// file may hold anything)
const row = el.closest('.row-set, .mod'), name = row && row.querySelector('b') ? row.querySelector('b').textContent : '';
box.innerHTML = tip ? `<div class="rtipin">${name ? `<b>${esc(name)}</b>` : ''}<p>${esc(tip)}</p></div>` : '';
box.classList.toggle('on', !!tip);
}
/* ---------------- sheets ---------------- */
function openInput(title, text, value, reply, placeholder, max) {
openSheet(`<h3>${esc(title)}</h3><p>${text}</p><div class="search rin"><input data-f id="rIn" spellcheck="false" autocomplete="off" maxlength="${max || 4000}" placeholder="${esc(placeholder || '')}" value="${esc(value || '')}"></div>` +
`<div class="acts"><span class="qlink" data-f data-act="closesheet" data-back-sound>Cancel</span><div class="play sm" style="width:200px" data-f id="rInOk" data-act="rinok">OK</div></div>`, 'rIn');
S.rInReply = reply;
const inp = $('#rIn');
inp.addEventListener('keydown', e => {
if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); ACTIONS.rinok(); }
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeSheet(); }
else if (e.key === 'ArrowDown') { e.preventDefault(); e.stopPropagation(); inp.blur(); setFocus($('#rInOk'), true); }
else e.stopPropagation();
});
setTimeout(() => { inp.focus(); inp.select(); }, 30);
}
ACTIONS.rinok = () => { const v = ($('#rIn') || {}).value || ''; const reply = S.rInReply; closeSheet(true); if (reply) cmd(reply, { text: v }); };
function rChoiceSheet(title, text, options, reply, ctx, ok) {
const at = Math.max(0, options.findIndex(o => o.sel));
const opts = options.map((o, i) => `<div class="opt ropt${o.sel ? ' sel' : ''}${o.dim ? ' dim' : ''}" data-f data-act="opt" data-id="${esc(o.id)}" id="op${i}">` +
`<div><b>${esc(o.name)}</b>${o.note ? `<em>${esc(o.note)}</em>` : ''}${o.sub ? `<span class="rdesc">${esc(o.sub)}</span>` : ''}</div><span></span></div>`).join('');
openSheet(`<h3>${esc(title)}</h3>${text ? `<div class="rintro">${text}</div>` : ''}<div class="ropts" id="rOpts">${opts}</div>` +
`<div class="acts"><span class="qlink" data-f data-act="closesheet" data-back-sound>Cancel</span><div class="play sm" style="width:220px" data-f data-act="rchoiceok" id="rChoiceOk">${esc(ok || 'Choose')}</div></div>`, 'op' + at);
S.rChoice = { reply, ctx };
const sel = $('#op' + at); if (sel) sel.scrollIntoView({ block: 'nearest' });
}
ACTIONS.rchoiceok = () => { const o = $('.opt.sel', $('#sheet')), c = S.rChoice; closeSheet(true); if (o && c) cmd(c.reply, { id: o.dataset.id, ctx: c.ctx }); };
function openMulti(x, row) {
const picked = new Set(Array.isArray(row.v) ? row.v : []);
const described = x.choices.some(c => c.tip);
const opts = x.choices.map((c, i) => `<div class="opt${described ? ' ropt' : ''}${picked.has(c.id) ? ' sel' : ''}" data-f data-act="mopt" data-id="${esc(c.id)}" id="mo${i}">` +
`<div><b>${esc(c.label)}</b>${described && c.tip ? `<span class="rdesc">${esc(c.tip)}</span>` : ''}</div><span></span></div>`).join('');
openSheet(`<h3>${esc(x.label)} <span class="mcount" id="mCount"></span></h3><div class="rintro">${rTip(x.tip)}</div><div class="${described ? 'ropts' : 'opts many'}">${opts}</div>` +
`<div class="acts"><span class="qlink" data-f data-act="mclear">None</span><span class="qlink" data-f data-act="closesheet" data-back-sound>Cancel</span><div class="play sm" style="width:200px" data-f data-act="mdone" id="mDone">Done</div></div>`, 'mo0');
S.rMulti = x.id;
mCount();
}
/* how many are ticked, beside the sheet's title */
function mCount() { const n = $$('#sheet .opt.sel').length, c = $('#mCount'); if (c) c.textContent = n ? '\u00b7 ' + n + ' chosen' : ''; }
ACTIONS.mopt = (a, el) => { el.classList.toggle('sel'); mCount(); };
ACTIONS.mclear = () => { $$('#sheet .opt').forEach(o => o.classList.remove('sel')); mCount(); };
ACTIONS.mdone = () => { const v = $$('#sheet .opt.sel').map(o => o.dataset.id); const id = S.rMulti; closeSheet(true); cmd('rando.set', { id, value: v }); };
function openSeedSheet(i) {
const x = ((S.rando || {}).seeds || [])[i]; if (!x) return;
openSheet(`<h3>Seed ${esc(x.seed)}</h3><p>${esc(x.sub)}${x.cos ? ' · ' + esc(x.cos) : ''}</p>` +
`<div class="asktext"><p>${x.on ? 'This seed is on: the game plays it from its next start. Saves you make now belong to it: play them only with it on.' : 'Turning it on turns your other seeds off. Start a new game in an empty file, or load a save you made with this seed.'}</p></div>` +
`<div class="acts rsacts"><span class="qlink" data-f data-act="closesheet">Close</span>` +
(x.spoiler ? `<span class="qlink" data-f data-act="rsgo:spoiler">Spoiler log</span>` : '') +
(x.settings ? `<span class="qlink" data-f data-act="rsgo:copy">Copy settings string</span>` : '') +
`<span class="qlink" data-f data-act="rsgo:folder">Its folder</span><span class="qlink" data-f data-act="rsgo:remove">Remove</span>` +
(x.on ? `<div class="play sm" style="width:200px" data-f data-act="rsoff" id="sh1">Turn off</div>` : `<div class="play sm" style="width:200px" data-f data-act="rsgo:use" id="sh1">Turn on</div>`) + '</div>', 'sh1');
// (the seed by its folder, not its place in the list: a seed made or removed while the sheet is open moves the others)
S.rSheetSeed = x.id;
}
/* ---------------- actions ---------------- */
ACTIONS.rtab = (t) => { S.rtab = t; drawRando(); $('#rando').scrollTop = 0; const i = $$('#randoTabs span').findIndex(s => s.dataset.act === 'rtab:' + t); setFocus($('#rt-' + Math.max(0, i))); };
ACTIONS.rnone = () => sfx('error');
ACTIONS.rtog = (id) => { const row = S.rando.rows[id]; if (row) cmd('rando.set', { id, value: !row.v }); };
ACTIONS.rchoice = (id) => {
const x = rSetting(id), row = S.rando.rows[id]; if (!x || !row) return;
// (an option OOTRR's build cannot apply yet is listed, marked, and refused by the launcher if chosen)
rChoiceSheet(x.label, rTip(x.tip), x.choices.map(c => ({ id: c.id, name: c.label, note: c.live === false ? 'Not in this OOTRR yet' : '', dim: c.live === false, sub: c.tip, sel: c.id === row.v })), 'rando.pick', id);
};
ACTIONS.rmulti = (id) => { const x = rSetting(id), row = S.rando.rows[id]; if (x && row) openMulti(x, row); };
ACTIONS.rpreset = () => {
const s = rSchema(); if (!s) return;
rChoiceSheet('Preset', 'OOTRR\'s own starting points. Every setting can still be changed after.', s.presets.map(p => ({ id: p.id, name: p.name, sub: p.tip, sel: p.id === S.rando.preset })), 'rando.preset.pick', '', 'Use it');
};
ACTIONS.rpaste = () => openInput('Paste a settings string', 'It sets every setting at once, as the seed it came from had them.', '', 'rando.decode', (rSchema() || {}).prefix ? rSchema().prefix + '…' : 'OOTRR1-…');
ACTIONS.rseedtext = () => openInput('Seed', 'Any text, up to ' + (S.rando.maxSeed || 200) + ' letters: the same text with the same settings and OOTRR makes the same seed. Leave it empty for a random one.', S.rando.seed || '', 'rando.seed', 'A word, a date, anything', S.rando.maxSeed || 200);
ACTIONS.rcos = (k) => { const c = RCOS[k]; if (!c) return; rChoiceSheet(c.label, 'Applied when the seed\'s files are written.', c.opts.map(o => ({ id: o[0], name: o[1], sub: o[2], sel: o[0] === (S.rando.cos || {})[k] })), 'rando.cos.pick', k); };
ACTIONS.rcostitle = () => cmd('rando.cos', { key: 'title', value: (S.rando.cos || {}).title === false ? 'on' : 'off' });
ACTIONS.rseed = (i) => openSeedSheet(+i);
ACTIONS.rsgo = (what) => { const id = S.rSheetSeed; closeSheet(true); if (id) cmd('rando.' + what, { id }); };
ACTIONS.rsoff = () => { closeSheet(true); cmd('rando.off'); };