Add puzzle hints and per-word descriptions with sources
Hint is revealed on demand below the board while playing. After the game ends, each word's description and source link are listed below the puzzle, and hovering a solved word highlights its entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4a2309b589
commit
b2f8e879ab
7 changed files with 141 additions and 21 deletions
|
|
@ -49,11 +49,12 @@ function showLogin(error) {
|
|||
}
|
||||
|
||||
function showEditor(game) {
|
||||
const g = game || { title: '', date: '', groups: COLORS.map((color) => ({ name: '', color, words: ['', '', '', ''] })) };
|
||||
const g = game || { title: '', date: '', hint: '', groups: COLORS.map((color) => ({ name: '', color, words: ['', '', '', ''] })) };
|
||||
const field = (id, label, input, help) =>
|
||||
el('div', { class: 'field' }, el('label', { for: id }, label), input, help ? el('p', { class: 'help' }, help) : null);
|
||||
const title = el('input', { id: 'title', value: g.title, maxlength: 100, required: true });
|
||||
const date = el('input', { id: 'date', type: 'date', value: g.date || '' });
|
||||
const hint = el('input', { id: 'hint', value: g.hint || '', maxlength: 200 });
|
||||
const errBox = el('div');
|
||||
|
||||
const groupEls = g.groups.map((grp, i) => {
|
||||
|
|
@ -61,14 +62,21 @@ function showEditor(game) {
|
|||
const name = el('input', { id: `g${n}-name`, value: grp.name, maxlength: 80, required: true });
|
||||
const color = el('select', { id: `g${n}-color` }, COLORS.map((c) => el('option', { value: c, selected: c === grp.color }, c[0].toUpperCase() + c.slice(1))));
|
||||
const words = grp.words.map((w, j) => el('input', { value: w, maxlength: 30, required: true, 'aria-label': `Group ${n} word ${j + 1}` }));
|
||||
const descs = grp.words.map((_, j) => el('input', { value: grp.details?.[j]?.description || '', maxlength: 500, placeholder: 'Description (optional)', 'aria-label': `Group ${n} word ${j + 1} description` }));
|
||||
const sources = grp.words.map((_, j) => el('input', { type: 'url', value: grp.details?.[j]?.source || '', maxlength: 500, placeholder: 'https://source (optional)', 'aria-label': `Group ${n} word ${j + 1} source link` }));
|
||||
const box = el('fieldset', { class: 'group-edit' },
|
||||
el('legend', { class: 'sr' }, `Group ${n}`),
|
||||
el('div', { class: 'head' },
|
||||
field(`g${n}-name`, el('span', {}, el('span', { class: `swatch ${grp.color}` }), `Group ${n} name`), name),
|
||||
field(`g${n}-color`, 'Color', color)),
|
||||
el('label', {}, 'Words'), el('div', { class: 'words' }, words));
|
||||
el('label', {}, 'Words'),
|
||||
el('p', { class: 'help', style: 'margin-bottom:8px' }, 'Descriptions and sources show below the puzzle once it ends.'),
|
||||
el('div', { class: 'words' }, words.map((w, j) => el('div', { class: 'word-row' }, w, descs[j], sources[j]))));
|
||||
color.addEventListener('change', () => { box.querySelector('.swatch').className = `swatch ${color.value}`; });
|
||||
return { box, read: () => ({ name: name.value, color: color.value, words: words.map((w) => w.value) }) };
|
||||
return { box, read: () => ({
|
||||
name: name.value, color: color.value, words: words.map((w) => w.value),
|
||||
details: words.map((_, j) => ({ description: descs[j].value, source: sources[j].value })),
|
||||
}) };
|
||||
});
|
||||
|
||||
$app.replaceChildren(
|
||||
|
|
@ -78,7 +86,7 @@ function showEditor(game) {
|
|||
el('form', { novalidate: true, onsubmit: async (e) => {
|
||||
e.preventDefault();
|
||||
const btn = e.submitter; btn.disabled = true;
|
||||
const body = { title: title.value, date: date.value || null, groups: groupEls.map((x) => x.read()) };
|
||||
const body = { title: title.value, date: date.value || null, hint: hint.value, groups: groupEls.map((x) => x.read()) };
|
||||
const { ok, data } = await api(game ? `/api/admin/games/${game.id}` : '/api/admin/games', { method: game ? 'PUT' : 'POST', body });
|
||||
btn.disabled = false;
|
||||
if (ok) { toast('Saved'); return showList(); }
|
||||
|
|
@ -89,6 +97,7 @@ function showEditor(game) {
|
|||
errBox,
|
||||
field('title', 'Title', title),
|
||||
field('date', 'Date', date, 'Optional. The puzzle becomes the daily puzzle on this date.'),
|
||||
field('hint', 'Hint', hint, 'Optional. Players can reveal it below the puzzle while playing.'),
|
||||
groupEls.map((x) => x.box),
|
||||
el('div', { class: 'actions', style: 'justify-content:flex-start' }, el('button', { class: 'btn primary', type: 'submit' }, icon('check'), 'Save puzzle'))),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue