diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/Readme.org b/Readme.org new file mode 100644 index 0000000..136a5c7 --- /dev/null +++ b/Readme.org @@ -0,0 +1,54 @@ +* Foreplay — toys to test the water + +This is an exhibition of games and tools written in Sex, that are capable to run in the browser. + +** Layout + +The page is static, a toy is one folder, each toy keeps its own Emscripten runtime. + +#+begin_src +index.html gallery shell +site.css +site.js menu, hash, frame, source +toys.json the menu +toys// + .sex + index.html what the frame loads + .js + .wasm +#+end_src + +~toys.json~ is a list: + +#+begin_src json +[ + { + "id": "triangle", + "title": "Triangle", + "blurb": "The basic thing in games.", + "source": "triangle.sex" + } +] +#+end_src + +~id~ is the folder name and the hash (~#triangle~). ~source~ is the Sex +file the source button shows. Leave ~source~ out when a toy has nothing +to show. + +Serve this directory with any static file server: + +#+begin_src shell +python3 -m http.server +#+end_src + +Opening ~index.html~ from disk will not load ~toys.json~. + +** Adding a toy + +1. Put the program at ~toys//.sex~. +2. Compile it with ~sexc~, then Emscripten, and write ~index.html~, + ~.js~, and ~.wasm~ into that same folder. +3. Add an entry to ~toys.json~. + +The wasm and the generated page stay in the repo, so the gallery is only +files. diff --git a/index.html b/index.html new file mode 100644 index 0000000..4fabb16 --- /dev/null +++ b/index.html @@ -0,0 +1,30 @@ + + + + + + Foreplay — toys to test the water + + + +
+

Foreplay — toys to test the water

+
+ +
+
+
+

+

+
+ +
+
+

Pick a toy for you to enjoy.

