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
45 changes: 45 additions & 0 deletions art/og.scene
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Overwinter - the picture under the link-preview card (web/og.png). Not a
# location still: it is not in stills.json and never ships in game.zip. It is
# the strip seen at noon on day 20 (2021-01-29 at 78 N, 14 E; see the
# "setting" in stills.json), the first day the sky shows twilight, with the
# station's lamps lit. art/render_og.py renders it with strata-golden and sets
# the title over it; see that file.
size 2400 1260
camera 2 3.2 34 10 2.4 -6 58 0.3 420
lighting sun 0.5 78 4 2048 120 0.6 1
clear 0 0 0 1 sky
sun date 2021-01-29 12:00 1 78.0 14.0
# snowfield, and the strip itself: gravel showing through, running north
item cube 40 -0.5 0 260 1 500 0.82 0.85 0.90
item cube 6 0.01 0 18 0.04 300 0.50 0.50 0.52
item cube -2.6 0.03 0 0.6 0.04 300 0.82 0.85 0.90
item cube 14.6 0.03 0 0.6 0.04 300 0.82 0.85 0.90
# the bay to the west: frozen, flat, darker than the snow
item cube -150 -0.7 0 300 1 600 0.40 0.43 0.48
# marker drums along the strip's edges
item cylinder -3 0.45 30 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder -3 0.45 0 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder -3 0.45 -30 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder -3 0.45 -60 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder 15 0.45 30 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder 15 0.45 0 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder 15 0.45 -30 0.6 0.45 0.6 0.75 0.25 0.10
item cylinder 15 0.45 -60 0.6 0.45 0.6 0.75 0.25 0.10
# the windsock, straight out to the west on its mast
item cylinder 18 3 12 0.16 3 0.16 0.30 0.30 0.30
item cube 16.9 5.7 12 2.2 0.06 0.06 0.30 0.30 0.30
item cube 16.4 5.7 12 1.0 0.8 0.8 0.95 0.45 0.10
item cube 15.4 5.7 12 1.0 0.7 0.7 0.92 0.92 0.92
item cube 14.4 5.7 12 1.0 0.6 0.6 0.95 0.45 0.10
item cube 13.4 5.7 12 1.0 0.5 0.5 0.92 0.92 0.92
# a lamp on a post at the strip's near end, burning
item cylinder 12 1.6 20 0.12 1.6 0.12 0.20 0.20 0.20
item cube 12.3 3.45 20 0.7 0.06 0.06 0.20 0.20 0.20
item sphere 12.6 3.3 20 0.3 0.3 0.3 1.0 0.85 0.55
light point 12.6 3.1 20 30 1.0 0.80 0.50 4.0
# the yard lamps on the huts' strip side
light point 20 4.2 -4 34 1.0 0.80 0.52 5.0 shadow
item sphere 21.6 4.0 -4 0.3 0.3 0.3 1.0 0.85 0.55
light point 8 3.0 -40 20 1.0 0.80 0.52 1.6
include _station_huts.scene
include _ridge.scene
82 changes: 82 additions & 0 deletions art/render_og.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
"""Render web/og.png, the picture a shared link to Overwinter unfurls with.

python3 art/render_og.py --strata-golden /path/to/strata-golden \\
--og-card /path/to/community-site-kit/tools/og-card

The picture is art/og.scene (the strip at noon on day 20, the station's lamps
lit), drawn offline and headless by Strata's golden-image tool at 2400x1260,
the same way art/render.py draws the location stills:

strata-golden render art/og.scene <out.png> --surface headless

Build strata-golden from Strata's source at the tag named in OG["strata"]
(see art/render.py for the cmake lines). The title, tagline and address are
then set over it by community-site-kit's og-card tool (tools/og-card/og_card.py,
its compose() step only), so the card's type and dark scrim match the other
link-preview cards made with that tool. Check that tool out at OG["og_card"]
and install its requirements.txt (Pillow) first. The PNG is committed; CI never
re-renders it. The <meta> tags in web/index.html carry OG["alt"].
"""

import argparse
import os
import subprocess
import sys
import tempfile

ART = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(ART)
SCENE = os.path.join(ART, "og.scene")
OUTPUT = os.path.join(ROOT, "web", "og.png")

OG = {
"strata": "v0.7.0",
"og_card": "5e3329e2f50d9700ad60979270557fb0e3de98f8",
"title": "Overwinter",
"wordmark": "A text adventure",
"subtitle": "Four people, one station, twenty days until a plane.",
"url": "overwinter.danielstephenson.dev",
"accent": "#7fb0d0",
"alt": (
"A snowy airstrip at polar twilight lit by a lamp on a post, the station's red huts with glowing windows "
"and a windsock behind it, a dark ridge against a faint red sky, beside the title Overwinter."
),
}


def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument("--strata-golden", default=os.environ.get("STRATA_GOLDEN"), required=False)
parser.add_argument("--og-card", required=True, help="community-site-kit's tools/og-card directory")
args = parser.parse_args(argv)
if not args.strata_golden:
parser.error("--strata-golden (or STRATA_GOLDEN) is required")

sys.path.insert(0, os.path.abspath(args.og_card))
import og_card # noqa: E402 (community-site-kit tools/og-card)
from PIL import Image

