From eda59540f5f315a8e203b9a27f5f8c2593d70136 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sun, 22 Nov 2026 00:12:07 -0700 Subject: [PATCH] feat: credit a game's author on its card and cabinet An optional `author:` in the registry (a display name, at most 80 characters, no control characters) is reported by /api/games, shown as "by " on the landing page's card, found by the search box, and named beside the organisation on the hall's cabinet card. For games made by someone other than the arcade's owner, such as Jon McElyea's Forward One and Glomus. Co-Authored-By: Claude Opus 5.5 --- src/arcade/filters.py | 4 +++- src/arcade/hall.py | 2 ++ src/arcade/hall_assets/hall.js | 3 ++- src/arcade/hosting/core.py | 2 ++ src/arcade/landing.py | 4 ++++ src/arcade/registry.py | 24 ++++++++++++++++++++++-- tests/test_hall.py | 8 ++++++++ tests/test_hosting_characterization.py | 1 + tests/test_landing.py | 15 +++++++++++++++ tests/test_registry.py | 12 ++++++++++++ 10 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/arcade/filters.py b/src/arcade/filters.py index 7ca841b..18984ba 100644 --- a/src/arcade/filters.py +++ b/src/arcade/filters.py @@ -171,10 +171,12 @@ def summary(self, search=True): def search_text(game): """What the search box looks in: a game's title, slug, theme tags (as - chips name them too) and engine (its name and label), lower case.""" + chips name them too), engine (its name and label) and author, lower case.""" engine = (game.get("engine") or "other").lower() tags = list(game.get("tags") or ()) parts = [game.get("title") or "", game.get("slug") or "", engine, ENGINE_LABELS.get(engine, "")] + if game.get("author"): + parts.append(game["author"]) parts += tags + [tag_label(tag) for tag in tags] return " ".join(parts).lower() diff --git a/src/arcade/hall.py b/src/arcade/hall.py index 0f74292..f6f2e7f 100644 --- a/src/arcade/hall.py +++ b/src/arcade/hall.py @@ -430,6 +430,8 @@ def layout(games, style=None): "added": game.get("added"), "tags": list(game.get("tags") or ()), "engine": game.get("engine") or "other", + # Who made it, when the registry names someone; the card says "by ". + "author": game.get("author"), } ) return { diff --git a/src/arcade/hall_assets/hall.js b/src/arcade/hall_assets/hall.js index 5f7d470..eeabe55 100644 --- a/src/arcade/hall_assets/hall.js +++ b/src/arcade/hall_assets/hall.js @@ -1569,7 +1569,8 @@ const card = $("card"); document.body.classList.toggle("at-cabinet", !!c); if (!c) { card.classList.remove("on"); return; } - $("card-org").textContent = c.org || c.repo.split("/")[0]; + const cardOrg = c.org || c.repo.split("/")[0]; + $("card-org").textContent = c.author ? `${cardOrg} ยท by ${c.author}` : cardOrg; $("card-title").textContent = c.title; // No line written for it yet (a game newer than blurbs.json, with no // release notes either): what it is, from its tags and engine. diff --git a/src/arcade/hosting/core.py b/src/arcade/hosting/core.py index 789468b..3fb3121 100644 --- a/src/arcade/hosting/core.py +++ b/src/arcade/hosting/core.py @@ -104,6 +104,8 @@ def describe(self, game): "engine": game.engine, # Its place among the featured games (1 first), or None. "featured": game.featured, + # Who made it, when not the arcade's owner; None otherwise. + "author": game.author, # "What's new" in the current version: the GitHub release's # notes, once arcade has looked them up (arcade.remote). "notes": self.notesFor(game), diff --git a/src/arcade/landing.py b/src/arcade/landing.py index db23f06..d15569b 100644 --- a/src/arcade/landing.py +++ b/src/arcade/landing.py @@ -241,6 +241,7 @@ def ogImage(): a.chip:focus-visible, a.clear:focus-visible, .shown a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; } a.clear { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-weight: 600; } +.by { display: block; font-size: .8rem; margin-top: .15rem; } .meta { display: block; font-size: .8rem; color: var(--muted); margin-top: .15rem; } .badge { display: inline-block; margin-left: .4rem; padding: 0 .45rem; border-radius: 999px; background: var(--accent); color: var(--accent-fg); font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; @@ -443,6 +444,7 @@ def render(registry, domain, portalUrl, deployed=lambda slug: True, plays=lambda "engine": getattr(game, "engine", None) or filters.default_engine(game.kind), "plays": plays(game.slug) or 0, "added": added(game), + "author": getattr(game, "author", None), } byDict[game.slug] = game everything.append(entry) @@ -461,6 +463,8 @@ def render(registry, domain, portalUrl, deployed=lambda slug: True, plays=lambda [filters.tag_label(tag) for tag in entry["tags"]] + [filters.ENGINE_LABELS.get(entry["engine"], "")] ) metaLine = '%s' % escape(meta) if meta else "" + if entry["author"]: + metaLine = 'by %s' % escape(entry["author"]) + metaLine hit = chosen.found(entry) if chosen.q else True found += hit attrs = ' data-slug="%s" data-search="%s"%s' % ( diff --git a/src/arcade/registry.py b/src/arcade/registry.py index 953be7e..800cea6 100644 --- a/src/arcade/registry.py +++ b/src/arcade/registry.py @@ -22,6 +22,7 @@ tags: [story, puzzle] # optional, flow list only (see below) engine: strata # optional (see below) featured: 1 # optional (see below) + author: Jon McElyea # optional (see below) `games: []` is an empty registry. @@ -67,6 +68,13 @@ set), and the hall stands the featured games side by side on its stage, in this order, left to right as seen from the door. Two games may not share a number. With no game featured the stage stands empty. + +author: who made the game, as a name to show ("Jon McElyea"), for a game made +by someone other than the arcade's owner. /api/games reports it as `author` +(null when not set), the landing page's card says "by " and the hall's +cabinet card names them beside the organisation. Plain text of at most +MAX_AUTHOR characters, no control characters; it is escaped wherever it is +shown. Without it no author is named. """ import datetime @@ -101,10 +109,11 @@ def org_of(repo): REQUIRED_KEYS = ("slug", "title", "repo", "token_sha256") -OPTIONAL_KEYS = ("owner", "aliases", "kind", "isolation", "canonical", "added", "tags", "engine", "featured") +OPTIONAL_KEYS = ("owner", "aliases", "kind", "isolation", "canonical", "added", "tags", "engine", "featured", "author") LIST_KEYS = ("aliases", "tags") TAG_PATTERN = re.compile(r"^[a-z][a-z0-9-]{1,23}$") MAX_TAGS = 6 +MAX_AUTHOR = 80 FEATURED_PATTERN = re.compile(r"^[1-9][0-9]{0,2}$") ADDED_PATTERN = re.compile(r"^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}Z)?$") KINDS = ("tak", "static") @@ -119,7 +128,7 @@ class RegistryError(ValueError): class Game(object): __slots__ = ( "slug", "title", "repo", "owner", "tokenSha256", "aliases", "kind", "isolation", "canonical", "added", - "tags", "engine", "featured", + "tags", "engine", "featured", "author", ) def __init__( @@ -137,6 +146,7 @@ def __init__( tags=(), engine=None, featured=None, + author=None, ): self.slug = slug self.title = title @@ -151,6 +161,7 @@ def __init__( self.tags = tuple(tags) self.engine = engine or default_engine(kind) self.featured = featured # a positive int (its place among the featured games), or None + self.author = author # a display name, or None @property def org(self): @@ -396,6 +407,14 @@ def validate(entries, domain=None): "line %d: featured %d for %r is already taken by %r" % (lineNumber, featured, slug, featuredOwners[featured]) ) featuredOwners[featured] = slug + author = entry.get("author") + if author is not None: + author = author.strip() + if not author or len(author) > MAX_AUTHOR or any(ord(c) < 32 or ord(c) == 127 for c in author): + raise RegistryError( + "line %d: author for %r must be a name of 1 to %d characters with no control characters, got %r" + % (lineNumber, slug, MAX_AUTHOR, entry["author"]) + ) games.append( Game( slug=slug, @@ -411,6 +430,7 @@ def validate(entries, domain=None): tags=tags, engine=engine, featured=featured, + author=author, ) ) return Registry(games) diff --git a/tests/test_hall.py b/tests/test_hall.py index 3e2c162..ec81b6b 100644 --- a/tests/test_hall.py +++ b/tests/test_hall.py @@ -1224,3 +1224,11 @@ def test_the_hall_serves_a_fetched_still_and_names_it_in_the_layout(running, tmp assert res.getheader("Content-Type") == "image/jpeg" and res.getheader("ETag") for bad in ("/hall/fetched/nothing.jpg", "/hall/fetched/../games.yaml", "/hall/fetched/Second.jpg"): assert get(port, bad)[0].status == 404, bad + + +def test_a_cabinet_carries_its_author_for_the_card(): + glomus = dict(entry("glomus", "McElyea/Glomus"), author="Jon McElyea") + doc = hall.layout([glomus, entry("roam", "Preponderous-Software/roam")]) + bySlug = {c["slug"]: c for c in doc["cabinets"]} + assert bySlug["glomus"]["author"] == "Jon McElyea" + assert bySlug["roam"]["author"] is None diff --git a/tests/test_hosting_characterization.py b/tests/test_hosting_characterization.py index 58d890c..2ae73bf 100644 --- a/tests/test_hosting_characterization.py +++ b/tests/test_hosting_characterization.py @@ -113,6 +113,7 @@ def test_upload_answers_201_with_the_full_description(arcade): "org": body(data)["org"], "engine": body(data)["engine"], "featured": None, + "author": None, "notes": None, } assert body(data)["added"].endswith("Z") diff --git a/tests/test_landing.py b/tests/test_landing.py index 742b4f7..cfa9fbf 100644 --- a/tests/test_landing.py +++ b/tests/test_landing.py @@ -304,3 +304,18 @@ def test_the_page_stays_phone_sized(): # Nothing fixed-width wider than a 320 px screen: the rows and the search shrink. assert "min-width: 0" in css.split("form.search {", 1)[1].split("}", 1)[0] assert "repeat(auto-fill, minmax(9.5rem, 1fr))" in css + + +def test_a_card_credits_its_author_escaped_and_the_search_finds_them(): + reg = Registry([ + Game("glomus", "Glomus", "McElyea/Glomus", "0" * 64, kind="static", author="Jon "), + Game("apex", "Apex", "Preponderous-Software/apex", "0" * 64, kind="static"), + ]) + text = landing.render(reg, "play.example.com", "https://example.com/play").decode("utf-8") + assert 'by Jon <McElyea>' in text + assert "Jon " not in text + # Only the game with an author gets a byline. + apex = text.split('
  • ", 1)[0] + assert 'class="by"' not in apex + searched = landing.render(reg, "play.example.com", "https://example.com/play", query="q=mcelyea").decode("utf-8") + assert shown(searched) == ["glomus"] diff --git a/tests/test_registry.py b/tests/test_registry.py index 819df60..61e4c83 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -286,3 +286,15 @@ def test_featured_must_be_a_whole_number_from_one(bad): def test_two_games_may_not_share_a_featured_place(): with pytest.raises(registry.RegistryError, match="line 7: featured 1 for 'cave' is already taken by 'tidewater'"): registry.loads(registryText([game("tidewater", featured="1"), game("cave", featured="1")])) + + +def test_author_is_an_optional_name_to_credit(): + loaded = registry.loads(registryText([game("tidewater", author="Jon McElyea"), game("roam")])) + assert loaded.get("tidewater").author == "Jon McElyea" + assert loaded.get("roam").author is None + + +@pytest.mark.parametrize("bad", ["\"\"", "\" \"", "x" * 81, "a\x7fb"]) +def test_author_must_be_a_short_plain_name(bad): + with pytest.raises(registry.RegistryError, match="line 2: author for 'tidewater' must be a name of 1 to 80"): + registry.loads(registryText([game("tidewater", author=bad)]))