+ + +
+
+ + + diff --git a/site.css b/site.css new file mode 100644 index 0000000..ca15329 --- /dev/null +++ b/site.css @@ -0,0 +1,223 @@ +:root { + --bg: #12110f; + --bar: #1a1815; + --line: #342f2a; + --text: #f4efe8; + --muted: #9c9288; + --dim: #6f675f; + --accent: #f0a36a; + --selected: #2a241e; + color-scheme: dark; +} + +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + height: 100%; +} + +body { + height: 100dvh; + display: grid; + grid-template-columns: 16rem minmax(0, 1fr); + grid-template-rows: auto minmax(0, 1fr); + background: var(--bg); + color: var(--text); + font: 15px/1.4 "Segoe UI", system-ui, sans-serif; +} + +.brand { + grid-column: 1 / -1; + display: flex; + align-items: center; + min-height: 3.25rem; + padding: 0.7rem 1rem; + background: var(--bar); + border-bottom: 1px solid var(--line); +} + +.brand h1 { + margin: 0; + font-size: 1rem; + font-weight: 560; + letter-spacing: 0.01em; + white-space: nowrap; +} + +.menu { + grid-column: 1; + grid-row: 2; + overflow: auto; + background: var(--bar); + border-right: 1px solid var(--line); + padding: 0.4rem 0; +} + +.menu a { + display: block; + padding: 0.45rem 1rem; + color: inherit; + text-decoration: none; +} + +.menu a:hover { + background: #231f1b; +} + +.menu a[aria-current="page"] { + background: var(--selected); + box-shadow: inset 3px 0 var(--accent); +} + +.menu a:focus-visible, +#source-btn:focus-visible { + outline: 2px solid var(--accent); + outline-offset: -2px; +} + +.viewport { + grid-column: 2; + grid-row: 2; + min-width: 0; + min-height: 0; + display: grid; + grid-template-rows: auto minmax(0, 1fr); +} + +.viewport.is-splash { + grid-template-rows: minmax(0, 1fr); +} + +.viewport.is-splash .caption { + display: none; +} + +.caption { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1rem; + min-height: 3.25rem; + padding: 0.7rem 1rem; + background: var(--bar); + border-bottom: 1px solid var(--line); +} + +.caption h2 { + margin: 0; + font-size: 0.95rem; + font-weight: 560; +} + +.caption p { + margin: 0.1rem 0 0; + color: var(--muted); + font-size: 0.85rem; +} + +#source-btn { + flex: none; + font: inherit; + color: var(--text); + background: transparent; + border: 1px solid var(--line); + border-radius: 999px; + padding: 0.2rem 0.75rem; + cursor: pointer; +} + +#source-btn[aria-pressed="true"] { + border-color: var(--accent); + color: var(--accent); +} + +.stage { + min-width: 0; + min-height: 0; + display: grid; + grid-template-columns: minmax(0, 1fr); +} + +.stage.has-source { + grid-template-columns: minmax(0, 1fr) minmax(16rem, 28rem); +} + +.splash { + place-self: center; + margin: 0; + color: var(--dim); +} + +iframe, +.source { + width: 100%; + height: 100%; + min-width: 0; + min-height: 0; + border: 0; +} + +iframe { + background: #000; +} + +.source { + margin: 0; + overflow: auto; + padding: 1rem 1.1rem; + background: #0e0d0b; + border-left: 1px solid var(--line); + color: #e7dfd4; + font: 13px/1.45 ui-monospace, "Cascadia Code", "Source Code Pro", monospace; + white-space: pre; +} + +@media (max-width: 720px) { + body { + grid-template-columns: 1fr; + grid-template-rows: auto auto minmax(0, 1fr); + } + + .brand h1 { + white-space: normal; + } + + .menu { + grid-column: 1; + grid-row: 2; + display: flex; + gap: 0.25rem; + overflow-x: auto; + border-right: 0; + border-bottom: 1px solid var(--line); + padding: 0.35rem; + } + + .menu a { + white-space: nowrap; + border-radius: 999px; + } + + .menu a[aria-current="page"] { + box-shadow: inset 0 -2px var(--accent); + } + + .viewport { + grid-column: 1; + grid-row: 3; + } + + .stage.has-source { + grid-template-columns: minmax(0, 1fr); + grid-template-rows: minmax(0, 1fr) minmax(8rem, 34vh); + } + + .source { + border-left: 0; + border-top: 1px solid var(--line); + } +} diff --git a/site.js b/site.js new file mode 100644 index 0000000..b13b038 --- /dev/null +++ b/site.js @@ -0,0 +1,143 @@ +const menu = document.querySelector("#menu"); +const caption = document.querySelector("#caption"); +const titleEl = document.querySelector("#toy-title"); +const blurbEl = document.querySelector("#toy-blurb"); +const sourceBtn = document.querySelector("#source-btn"); +const viewport = document.querySelector("#viewport"); +const stage = document.querySelector("#stage"); +const splash = document.querySelector("#splash"); +const frame = document.querySelector("#frame"); +const sourceEl = document.querySelector("#source"); + +let toys = []; +let current = null; +let sourceOpen = false; +let sourceText = null; +let sourceGen = 0; + +function splashCopy(missing) { + if (missing) return "No such toy."; + if (!toys.length) return "No toys yet."; + return "Pick a toy."; +} + +function markSelected(id) { + for (const link of menu.querySelectorAll("a")) { + const on = link.dataset.id === id; + if (on) link.setAttribute("aria-current", "page"); + else link.removeAttribute("aria-current"); + } +} + +function showSplash(missing) { + current = null; + sourceOpen = false; + sourceText = null; + sourceGen++; + splash.hidden = false; + splash.textContent = splashCopy(missing); + frame.hidden = true; + frame.removeAttribute("src"); + sourceEl.hidden = true; + sourceEl.textContent = ""; + viewport.classList.add("is-splash"); + stage.classList.remove("has-source"); + titleEl.textContent = ""; + blurbEl.textContent = ""; + sourceBtn.hidden = true; + sourceBtn.setAttribute("aria-pressed", "false"); + markSelected(null); +} + +function renderMenu() { + menu.replaceChildren(); + for (const toy of toys) { + const link = document.createElement("a"); + link.href = "#" + encodeURIComponent(toy.id); + link.dataset.id = toy.id; + link.textContent = toy.title; + if (toy.blurb) link.title = toy.blurb; + menu.append(link); + } +} + +function openToy(toy) { + current = toy; + sourceOpen = false; + sourceText = null; + sourceGen++; + splash.hidden = true; + frame.hidden = false; + frame.title = toy.title; + frame.src = "toys/" + encodeURIComponent(toy.id) + "/index.html"; + sourceEl.hidden = true; + sourceEl.textContent = ""; + viewport.classList.remove("is-splash"); + stage.classList.remove("has-source"); + titleEl.textContent = toy.title; + blurbEl.textContent = toy.blurb || ""; + sourceBtn.hidden = !toy.source; + sourceBtn.setAttribute("aria-pressed", "false"); + markSelected(toy.id); +} + +function selectFromHash() { + const id = decodeURIComponent(location.hash.replace(/^#/, "")); + if (!id) { + showSplash(false); + return; + } + const toy = toys.find((item) => item.id === id); + if (!toy) { + showSplash(true); + return; + } + openToy(toy); +} + +sourceBtn.addEventListener("click", async () => { + if (!current || !current.source) return; + sourceOpen = !sourceOpen; + sourceBtn.setAttribute("aria-pressed", String(sourceOpen)); + if (!sourceOpen) { + sourceEl.hidden = true; + stage.classList.remove("has-source"); + return; + } + const gen = sourceGen; + const toy = current; + stage.classList.add("has-source"); + sourceEl.hidden = false; + if (sourceText == null) { + sourceEl.textContent = "Loading…"; + const url = "toys/" + encodeURIComponent(toy.id) + "/" + toy.source; + let text; + try { + const res = await fetch(url); + text = res.ok ? await res.text() : "Source missing."; + } catch { + text = "Source missing."; + } + if (gen !== sourceGen) return; + sourceText = text; + } + if (!sourceOpen) return; + sourceEl.textContent = sourceText; +}); + +window.addEventListener("hashchange", selectFromHash); + +fetch("toys.json") + .then((res) => { + if (!res.ok) throw new Error("toys.json"); + return res.json(); + }) + .then((list) => { + toys = Array.isArray(list) ? list : []; + renderMenu(); + selectFromHash(); + }) + .catch(() => { + splash.hidden = false; + splash.textContent = "Could not load the toy list."; + }); diff --git a/toys.json b/toys.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/toys.json @@ -0,0 +1 @@ +[] diff --git a/toys/.gitkeep b/toys/.gitkeep new file mode 100644 index 0000000..e69de29