Icons: emoji become glyphs wherever the page draws, board text stays as typed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-04 18:07:03 +00:00
parent 3486897630
commit 842ceaa10e
3 changed files with 123 additions and 8 deletions

View file

@ -55,6 +55,19 @@ function iconise(content) {
for (const entry of entries) if (entry.glyph) entry.icon = glyph(entry.glyph, entry.tint);
return content;
}
// Emoji become glyphs wherever the page is drawn. Not inside tags (a title can't hold an icon), a dropdown
// (nor can an option), or what players typed on the board.
let emojiPattern = null;
function iconed(html) {
if (!C?.emoji_glyphs) return html;
emojiPattern ||= new RegExp(`(<(select|textarea)\\b[\\s\\S]*?</\\2>|<div class="text">[\\s\\S]*?</div>|<(?:[^>"']|"[^"]*"|'[^']*')*>)|(${
Object.keys(C.emoji_glyphs).sort((a, b) => b.length - a.length).join("|")})\\uFE0F?`, "gu");
return html.replace(emojiPattern, (match, keep, _tag, emoji) => {
if (keep) return match;
const [name, tint] = C.emoji_glyphs[emoji];
return glyph(name, tint);
});
}
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
const fmt = (n) => Math.floor(n).toLocaleString("en-GB");
const serverNow = () => Date.now() / 1000 + skew;
@ -170,7 +183,7 @@ const countdown = (t) => `<span data-countdown="${t}"></span>`;
function toast(text, kind = "") {
const el = document.createElement("div");
el.className = "toast " + kind;
el.textContent = text;
el.innerHTML = iconed(esc(text));
$("#toasts").append(el);
setTimeout(() => el.remove(), kind === "level" ? 6000 : 3500);
const keep = matchMedia("(max-width: 900px)").matches ? 2 : 4;
@ -618,7 +631,7 @@ function drawBattle(b, box, t) {
log.dataset.key = `${told}:${t >= b.end}`;
const lines = b.told.slice(Math.max(0, told - 7), told).reverse().map((e) => battleLine(e, b)).filter(Boolean);
if (t >= b.end) lines.unshift(b.won ? `<li class="good"><b>Victory!</b></li>` : `<li class="bad"><b>The line breaks.</b></li>`);
log.innerHTML = lines.slice(0, 7).join("");
log.innerHTML = iconed(lines.slice(0, 7).join(""));
}
// The damage meter: what each of ours has dealt so far, best first.
const meter = $("[data-b-dps]", box), secs = Math.max(1, Math.min(t, b.end) - BATTLE_LEAD);
@ -646,7 +659,7 @@ function battleTold(e, b) {
function openModal(html) {
const modal = $("#modal");
modal.innerHTML = `<div class="modal-box">${html}</div>`;
modal.innerHTML = iconed(`<div class="modal-box">${html}</div>`);
modal.hidden = false;
}
@ -686,7 +699,7 @@ function render() {
function setHtml(el, html) {
if (el.dataset.html === html) return;
const next = document.createElement("template");
next.innerHTML = html;
next.innerHTML = iconed(html);
morphChildren(el, next.content);
el.dataset.html = html;
}
@ -1087,7 +1100,7 @@ function kingdom() {
: full ? `<p class="small muted">${k.cities.length} / ${k.max} towns</p>`
: `<p class="small">${cost}</p>
${S.city.next_tier ? `<p class="small muted">${esc(k.short)}</p>` : `<div class="pouch-row"><input type="text" maxlength="24" placeholder="Town name" data-keep="charter-name">
<select data-keep="charter-region" class="wide">${open.map(([id, r]) => `<option value="${id}">${r.icon} ${esc(r.name)} · ${regionPerks(r, 0.5)}</option>`).join("")}</select>
<select data-keep="charter-region" class="wide">${open.map(([id, r]) => `<option value="${id}">${esc(r.name)} · ${regionPerks(r, 0.5)}</option>`).join("")}</select>
<button class="btn primary" data-charter-new ${k.short ? "disabled" : ""}>📜 Draw up</button></div>`}`;
return `<div class="grid">${towns}</div>
<div class="grid" style="margin-top:14px">
@ -2802,7 +2815,7 @@ function orderPicker(list) {
}).join("");
return `<div class="picker">
<div class="pick-skills">${skills.map((k) => `<button class="pick-skill ${!q && k === d.skill ? "on" : ""}" data-draft-skill="${k}" title="${esc(skillOf(k).name)}">${skillOf(k).icon}</button>`).join("")}
<input type="text" data-keep="order-search" placeholder="🔍" value="${esc(d.search || "")}"></div>
<input type="text" data-keep="order-search" placeholder="Search" value="${esc(d.search || "")}"></div>
${groups.length && !q ? `<div class="tabs sm">${groups.map((g) => `<button class="tab ${g === d.group ? "on" : ""}" data-draft-group="${esc(g)}">${esc(g)}</button>`).join("")}</div>` : ""}
<div class="swap-grid pick-grid">${tiles || `<span class="muted small">—</span>`}</div></div>`;
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 469 KiB

After

Width:  |  Height:  |  Size: 556 KiB

Before After
Before After