env = dict(os.environ)
env.setdefault("LIBGL_ALWAYS_SOFTWARE", "1")
env.setdefault("GALLIUM_DRIVER", "llvmpipe")
with tempfile.TemporaryDirectory() as tmp:
render = os.path.join(tmp, "og-scene.png")
subprocess.run([args.strata_golden, "render", SCENE, render, "--surface", "headless"], check=True, env=env)
image = Image.open(render).convert("RGBA")
spec = {
"title": OG["title"],
"wordmark": OG["wordmark"],
"subtitle": OG["subtitle"],
"url": OG["url"],
"accent": OG["accent"],
"credit": "Rendered with Strata",
}
card = og_card.compose(image.tobytes(), image.size, spec, ART, OG["strata"].lstrip("v"))
card.save(OUTPUT, format="PNG", optimize=True)
print("wrote %s" % OUTPUT)
return 0


if __name__ == "__main__":
sys.exit(main())
66 changes: 66 additions & 0 deletions tests/test_og_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""The link-preview card (og:image): web/og.png and the <meta> tags naming it.

The card is a 1200x630 PNG rendered with Strata and committed; nothing here
renders it. The alt text is OG["alt"] in art/render_og.py.
"""

import html
import os
import re
import struct
import sys

REPOSITORY_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))
CARD = os.path.join(REPOSITORY_ROOT, "web", "og.png")
IMAGE_URL = "https://raw.githubusercontent.com/Stephenson-Software/Overwinter/main/web/og.png"


def page():
with open(os.path.join(REPOSITORY_ROOT, "web", "index.html"), encoding="utf-8") as f:
return f.read()


def meta(attribute, name):
found = re.findall(r'<meta %s="%s" content="([^"]*)">' % (attribute, re.escape(name)), page())
assert len(found) == 1, "%s=%s should appear once, found %d" % (attribute, name, len(found))
return html.unescape(found[0])


def card_alt():
sys.path.insert(0, os.path.join(REPOSITORY_ROOT, "art"))
import render_og

return render_og.OG["alt"]


def test_the_card_is_a_1200_by_630_png():
with open(CARD, "rb") as f:
head = f.read(24)
assert head[:8] == b"\x89PNG\r\n\x1a\n"
assert head[12:16] == b"IHDR"
assert struct.unpack(">II", head[16:24]) == (1200, 630)


def test_the_card_stays_small_enough_for_scrapers():
# Facebook and X refuse cards over 5 MB; stay well under.
assert os.path.getsize(CARD) < 512 * 1024


def test_the_page_names_the_card_with_its_size_and_alt_text():
assert meta("property", "og:image") == IMAGE_URL
assert meta("name", "twitter:image") == IMAGE_URL
assert meta("property", "og:image:type") == "image/png"
assert meta("property", "og:image:width") == "1200"
assert meta("property", "og:image:height") == "630"
assert meta("name", "twitter:card") == "summary_large_image"
alt = card_alt()
assert 20 <= len(alt) <= 420
assert meta("property", "og:image:alt") == alt
assert meta("name", "twitter:image:alt") == alt


def test_the_preview_text_matches_the_page():
assert meta("property", "og:title") == meta("name", "twitter:title")
assert meta("property", "og:description") == meta("name", "twitter:description")
assert meta("property", "og:description") == meta("name", "description")
assert "<title>%s</title>" % meta("property", "og:title") in page()
20 changes: 20 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Overwinter</title>
<meta name="description" content="A text adventure: four people, one station, twenty days until a plane. Plays in your browser.">
<!-- Link previews (og:image). The card is web/og.png in this repository,
rendered with Strata (see art/render_og.py). arcade serves only
index.html and game.zip for a tak game, so the image is linked from
GitHub's raw host rather than from the game's own host. -->
<meta property="og:type" content="website">
<meta property="og:site_name" content="danielstephenson.dev">
<meta property="og:title" content="Overwinter">
<meta property="og:description" content="A text adventure: four people, one station, twenty days until a plane. Plays in your browser.">
<meta property="og:url" content="https://overwinter.danielstephenson.dev/">
<meta property="og:image" content="https://raw.githubusercontent.com/Stephenson-Software/Overwinter/main/web/og.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="A snowy airstrip at polar twilight lit by a lamp on a post, the station&#x27;s red huts with glowing windows and a windsock behind it, a dark ridge against a faint red sky, beside the title Overwinter.">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Overwinter">
<meta name="twitter:description" content="A text adventure: four people, one station, twenty days until a plane. Plays in your browser.">
<meta name="twitter:image" content="https://raw.githubusercontent.com/Stephenson-Software/Overwinter/main/web/og.png">
<meta name="twitter:image:alt" content="A snowy airstrip at polar twilight lit by a lamp on a post, the station&#x27;s red huts with glowing windows and a windsock behind it, a dark ridge against a faint red sky, beside the title Overwinter.">
<!-- The renderer, styles, boot script and Worker all come from the tak
package, served at /tak/ by web/serve.py. Only what is on this page is
Overwinter's: the title, the tagline, and the TakBoot configuration. -->
Expand Down
Binary file added web/og.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading