Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/arcade/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions src/arcade/hall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>".
"author": game.get("author"),
}
)
return {
Expand Down
3 changes: 2 additions & 1 deletion src/arcade/hall_assets/hall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/arcade/hosting/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions src/arcade/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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 = '<span class="meta">%s</span>' % escape(meta) if meta else ""
if entry["author"]:
metaLine = '<span class="by">by %s</span>' % escape(entry["author"]) + metaLine
hit = chosen.found(entry) if chosen.q else True
found += hit
attrs = ' data-slug="%s" data-search="%s"%s' % (
Expand Down
24 changes: 22 additions & 2 deletions src/arcade/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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 <author>" 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
Expand Down Expand Up @@ -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")
Expand All @@ -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__(
Expand All @@ -137,6 +146,7 @@ def __init__(
tags=(),
engine=None,
featured=None,
author=None,
):
self.slug = slug
self.title = title
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -411,6 +430,7 @@ def validate(entries, domain=None):
tags=tags,
engine=engine,
featured=featured,
author=author,
)
)
return Registry(games)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/test_hosting_characterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions tests/test_landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <McElyea>"),
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 '<span class="by">by Jon &lt;McElyea&gt;</span>' in text
assert "Jon <McElyea>" not in text
# Only the game with an author gets a byline.
apex = text.split('<li data-slug="apex"', 1)[1].split("</li>", 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"]
12 changes: 12 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]))
Loading