mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
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:
202
launcher/ui/rando.js
Normal file
202
launcher/ui/rando.js
Normal 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">◆ 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'); };
|
||||
Reference in New Issue
Block a user