Integrate BGS chat and a tabbed journal below the board
This commit is contained in:
parent
2cd5a457be
commit
a4faf61dd0
9 changed files with 587 additions and 15 deletions
|
|
@ -11,6 +11,8 @@ pnpm dev
|
|||
|
||||
Local practice: http://127.0.0.1:5221/ . Lessons start at `/?chapter=drift`.
|
||||
|
||||
Chat and journal preview: `/?chat=1`. This uses the BGS viewer protocol with local messages, unread notifications, mentions and send-failure controls; nothing is sent to other players.
|
||||
|
||||
## Rules and implementation status
|
||||
|
||||
Rules: [Z-Man English rulebook](https://cs.uwaterloo.ca/~dtompkin/archive/dtlib/base/Primordial%20Soup.pdf), [publisher's reference sheets](http://doris-frank.de/download/Ursuppe_Rules.pdf), and [publisher FAQ](http://doris-frank.de/UrsuppeFAQ.html).
|
||||
|
|
|
|||
248
viewer/activity.css
Normal file
248
viewer/activity.css
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
.pond-tools {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
.soup .activity-slot {
|
||||
flex: none;
|
||||
margin-top: 24px;
|
||||
}
|
||||
.soup-activity {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 14px;
|
||||
background: var(--paper);
|
||||
overflow: hidden;
|
||||
font-size: 13px;
|
||||
--activity-height: 320px;
|
||||
--activity-padding: 12px;
|
||||
}
|
||||
.activity-header,
|
||||
.activity-header [role="tablist"] {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.activity-header {
|
||||
justify-content: space-between;
|
||||
padding: 10px 16px 0;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.activity-header [role="tab"] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 10px 12px;
|
||||
border-bottom: 3px solid transparent;
|
||||
color: var(--muted);
|
||||
font-weight: 600;
|
||||
}
|
||||
.activity-header [role="tab"][aria-selected="true"] {
|
||||
color: var(--ink);
|
||||
border-color: #8cb74a;
|
||||
}
|
||||
.activity-header svg,
|
||||
.soup-chat-shortcut > svg {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
}
|
||||
.activity-back {
|
||||
padding: 10px 4px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.soup .chat-count,
|
||||
.soup-chat-shortcut > span {
|
||||
border-radius: 20px;
|
||||
min-width: 20px;
|
||||
padding: 1px 5px;
|
||||
background: #dcebb9;
|
||||
color: var(--ink);
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
}
|
||||
.soup .soup-activity [hidden],
|
||||
.soup .soup-chat-shortcut[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.activity-chat,
|
||||
.activity-journal {
|
||||
height: var(--activity-height);
|
||||
padding: var(--activity-padding) 20px;
|
||||
}
|
||||
.soup-activity .bgs-game-chat {
|
||||
height: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
.soup-activity .chat-body {
|
||||
height: calc(var(--activity-height) - 2 * var(--activity-padding));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
.soup-activity .bgs-game-chat > summary {
|
||||
display: none;
|
||||
}
|
||||
.soup-activity .chat-messages,
|
||||
.soup .soup-activity .journal-list {
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
overflow-anchor: none;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #b7c5a6 transparent;
|
||||
padding: 0 6px 0 0;
|
||||
margin: 0;
|
||||
}
|
||||
.soup-activity .chat-messages {
|
||||
flex: 1;
|
||||
}
|
||||
.soup .soup-activity .journal-list {
|
||||
height: 100%;
|
||||
max-height: none;
|
||||
}
|
||||
.soup-activity article {
|
||||
padding: 9px 0;
|
||||
border-bottom: 1px solid var(--line);
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.65;
|
||||
}
|
||||
.soup-activity article:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.soup-activity .chat-author {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
vertical-align: middle;
|
||||
gap: 6px;
|
||||
padding: 0;
|
||||
font-weight: 700;
|
||||
}
|
||||
.soup-activity .chat-portrait {
|
||||
display: inline-block;
|
||||
width: 23px;
|
||||
height: 23px;
|
||||
}
|
||||
.soup-activity .chat-portrait svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.soup-activity time,
|
||||
.soup-activity .chat-edited {
|
||||
margin-left: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.soup-activity .chat-day {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.soup-activity .chat-day::before,
|
||||
.soup-activity .chat-day::after {
|
||||
content: "";
|
||||
flex: 1;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.soup-activity .chat-day time {
|
||||
margin: 0;
|
||||
}
|
||||
.soup-activity .chat-composer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.soup-activity input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 40px;
|
||||
border: 1px solid #c5d2b8;
|
||||
border-radius: 9px;
|
||||
background: var(--cream);
|
||||
color: var(--ink);
|
||||
font: inherit;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
.soup-activity .chat-composer > button {
|
||||
padding: 10px 18px;
|
||||
border: 1px solid #a4bb7d;
|
||||
border-radius: 9px;
|
||||
background: #dfedc4;
|
||||
font-weight: 600;
|
||||
}
|
||||
.soup-activity .chat-suggestions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.soup-activity .chat-suggestions button {
|
||||
padding: 5px 8px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.soup-activity .chat-suggestions [aria-selected="true"] {
|
||||
background: #dfedc4;
|
||||
}
|
||||
.soup-activity .chat-status {
|
||||
color: #845538;
|
||||
font-size: 12px;
|
||||
}
|
||||
.soup-activity .chat-suggestions:empty,
|
||||
.soup-activity .chat-status:empty {
|
||||
display: none;
|
||||
}
|
||||
.soup-activity article a,
|
||||
.soup-activity .chat-mention {
|
||||
color: var(--ink);
|
||||
text-decoration: underline;
|
||||
}
|
||||
.soup-activity .chat-mention {
|
||||
padding: 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
.soup-activity .chat-empty,
|
||||
.soup-activity .journal-empty {
|
||||
color: var(--muted);
|
||||
}
|
||||
.soup-chat-shortcut {
|
||||
position: fixed;
|
||||
left: max(16px, env(safe-area-inset-left));
|
||||
bottom: max(16px, env(safe-area-inset-bottom));
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 15px;
|
||||
border: 1px solid #809b62;
|
||||
border-radius: 24px;
|
||||
background: var(--dark);
|
||||
color: var(--cream);
|
||||
box-shadow: 0 3px 12px var(--shadow);
|
||||
font-weight: 600;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.soup-activity {
|
||||
--activity-height: 300px;
|
||||
--activity-padding: 10px;
|
||||
}
|
||||
.activity-header {
|
||||
padding: 6px 8px 0;
|
||||
gap: 4px;
|
||||
}
|
||||
.activity-header [role="tab"] {
|
||||
padding: 10px 8px;
|
||||
gap: 5px;
|
||||
}
|
||||
.activity-back {
|
||||
font-size: 11px;
|
||||
}
|
||||
.activity-chat,
|
||||
.activity-journal {
|
||||
padding: 10px 12px;
|
||||
}
|
||||
.soup-activity input {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
181
viewer/activity.js
Normal file
181
viewer/activity.js
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
import { mountChat } from "@boardgamers/protocol/chat/dom";
|
||||
import { amoeba, colors, icon } from "./art.js";
|
||||
import { richText } from "./rich-text.js";
|
||||
|
||||
let sequence = 0;
|
||||
|
||||
export function mountActivity(target, { chat, openPlayer, backToBoard } = {}) {
|
||||
const id = `soup-activity-${++sequence}`;
|
||||
const section = document.createElement("section");
|
||||
section.className = "soup-activity";
|
||||
section.setAttribute("aria-label", "Chat and journal");
|
||||
section.innerHTML = `<header class="activity-header"><div role="tablist" aria-label="Chat and journal">
|
||||
<button type="button" role="tab" id="${id}-chat-tab" aria-controls="${id}-chat" data-tab="chat" ${chat ? "" : "hidden"}>${icon("chat")} Chat <span class="chat-count" hidden></span></button>
|
||||
<button type="button" role="tab" id="${id}-journal-tab" aria-controls="${id}-journal" data-tab="journal">${icon("history")} Journal</button>
|
||||
</div><button type="button" class="text-button activity-back">Back to board ↑</button></header>
|
||||
<div id="${id}-chat" class="activity-chat" role="tabpanel" aria-labelledby="${id}-chat-tab" hidden></div>
|
||||
<div id="${id}-journal" class="activity-journal" role="tabpanel" aria-labelledby="${id}-journal-tab" hidden><ol class="journal-list" tabindex="0" aria-label="Game journal"></ol></div>`;
|
||||
const shortcut = document.createElement("button");
|
||||
shortcut.type = "button";
|
||||
shortcut.className = "soup-chat-shortcut";
|
||||
shortcut.hidden = true;
|
||||
target.append(section, shortcut);
|
||||
const tabs = [...section.querySelectorAll("[data-tab]")];
|
||||
const chatPanel = section.querySelector(".activity-chat");
|
||||
const journalPanel = section.querySelector(".activity-journal");
|
||||
const journal = journalPanel.querySelector("ol");
|
||||
const count = section.querySelector(".chat-count");
|
||||
let active = chat ? "chat" : "journal";
|
||||
let players = [];
|
||||
let identity = "";
|
||||
let journalKey;
|
||||
let following = true;
|
||||
let journalFrame;
|
||||
const events = new AbortController();
|
||||
const eventOptions = { signal: events.signal };
|
||||
|
||||
const chatView =
|
||||
chat &&
|
||||
mountChat(chatPanel, {
|
||||
chat,
|
||||
styles: false,
|
||||
openPlayer,
|
||||
renderAuthor(message) {
|
||||
const author = document.createElement(
|
||||
message.playerIndex !== undefined && openPlayer ? "button" : "strong",
|
||||
);
|
||||
author.className = "chat-author";
|
||||
const player = players[message.playerIndex];
|
||||
if (player && colors[player.color]) {
|
||||
const portrait = document.createElement("span");
|
||||
portrait.className = "chat-portrait";
|
||||
portrait.innerHTML = amoeba(player.color);
|
||||
author.append(portrait);
|
||||
}
|
||||
author.append(
|
||||
document.createTextNode(message.author ?? player?.name ?? "Game"),
|
||||
);
|
||||
if (author.tagName === "BUTTON") {
|
||||
author.type = "button";
|
||||
author.onclick = () => openPlayer(message.playerIndex);
|
||||
}
|
||||
return author;
|
||||
},
|
||||
});
|
||||
if (chatView) {
|
||||
const body = document.createElement("div");
|
||||
body.className = "chat-body";
|
||||
body.append(
|
||||
...[...chatView.element.children].filter(
|
||||
(child) => child.tagName !== "SUMMARY",
|
||||
),
|
||||
);
|
||||
chatView.element.append(body);
|
||||
}
|
||||
|
||||
function followJournal() {
|
||||
cancelAnimationFrame(journalFrame);
|
||||
journalFrame = requestAnimationFrame(() => {
|
||||
if (active === "journal" && following)
|
||||
journal.scrollTop = journal.scrollHeight;
|
||||
});
|
||||
}
|
||||
function select(kind) {
|
||||
active = kind === "chat" && chat ? "chat" : "journal";
|
||||
for (const tab of tabs) {
|
||||
tab.setAttribute("aria-selected", String(tab.dataset.tab === active));
|
||||
tab.tabIndex = tab.dataset.tab === active ? 0 : -1;
|
||||
}
|
||||
chatPanel.hidden = active !== "chat";
|
||||
journalPanel.hidden = active !== "journal";
|
||||
chat?.setOpen(active === "chat");
|
||||
followJournal();
|
||||
}
|
||||
function open(kind) {
|
||||
select(kind);
|
||||
section.scrollIntoView({ block: "center" });
|
||||
if (active === "chat") chatView.open();
|
||||
else journal.focus({ preventScroll: true });
|
||||
}
|
||||
for (const tab of tabs) {
|
||||
tab.addEventListener("click", () => select(tab.dataset.tab), eventOptions);
|
||||
tab.addEventListener(
|
||||
"keydown",
|
||||
(event) => {
|
||||
const shown = tabs.filter((item) => !item.hidden);
|
||||
const index = shown.indexOf(tab);
|
||||
const next = {
|
||||
ArrowRight: (index + 1) % shown.length,
|
||||
ArrowLeft: (index + shown.length - 1) % shown.length,
|
||||
Home: 0,
|
||||
End: shown.length - 1,
|
||||
}[event.key];
|
||||
if (next === undefined) return;
|
||||
event.preventDefault();
|
||||
select(shown[next].dataset.tab);
|
||||
shown[next].focus();
|
||||
},
|
||||
eventOptions,
|
||||
);
|
||||
}
|
||||
section
|
||||
.querySelector(".activity-back")
|
||||
.addEventListener("click", backToBoard, eventOptions);
|
||||
shortcut.addEventListener("click", () => open("chat"), eventOptions);
|
||||
journal.addEventListener(
|
||||
"scroll",
|
||||
() => {
|
||||
if (journal.clientHeight)
|
||||
following =
|
||||
journal.scrollHeight - journal.scrollTop - journal.clientHeight < 32;
|
||||
},
|
||||
{ ...eventOptions, passive: true },
|
||||
);
|
||||
|
||||
const unsubscribe = chat?.subscribe((snapshot) => {
|
||||
const unread = snapshot.unreadIds.length;
|
||||
count.hidden = !unread;
|
||||
count.textContent = unread;
|
||||
count.setAttribute("aria-label", `${unread} unread messages`);
|
||||
shortcut.hidden = !unread;
|
||||
shortcut.innerHTML = `${icon("chat")} Chat <span>${unread}</span>`;
|
||||
shortcut.setAttribute(
|
||||
"aria-label",
|
||||
`Open chat, ${unread} unread message${unread === 1 ? "" : "s"}`,
|
||||
);
|
||||
});
|
||||
select(active);
|
||||
return {
|
||||
open,
|
||||
update(state) {
|
||||
players = state.players;
|
||||
const nextIdentity = JSON.stringify(
|
||||
players.map(({ name, color }) => [name, color]),
|
||||
);
|
||||
if (nextIdentity !== identity) {
|
||||
identity = nextIdentity;
|
||||
chatView?.refresh();
|
||||
}
|
||||
const lines = state.log.slice(-150);
|
||||
const key = JSON.stringify(lines);
|
||||
if (key === journalKey) return;
|
||||
journalKey = key;
|
||||
journal.innerHTML =
|
||||
lines
|
||||
.map(
|
||||
(line) =>
|
||||
`<li><small>Round ${Number(line.round)}</small><span>${richText(line.text)}</span></li>`,
|
||||
)
|
||||
.join("") || '<li class="journal-empty">No moves yet.</li>';
|
||||
followJournal();
|
||||
},
|
||||
destroy() {
|
||||
events.abort();
|
||||
cancelAnimationFrame(journalFrame);
|
||||
unsubscribe?.();
|
||||
chatView?.destroy();
|
||||
section.remove();
|
||||
shortcut.remove();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ const iconPaths = {
|
|||
"sound-off": '<path d="M11 4 6 8H3v8h3l5 4Zm5 5 6 6m-6 0 6-6"/>',
|
||||
sound: '<path d="M11 4 6 8H3v8h3l5 4Zm4 4q4 4 0 8m3-11q7 7 0 14"/>',
|
||||
history: '<path d="M3 10a9 9 0 1 1 1 7M3 4v6h6m3-4v6l4 2"/>',
|
||||
chat: '<path d="M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 3V6a2 2 0 0 1 2-2Z"/><path d="M7 9h10M7 13h6"/>',
|
||||
spark: '<path d="m12 2 3 7 7 3-7 3-3 7-3-7-7-3 7-3Z"/>',
|
||||
wave: '<path d="M2 8q3-5 7 0t7 0 6 0M2 15q3-5 7 0t7 0 6 0"/>',
|
||||
arrow: '<path d="M4 12h16m-6-6 6 6-6 6"/>',
|
||||
|
|
|
|||
112
viewer/chat-preview.js
Normal file
112
viewer/chat-preview.js
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import * as E from "../engine/index.js";
|
||||
import { chatSegments } from "@boardgamers/protocol/chat";
|
||||
import { prepared } from "./tutorials.js";
|
||||
|
||||
export function mountChatPreview(nav) {
|
||||
let state = prepared({ round: 3 });
|
||||
let sequence = 0;
|
||||
let failNext = false;
|
||||
let spectator = false;
|
||||
const emitter = window.primordialSoup.launch("#game");
|
||||
const people = state.players.map((p, i) => ({
|
||||
id: String(i),
|
||||
name: p.name,
|
||||
playerIndex: i,
|
||||
}));
|
||||
const names = new Map(people.map((p) => [p.name, p.id]));
|
||||
const status = document.createElement("span");
|
||||
status.setAttribute("role", "status");
|
||||
status.textContent = "Local chat · messages stay here";
|
||||
function message(playerIndex, text, ago = 0) {
|
||||
return {
|
||||
_id: (++sequence).toString(16).padStart(24, "0"),
|
||||
type: "text",
|
||||
author: state.players[playerIndex].name,
|
||||
playerIndex,
|
||||
text,
|
||||
segments: chatSegments(text, names, true),
|
||||
createdAt: new Date(Date.now() - ago).toISOString(),
|
||||
};
|
||||
}
|
||||
function permissions() {
|
||||
emitter.emit("player", { index: spectator ? undefined : 0 });
|
||||
emitter.emit("chat:state", {
|
||||
canSend: !spectator,
|
||||
reason: spectator ? "not-a-player" : "",
|
||||
mentions: people,
|
||||
});
|
||||
}
|
||||
emitter.on("chat:send", ({ text, requestId }) => {
|
||||
setTimeout(() => {
|
||||
if (failNext) {
|
||||
failNext = false;
|
||||
emitter.emit("chat:result", {
|
||||
requestId,
|
||||
ok: false,
|
||||
error: "Could not send. Try again.",
|
||||
});
|
||||
status.textContent = "Send failed; draft kept";
|
||||
} else {
|
||||
emitter.emit("chat:appended", [message(0, text)]);
|
||||
emitter.emit("chat:result", { requestId, ok: true });
|
||||
status.textContent = "Message sent locally";
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
emitter.on("chat:read", () => {
|
||||
status.textContent = "Read receipt received locally";
|
||||
});
|
||||
emitter.on("player:clicked", ({ index }) => {
|
||||
status.textContent = `Player link: ${state.players[index].name}`;
|
||||
});
|
||||
emitter.on("move", (move) => {
|
||||
state = E.move(state, move, 0);
|
||||
emitter.emit("state", E.stripSecret(state));
|
||||
});
|
||||
const controls = [
|
||||
[
|
||||
"Receive message",
|
||||
() =>
|
||||
emitter.emit("chat:appended", [
|
||||
message(1, "@You Ready for the next round?"),
|
||||
]),
|
||||
],
|
||||
[
|
||||
"Fail next send",
|
||||
() => {
|
||||
failNext = true;
|
||||
status.textContent = "Next send will fail locally";
|
||||
},
|
||||
],
|
||||
[
|
||||
"Toggle spectator",
|
||||
() => {
|
||||
spectator = !spectator;
|
||||
permissions();
|
||||
},
|
||||
],
|
||||
["Refresh position", () => emitter.emit("state", E.stripSecret(state))],
|
||||
];
|
||||
for (const [label, click] of controls) {
|
||||
const button = document.createElement("button");
|
||||
button.textContent = label;
|
||||
button.onclick = click;
|
||||
nav.append(button);
|
||||
}
|
||||
nav.append(status);
|
||||
permissions();
|
||||
emitter.emit("state", E.stripSecret(state));
|
||||
emitter.emit("chat:messages", [
|
||||
message(1, "Good luck, everyone!", 86400000),
|
||||
message(2, "I like the little amoebas.", 86300000),
|
||||
message(0, "Trying Movement I this time.", 86200000),
|
||||
message(3, "@Maya The gene pool explains each ability.", 400000),
|
||||
message(1, "Thanks! Saving some BP for division.", 300000),
|
||||
message(2, "The current is going east this round.", 200000),
|
||||
message(
|
||||
3,
|
||||
"Rules: https://boardgamers.space/page/primordial-soup/rules",
|
||||
100000,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import "./style.css";
|
||||
import { registerViewer } from "@boardgamers/protocol/viewer";
|
||||
import { ChatController } from "@boardgamers/protocol/chat";
|
||||
import { createTutorial } from "@boardgamers/protocol/tutorial";
|
||||
import { mountTutorialGuide } from "@boardgamers/protocol/tutorial/dom";
|
||||
import { stripSecret } from "../engine/index.js";
|
||||
|
|
@ -53,7 +54,10 @@ registerViewer(
|
|||
"primordialSoup",
|
||||
(ctx) => {
|
||||
let pending, timeout;
|
||||
const chat = new ChatController();
|
||||
const ui = mountGame(ctx.target, {
|
||||
chat,
|
||||
onOpenPlayer: ctx.openPlayer,
|
||||
onMove: (m) =>
|
||||
new Promise((resolve, reject) => {
|
||||
pending = { resolve, reject };
|
||||
|
|
@ -69,6 +73,7 @@ registerViewer(
|
|||
}),
|
||||
});
|
||||
return {
|
||||
chat,
|
||||
onPlayer(player) {
|
||||
ui.setPlayer(player.index);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ import * as E from "../engine/index.js";
|
|||
import { mountGame } from "./ui.js";
|
||||
import { chapterMetadata, prepared } from "./tutorials.js";
|
||||
import { mountLesson } from "./index.js";
|
||||
import { mountChatPreview } from "./chat-preview.js";
|
||||
const params = new URLSearchParams(location.search),
|
||||
chapter = params.get("chapter"),
|
||||
appearance = params.get("appearance") === "genes",
|
||||
chatPreview = params.has("chat"),
|
||||
target = document.querySelector("#game"),
|
||||
nav = document.querySelector("#preview-nav");
|
||||
nav.className = "practice-nav";
|
||||
|
|
@ -13,7 +15,12 @@ nav.innerHTML = `<span>Local preview</span><a href="/">Practice game</a><a href=
|
|||
nav.querySelector("select").addEventListener("change", (e) => {
|
||||
location.href = e.target.value ? `/?chapter=${e.target.value}` : "/";
|
||||
});
|
||||
if (chapter) {
|
||||
if (chatPreview) {
|
||||
nav
|
||||
.querySelectorAll("#new-three, #new-four")
|
||||
.forEach((button) => button.remove());
|
||||
mountChatPreview(nav);
|
||||
} else if (chapter) {
|
||||
const next =
|
||||
chapterMetadata[chapterMetadata.findIndex((c) => c.id === chapter) + 1];
|
||||
await mountLesson(target, {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
@import "./fonts.css";
|
||||
@import "./prototype.css";
|
||||
@import "./activity.css";
|
||||
.soup {
|
||||
min-height: 100dvh;
|
||||
padding-bottom: 18px;
|
||||
|
|
@ -457,6 +458,11 @@
|
|||
.soup .journal-list li {
|
||||
font-size: 13px;
|
||||
}
|
||||
.rules-links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px 24px;
|
||||
}
|
||||
.results-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
|
|
|
|||
38
viewer/ui.js
38
viewer/ui.js
|
|
@ -28,9 +28,12 @@ import {
|
|||
sensitivity,
|
||||
evolutionPoints,
|
||||
} from "./rich-text.js";
|
||||
import { mountActivity } from "./activity.js";
|
||||
import { pondArt } from "./pond.js";
|
||||
export const RULES_URL =
|
||||
"https://s3.fr-par.scw.cloud/bgs-assets/assets/primordial-soup/rules-en/69e877694adc4a15/rules-en.pdf";
|
||||
export const SIMPLE_RULES_URL =
|
||||
"https://boardgamers.space/page/primordial-soup/rules";
|
||||
export const esc = (x) =>
|
||||
String(x ?? "").replace(
|
||||
/[&<>"']/g,
|
||||
|
|
@ -151,16 +154,16 @@ function instruction(s, seat) {
|
|||
}
|
||||
export function mountGame(
|
||||
target,
|
||||
{ onMove, onFullscreen, onOpenPlayer, practice = false } = {},
|
||||
{ onMove, onFullscreen, onOpenPlayer, chat, practice = false } = {},
|
||||
) {
|
||||
const root = document.createElement("div");
|
||||
root.className = "soup game-shell";
|
||||
target.append(root);
|
||||
root.innerHTML = `<header class="topbar"><div class="brand"><span>${amoeba("green", 0)}</span><div><h1>primordial soup<span class="title-dot">.</span></h1><span class="byline">DORIS MATTHÄUS & FRANK NESTEL</span></div></div><nav class="utilities" aria-label="Game options"><button class="quiet-button" data-ui="genes">${icon("gene")} Genes</button><button class="icon-button" data-ui="rules" aria-label="How to play">${icon("help")}</button><button class="icon-button" data-ui="fullscreen" aria-label="Fullscreen">${icon("expand")}</button></nav></header>
|
||||
<div class="tutorial-slot"></div><section class="players" aria-label="The colonies" data-tutorial="colonies"></section>
|
||||
<main class="play-area"><section class="pond-section" aria-label="Primordial soup board"><div class="pond-toolbar"><div><span class="eyebrow">A LITTLE LIFE IN A BIG SOUP</span><span class="pond-subtitle" id="turn-order"></span></div><button class="quiet-button" data-ui="journal">${icon("history")} Journal</button></div><div class="board-wrap"><div class="board" data-tutorial="board"><svg id="pond-art" viewBox="0 0 900 650" preserveAspectRatio="none" aria-hidden="true">${pondArt()}</svg><div class="cells"></div><div class="organisms"></div><div class="current-compass" data-tutorial="current"><span>CURRENT</span><div class="compass-arrow">➜</div><b class="compass-label"></b><small>Ozone <strong class="ozone"></strong></small></div><aside class="soup-board-key" data-tutorial="scoring" aria-label="Scoring reference"></aside></div></div><div class="pond-bottom"><span class="last-move" aria-live="polite"></span><span class="food-reserve" title="Food cubes remaining in the common supply"></span></div></section><aside class="colony-panel" data-tutorial="colony"></aside></main>
|
||||
<main class="play-area"><section class="pond-section" aria-label="Primordial soup board"><div class="pond-toolbar"><div><span class="eyebrow">A LITTLE LIFE IN A BIG SOUP</span><span class="pond-subtitle" id="turn-order"></span></div><div class="pond-tools">${chat ? `<button class="quiet-button" data-ui="chat">${icon("chat")} Chat</button>` : ""}<button class="quiet-button" data-ui="journal">${icon("history")} Journal</button></div></div><div class="board-wrap"><div class="board" data-tutorial="board"><svg id="pond-art" viewBox="0 0 900 650" preserveAspectRatio="none" aria-hidden="true">${pondArt()}</svg><div class="cells"></div><div class="organisms"></div><div class="current-compass" data-tutorial="current"><span>CURRENT</span><div class="compass-arrow">➜</div><b class="compass-label"></b><small>Ozone <strong class="ozone"></strong></small></div><aside class="soup-board-key" data-tutorial="scoring" aria-label="Scoring reference"></aside></div></div><div class="pond-bottom"><span class="last-move" aria-live="polite"></span><span class="food-reserve" title="Food cubes remaining in the common supply"></span></div></section><aside class="colony-panel" data-tutorial="colony"></aside></main>
|
||||
<footer class="turnbar" data-tutorial="actions"><div class="round"><span>ROUND</span><strong class="round-number"></strong></div><div class="turn-details"><div class="phase-label"></div><div class="phase-instruction" aria-live="polite"></div><div class="phase-dots"></div></div><div class="action-buttons"></div></footer><div class="game-message" role="alert"></div>
|
||||
<dialog><button class="close-modal icon-button" data-ui="close" aria-label="Close">×</button><div class="modal-content"></div></dialog>`;
|
||||
<div class="activity-slot"></div><dialog><button class="close-modal icon-button" data-ui="close" aria-label="Close">×</button><div class="modal-content"></div></dialog>`;
|
||||
const $ = (q) => root.querySelector(q),
|
||||
$$ = (q) => [...root.querySelectorAll(q)];
|
||||
let state,
|
||||
|
|
@ -173,6 +176,16 @@ export function mountGame(
|
|||
modalKind,
|
||||
oldTask;
|
||||
const dialog = $("dialog");
|
||||
const activity = mountActivity($(".activity-slot"), {
|
||||
chat,
|
||||
openPlayer: onOpenPlayer,
|
||||
backToBoard() {
|
||||
$(".play-area").scrollIntoView({ block: "start" });
|
||||
$(chat ? '[data-ui="chat"]' : '[data-ui="journal"]').focus({
|
||||
preventScroll: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
const canAct = () =>
|
||||
!busy &&
|
||||
!locked &&
|
||||
|
|
@ -199,6 +212,7 @@ export function mountGame(
|
|||
}
|
||||
function render() {
|
||||
if (!state) return;
|
||||
activity.update(state);
|
||||
const t = state.tasks[0],
|
||||
taskKey = JSON.stringify(t),
|
||||
actor = state.actor;
|
||||
|
|
@ -314,16 +328,7 @@ export function mountGame(
|
|||
else if (modalKind === "scoring") {
|
||||
const player = viewPlayer ?? seat ?? state.actor ?? 0;
|
||||
html = `<h2>Scoring each round</h2><p>Look up your living amoebas and your gene total, then add the two rows. These points belong to the whole colony.</p><div class="scoring-detail">${scoringLegend(colony(state, player).length, geneCount(state, player), state.players[player].color, false)}</div><p>Advanced genes count as two; Ray Protection counts as zero. Score every round. Skip occupied scores on the track.</p>`;
|
||||
} else if (modalKind === "journal")
|
||||
html = `<span class="eyebrow">LIFE IN THE SOUP</span><h2>Journal</h2><ol class="journal-list">${state.log
|
||||
.slice(-150)
|
||||
.reverse()
|
||||
.map(
|
||||
(l) =>
|
||||
`<li><small>Round ${l.round}</small><span>${richText(l.text)}</span></li>`,
|
||||
)
|
||||
.join("")}</ol>`;
|
||||
else if (modalKind === "results")
|
||||
} else if (modalKind === "results")
|
||||
html = `<h2>A little life goes a long way.</h2><p>${esc(state.players[state.winner]?.name ?? "")} wins.</p><ol class="results-list">${state.players
|
||||
.map((p, i) => ({ ...p, index: i }))
|
||||
.sort((a, b) => b.score - a.score)
|
||||
|
|
@ -340,7 +345,7 @@ export function mountGame(
|
|||
)
|
||||
.join("")}</div>`;
|
||||
} else
|
||||
html = `<span class="eyebrow">HOW LIFE WORKS</span><h2>Welcome to the soup.</h2><p>Grow your population and evolve genes. At the end of each round, earn evolution points from your amoebas and genes. Advance along the evolution track, skipping occupied scores. When a colony reaches 42 points — or the last environment card is revealed — finish the round. The highest score wins.</p><div class="help-steps"><section><h3>1 · Move & feed</h3><p>Lowest score first; amoebas act in number order. Drift with the current for free, or pay 1 BP to swim: roll a die for direction. 1 west, 2 north, 3 east, 4 south, 5 stay, 6 choose. A blocked move stays in place.</p></section><section><h3>Food & injuries</h3><p>Eat three nutrients, never your own colour. With four colonies, eat one of each other colour; with three, eat two of one and one of the other. After eating, excrete two nutrients of your own colour onto the same space. If you cannot eat, excrete nothing and take one injury instead.</p></section><section><h3>2 · Environment</h3><p>A new card sets the next current and ozone layer. If your mutation exceeds the ozone, pay the difference in BP or discard genes. No defects in round one.</p></section><section><h3>3 · New genes</h3><p>Highest score first. Buy as many genes as you can afford. Advanced genes replace a prerequisite owned since a previous round.</p></section><section><h3>4 · Cell division</h3><p>Receive 10 BP. Each new amoeba costs 6 BP and goes next to one of yours, without sharing your colour's space. With one amoeba, the second may go anywhere. With none, the first returns anywhere for free.</p></section><section><h3>5 · Survival</h3><p>Two injuries cause death, or three with Longevity. Return two food cubes of every colour to that space. Aggression happens after natural deaths.</p></section><section><h3>6 · Evolution points</h3><p>Your living amoebas and genes earn points automatically. See the scoring table on the board.</p></section><section><h3>Food supply</h3><p>There are 55 cubes of each colour. If the supply runs out, place only the cubes still available. Dead amoeba numbers may be used again.</p></section></div><p><a href="${RULES_URL}" target="_blank" rel="noopener">Read the original English rules (PDF) ↗</a></p>`;
|
||||
html = `<span class="eyebrow">HOW LIFE WORKS</span><h2>Welcome to the soup.</h2><p>Grow your population and evolve genes. At the end of each round, earn evolution points from your amoebas and genes. Advance along the evolution track, skipping occupied scores. When a colony reaches 42 points — or the last environment card is revealed — finish the round. The highest score wins.</p><div class="help-steps"><section><h3>1 · Move & feed</h3><p>Lowest score first; amoebas act in number order. Drift with the current for free, or pay 1 BP to swim: roll a die for direction. 1 west, 2 north, 3 east, 4 south, 5 stay, 6 choose. A blocked move stays in place.</p></section><section><h3>Food & injuries</h3><p>Eat three nutrients, never your own colour. With four colonies, eat one of each other colour; with three, eat two of one and one of the other. After eating, excrete two nutrients of your own colour onto the same space. If you cannot eat, excrete nothing and take one injury instead.</p></section><section><h3>2 · Environment</h3><p>A new card sets the next current and ozone layer. If your mutation exceeds the ozone, pay the difference in BP or discard genes. No defects in round one.</p></section><section><h3>3 · New genes</h3><p>Highest score first. Buy as many genes as you can afford. Advanced genes replace a prerequisite owned since a previous round.</p></section><section><h3>4 · Cell division</h3><p>Receive 10 BP. Each new amoeba costs 6 BP and goes next to one of yours, without sharing your colour's space. With one amoeba, the second may go anywhere. With none, the first returns anywhere for free.</p></section><section><h3>5 · Survival</h3><p>Two injuries cause death, or three with Longevity. Return two food cubes of every colour to that space. Aggression happens after natural deaths.</p></section><section><h3>6 · Evolution points</h3><p>Your living amoebas and genes earn points automatically. See the scoring table on the board.</p></section><section><h3>Food supply</h3><p>There are 55 cubes of each colour. If the supply runs out, place only the cubes still available. Dead amoeba numbers may be used again.</p></section></div><p class="rules-links"><a href="${SIMPLE_RULES_URL}" target="_blank" rel="noopener">Simplified rules ↗</a><a href="${RULES_URL}" target="_blank" rel="noopener">Original rules (PDF) ↗</a></p>`;
|
||||
$(".modal-content").innerHTML = html;
|
||||
if (modalKind === "rules") {
|
||||
for (const text of $(".modal-content").querySelectorAll(
|
||||
|
|
@ -410,6 +415,10 @@ export function mountGame(
|
|||
dialog.close();
|
||||
return;
|
||||
}
|
||||
if (el.dataset.ui === "chat" || el.dataset.ui === "journal") {
|
||||
activity.open(el.dataset.ui);
|
||||
return;
|
||||
}
|
||||
if (el.dataset.ui === "fullscreen") {
|
||||
void toggleFullscreen();
|
||||
return;
|
||||
|
|
@ -442,6 +451,7 @@ export function mountGame(
|
|||
dialog.close();
|
||||
},
|
||||
destroy() {
|
||||
activity.destroy();
|
||||
dialog.close();
|
||||
root.remove();
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue