Initial layout
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.o
|
||||
54
Readme.org
Normal file
54
Readme.org
Normal file
@@ -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/<id>/
|
||||
<id>.sex
|
||||
index.html what the frame loads
|
||||
<id>.js
|
||||
<id>.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/<id>/<id>.sex~.
|
||||
2. Compile it with ~sexc~, then Emscripten, and write ~index.html~,
|
||||
~<id>.js~, and ~<id>.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.
|
||||
30
index.html
Normal file
30
index.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Foreplay — toys to test the water</title>
|
||||
<link rel="stylesheet" href="site.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="brand">
|
||||
<h1>Foreplay — toys to test the water</h1>
|
||||
</header>
|
||||
<nav class="menu" id="menu" aria-label="Toys"></nav>
|
||||
<div class="viewport is-splash" id="viewport">
|
||||
<div class="caption" id="caption">
|
||||
<div class="caption-text">
|
||||
<h2 id="toy-title"></h2>
|
||||
<p id="toy-blurb"></p>
|
||||
</div>
|
||||
<button type="button" id="source-btn" hidden aria-pressed="false">source</button>
|
||||
</div>
|
||||
<div class="stage" id="stage">
|
||||
<p class="splash" id="splash">Pick a toy for you to enjoy.</p>
|
||||
<iframe id="frame" hidden title="Toy"></iframe>
|
||||
<pre class="source" id="source" hidden></pre>
|
||||
</div>
|
||||
</div>
|
||||
<script src="site.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
223
site.css
Normal file
223
site.css
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
143
site.js
Normal file
143
site.js
Normal file
@@ -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.";
|
||||
});
|
||||
0
toys/.gitkeep
Normal file
0
toys/.gitkeep
Normal file
Reference in New Issue
Block a user