Render TOML reminder text onto card templates and add trigger-order reminder

This commit is contained in:
Dandaedre 2026-11-10 12:09:38 +01:00
parent 09855fb9bc
commit ccb8036405
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
15 changed files with 598 additions and 17 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
/dist/
__pycache__/
*.pyc
/.venv/
/.uv-cache/

View File

@ -11,7 +11,12 @@
`scripts/generate_xml.py` generates XML under `dist/sets/`. Preserve stable
token IDs, imported UUIDs, and published XML filenames when updating content.
Archives are historical snapshots, not a second source to maintain.
- Building requires Python 3.11+ (`tomllib`); the client installer remains 3.8+.
- Building requires Python 3.11+ (`tomllib`) and Pillow from `requirements-build.lock`.
Activate `.venv` before building/testing; the client installer remains 3.8+.
- Render reminder text from `[tokens.render]` with `scripts/render_cards.py`. Keep
blank templates in `templates/`, bundled fonts and licenses in `assets/fonts/`,
and rendered images only under `dist/`. Reject overflow instead of clipping text.
Cite official rules and record the reviewed date for rules reminders.
- Build ZIPs using `python3 scripts/build.py`; do not hand-edit ZIPs or commit
generated `dist/` contents.
- Keep `deploy.sh` and `deploy.ps1` as non-mutating mocks until real deployment is

24
Jenkinsfile vendored
View File

@ -40,6 +40,16 @@ pipeline {
'''
}
}
stage('Install rendering dependency') {
steps {
sh '''
set -eu
python3 -m venv .venv
.venv/bin/python -m pip install --require-hashes -r requirements-build.lock
.venv/bin/python -c 'import PIL; print("Pillow", PIL.__version__)'
'''
}
}
stage('Check scripts') {
steps {
sh '''
@ -53,7 +63,7 @@ pipeline {
steps {
sh '''
set -eu
python3 -m unittest discover -s tests -v
.venv/bin/python -m unittest discover -s tests -v
'''
}
}
@ -61,10 +71,10 @@ pipeline {
steps {
sh '''
set -eu
python3 scripts/build.py
python3 scripts/generate_xml.py --check
python3 scripts/publish.py prepare
python3 scripts/publish.py verify
.venv/bin/python scripts/build.py
.venv/bin/python scripts/generate_xml.py --check
.venv/bin/python scripts/publish.py prepare
.venv/bin/python scripts/publish.py verify
sh -n dist/publish/install.sh
sh dist/publish/install.sh --help
'''
@ -89,8 +99,8 @@ pipeline {
steps {
sh '''
set -eu
python3 scripts/publish.py verify
python3 scripts/publish.py publish --web-root "$ASSETS_WEB_ROOT"
.venv/bin/python scripts/publish.py verify
.venv/bin/python scripts/publish.py publish --web-root "$ASSETS_WEB_ROOT"
'''
script { env.ASSETS_PUBLISHED = 'true' }
}

View File

@ -13,12 +13,17 @@ scheduled background updates are not implemented.
sets/TKR/
set.toml Shared set metadata
command_zones.toml Command Zone token and alternative artwork
reminders.toml Automatically typeset rules reminders
templates/reminders/ Original blank reminder templates
artwork/
command-zone/ Command Zone artwork variants
command-zone-default.png
command-zone-ajani.png
...
archives/customtokens.zip Legacy XML snapshot (not used by CI)
scripts/render_cards.py Pillow text layout on reminder templates
assets/fonts/ Bundled DejaVu Serif fonts and license
requirements-build.lock Pinned, hash-checked rendering dependency
scripts/generate_xml.py TOML validation and XML generation
scripts/build.py Generate XML and build ZIPs
scripts/publish.py CI payload validation and atomic publication
@ -105,6 +110,61 @@ Command Zone token retains its explicit imported UUID and collector number.
Renaming installed cards or XML filenames may leave old local files behind;
the installer does not automatically delete them.
## Automatically put TOML text on a card
`sets/TKR/reminders.toml` contains the ready-to-build **Reminder - Trigger Order**.
Its description is the single source for both the visible image text and Cockatrice
XML text. The original blank images are preserved in
`sets/TKR/templates/reminders/`; only rendered cards are packaged and published.
To make another reminder, add a token with an output artwork path and a render table:
```toml
[[tokens]]
id = "my-reminder"
name = "My Reminder"
type = "Emblem"
artwork = "artwork/reminders/my-reminder.png" # Generated PNG, not an input file.
description = """
Your rules or reminder text here.
Use blank lines to separate paragraphs.
"""
[tokens.render]
template = "templates/reminders/reminder-larger.png"
title = "MY REMINDER" # Defaults to the card name.
box = [100, 155, 655, 1100] # Left, top, right, bottom in original image pixels.
font_size = 27 # Preferred body size; shrinks only as needed.
min_font_size = 23 # Fail the build instead of shrinking further/clipping.
title_size = 36
color = "#192b3b" # Optional dark blue ink.
footer = "Your short source or note"
```
Run the normal build, then open
`dist/sets/TKR/artwork/reminders/my-reminder.png`. Do not save that generated PNG
in the source artwork folder: the generator rejects overwriting a source image.
Templates must be inside the set's `templates/` folder. Choose a box that stays
inside its blank panel; the narrower `reminder.png` needs a narrower box than
`reminder-larger.png`. Text is wrapped automatically, blank lines are preserved,
and excessively long text or words fail with an explicit error. This is plain
text, not Markdown. Rendering currently applies to a token's primary artwork;
existing alternative printings continue to use supplied images.
The renderer uses the bundled DejaVu Serif regular/bold faces with dark ink and a
small gold rule under the title. The license is in `assets/fonts/LICENSE-DejaVu.txt`.
Using these files avoids depending on whatever fonts a Jenkins worker happens to
have. Pillow is pinned and hash-locked; no runtime font downloads are needed.
The installer itself still requires no image-rendering packages.
The trigger-order reminder paraphrases CR **101.4, 117.4–117.5, 603.3–603.3b,
and 605.4a**, checked against the
[official Comprehensive Rules effective November 6, 2026](https://media.wizards.com/2026/downloads/MagicCompRules%2020261106.txt).
The source URL and date are also recorded in the TOML. This is a concise reminder,
not a replacement for the full rules. Review the wording when those rules change;
CI does not download or automatically rewrite rules text.
## Topic files and alternative artwork
Each set can contain any number of topic files, such as `command_zones.toml`,
@ -163,8 +223,22 @@ invalid input leaves that output intact and causes the command/CI to fail.
## Generate XML and build packages
Building requires **Python 3.11+**, using its built-in `tomllib`; no third-party
packages are required. The client installer still supports Python 3.8+.
Building requires **Python 3.11+** and the pinned Pillow renderer. Set up the build
environment once (with `uv` installed), then activate it before the commands below:
```sh
uv venv --python python3 .venv
uv pip sync --python .venv/bin/python --require-hashes requirements-build.lock
. .venv/bin/activate
```
Without uv, use `python3 -m venv .venv`, then
`.venv/bin/python -m pip install --require-hashes -r requirements-build.lock` and
activate the environment. On Windows use `.venv\Scripts\python.exe` and the
appropriate activation command. The client installer still supports Python 3.8+
and does not require Pillow. To update the renderer deliberately, edit
`requirements-build.txt` and regenerate the lock with
`uv pip compile requirements-build.txt --generate-hashes -o requirements-build.lock`.
```sh
python3 scripts/build.py
@ -174,7 +248,7 @@ This command reads every `sets/*/*.toml`, generates XML and stages artwork
under `dist/sets/<SET_CODE>/`, then creates `dist/<SET_CODE>.zip`. ZIPs contain
only generated XML and artwork, not TOML. Stable ordering, identities, and ZIP
timestamps make repeated builds reproducible. Removed generated files are cleared
on the next successful build. On Windows, use `py -3.11 scripts/build.py` (or newer).
on the next successful build. On Windows, use `.venv\Scripts\python.exe scripts/build.py`.
For XML generation alone or a check that generated output matches current sources:
@ -306,8 +380,10 @@ publication skip message. Concurrent builds of the publication job are disabled.
Do not configure duplicate jobs that publish to the same destinations.
The confirmed worker label is `rust_nodocker`. It must provide Git, Bash, and
Python 3.11+ with its standard library (including `tomllib`). The pipeline verifies these tools and
installs nothing. No submodules, Git LFS, or tag-dependent build steps are needed.
Python 3.11+ with `tomllib`, `venv`, and pip. The pipeline verifies these tools,
creates `.venv`, and installs Pillow from `requirements-build.lock` with hash
verification. Network access to the configured Python package index is required
for that dependency step; uv is optional locally and is not required on Jenkins. No submodules, Git LFS, or tag-dependent build steps are needed.
Checkout uses the job's configured SCM credentials; no credential ID is embedded
in this repository. Publication uses the worker's filesystem permissions and
requires no additional Jenkins credential binding.
@ -334,7 +410,8 @@ within each destination category; collisions fail before publication. Artwork UR
are generated from the TOML artwork filenames.
The pipeline starts with a clean workspace, checks the Bash mock, runs generation,
installer, and publication tests, generates XML from TOML, builds ZIPs, prepares
installer, rendering, and publication tests, renders reminder images and generates
XML from TOML, builds ZIPs, prepares
the public payload, and verifies every payload and ZIP
against the sources. It fingerprints and archives `dist/*.zip`,
`dist/publish/cards/*`, `dist/publish/xml/*.xml`, `dist/publish/install.sh`, and
@ -349,7 +426,7 @@ file. The complete multi-file update is not a transaction; a failure may leave
some files updated. Re-running a successful build safely replaces the same names.
Unrelated and obsolete remote files are never deleted.
Local equivalents (start with a clean generated `dist/` directory):
Local equivalents (activate `.venv` and start with a clean generated `dist/` directory):
```sh
bash -n deploy.sh

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,187 @@
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
Bitstream Vera Fonts Copyright
------------------------------
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.
Arev Fonts Copyright
------------------------------
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:
The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.
The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".
This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.
The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.
TeX Gyre DJV Math
-----------------
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
(on behalf of TeX users groups) are in public domain.
Letters imported from Euler Fraktur from AMSfonts are (c) American
Mathematical Society (see below).
Bitstream Vera Fonts Copyright
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
is a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license (“Fonts”) and associated
documentation
files (the “Font Software”), to reproduce and distribute the Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute,
and/or sell copies of the Font Software, and to permit persons to whom
the Font Software is furnished to do so, subject to the following
conditions:
The above copyright and trademark notices and this permission notice
shall be
included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional
glyphs or characters may be added to the Fonts, only if the fonts are
renamed
to names not containing either the words “Bitstream” or the word “Vera”.
This License becomes null and void to the extent applicable to Fonts or
Font Software
that has been modified and is distributed under the “Bitstream Vera”
names.
The Font Software may be sold as part of a larger software package but
no copy
of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
INABILITY TO USE
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the names of GNOME, the GNOME
Foundation,
and Bitstream Inc., shall not be used in advertising or otherwise to promote
the sale, use or other dealings in this Font Software without prior written
authorization from the GNOME Foundation or Bitstream Inc., respectively.
For further information, contact: fonts at gnome dot org.
AMSFonts (v. 2.2) copyright
The PostScript Type 1 implementation of the AMSFonts produced by and
previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
available for general use. This has been accomplished through the
cooperation
of a consortium of scientific publishers with Blue Sky Research and Y&Y.
Members of this consortium include:
Elsevier Science IBM Corporation Society for Industrial and Applied
Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)
In order to assure the authenticity of these fonts, copyright will be
held by
the American Mathematical Society. This is not meant to restrict in any way
the legitimate use of the fonts, such as (but not limited to) electronic
distribution of documents containing these fonts, inclusion of these fonts
into other public domain or commercial font collections or computer
applications, use of the outline data to create derivative fonts and/or
faces, etc. However, the AMS does require that the AMS copyright notice be
removed from any derivative versions of the fonts which have been altered in
any way. In addition, to ensure the fidelity of TeX documents using Computer
Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
has requested that any alterations which yield different font metrics be
given a different name.
$Id$

95
requirements-build.lock Normal file
View File

@ -0,0 +1,95 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements-build.txt --generate-hashes --output-file requirements-build.lock
pillow==12.0.0 \
--hash=sha256:0869154a2d0546545cde61d1789a6524319fc1897d9ee31218eae7a60ccc5643 \
--hash=sha256:09f2d0abef9e4e2f349305a4f8cc784a8a6c2f58a8c4892eea13b10a943bd26e \
--hash=sha256:0b817e7035ea7f6b942c13aa03bb554fc44fea70838ea21f8eb31c638326584e \
--hash=sha256:0fd00cac9c03256c8b2ff58f162ebcd2587ad3e1f2e397eab718c47e24d231cc \
--hash=sha256:110486b79f2d112cf6add83b28b627e369219388f64ef2f960fef9ebaf54c642 \
--hash=sha256:1979f4566bb96c1e50a62d9831e2ea2d1211761e5662afc545fa766f996632f6 \
--hash=sha256:1ac11e8ea4f611c3c0147424eae514028b5e9077dd99ab91e1bd7bc33ff145e1 \
--hash=sha256:1b1b133e6e16105f524a8dec491e0586d072948ce15c9b914e41cdadd209052b \
--hash=sha256:1ee80a59f6ce048ae13cda1abf7fbd2a34ab9ee7d401c46be3ca685d1999a399 \
--hash=sha256:21f241bdd5080a15bc86d3466a9f6074a9c2c2b314100dd896ac81ee6db2f1ba \
--hash=sha256:266cd5f2b63ff316d5a1bba46268e603c9caf5606d44f38c2873c380950576ad \
--hash=sha256:26d9f7d2b604cd23aba3e9faf795787456ac25634d82cd060556998e39c6fa47 \
--hash=sha256:27f95b12453d165099c84f8a8bfdfd46b9e4bda9e0e4b65f0635430027f55739 \
--hash=sha256:2c54c1a783d6d60595d3514f0efe9b37c8808746a66920315bfd34a938d7994b \
--hash=sha256:2fa5f0b6716fc88f11380b88b31fe591a06c6315e955c096c35715788b339e3f \
--hash=sha256:32ed80ea8a90ee3e6fa08c21e2e091bba6eda8eccc83dbc34c95169507a91f10 \
--hash=sha256:3830c769decf88f1289680a59d4f4c46c72573446352e2befec9a8512104fa52 \
--hash=sha256:38df9b4bfd3db902c9c2bd369bcacaf9d935b2fff73709429d95cc41554f7b3d \
--hash=sha256:3adfb466bbc544b926d50fe8f4a4e6abd8c6bffd28a26177594e6e9b2b76572b \
--hash=sha256:3e42edad50b6909089750e65c91aa09aaf1e0a71310d383f11321b27c224ed8a \
--hash=sha256:4078242472387600b2ce8d93ade8899c12bf33fa89e55ec89fe126e9d6d5d9e9 \
--hash=sha256:455247ac8a4cfb7b9bc45b7e432d10421aea9fc2e74d285ba4072688a74c2e9d \
--hash=sha256:4cc6b3b2efff105c6a1656cfe59da4fdde2cda9af1c5e0b58529b24525d0a098 \
--hash=sha256:4cf7fed4b4580601c4345ceb5d4cbf5a980d030fd5ad07c4d2ec589f95f09905 \
--hash=sha256:5193fde9a5f23c331ea26d0cf171fbf67e3f247585f50c08b3e205c7aeb4589b \
--hash=sha256:5269cc1caeedb67e6f7269a42014f381f45e2e7cd42d834ede3c703a1d915fe3 \
--hash=sha256:53561a4ddc36facb432fae7a9d8afbfaf94795414f5cdc5fc52f28c1dca90371 \
--hash=sha256:55f818bd74fe2f11d4d7cbc65880a843c4075e0ac7226bc1a23261dbea531953 \
--hash=sha256:58eea5ebe51504057dd95c5b77d21700b77615ab0243d8152793dc00eb4faf01 \
--hash=sha256:5d5c411a8eaa2299322b647cd932586b1427367fd3184ffbb8f7a219ea2041ca \
--hash=sha256:6846bd2d116ff42cba6b646edf5bf61d37e5cbd256425fa089fee4ff5c07a99e \
--hash=sha256:6ace95230bfb7cd79ef66caa064bbe2f2a1e63d93471c3a2e1f1348d9f22d6b7 \
--hash=sha256:6e51b71417049ad6ab14c49608b4a24d8fb3fe605e5dfabfe523b58064dc3d27 \
--hash=sha256:71db6b4c1653045dacc1585c1b0d184004f0d7e694c7b34ac165ca70c0838082 \
--hash=sha256:7438839e9e053ef79f7112c881cef684013855016f928b168b81ed5835f3e75e \
--hash=sha256:759de84a33be3b178a64c8ba28ad5c135900359e85fb662bc6e403ad4407791d \
--hash=sha256:792a2c0be4dcc18af9d4a2dfd8a11a17d5e25274a1062b0ec1c2d79c76f3e7f8 \
--hash=sha256:7d87ef5795da03d742bf49439f9ca4d027cde49c82c5371ba52464aee266699a \
--hash=sha256:7dfb439562f234f7d57b1ac6bc8fe7f838a4bd49c79230e0f6a1da93e82f1fad \
--hash=sha256:7fa22993bac7b77b78cae22bad1e2a987ddf0d9015c63358032f84a53f23cdc3 \
--hash=sha256:805ebf596939e48dbb2e4922a1d3852cfc25c38160751ce02da93058b48d252a \
--hash=sha256:82240051c6ca513c616f7f9da06e871f61bfd7805f566275841af15015b8f98d \
--hash=sha256:87d4f8125c9988bfbed67af47dd7a953e2fc7b0cc1e7800ec6d2080d490bb353 \
--hash=sha256:8d8ca2b210ada074d57fcee40c30446c9562e542fc46aedc19baf758a93532ee \
--hash=sha256:8dc232e39d409036af549c86f24aed8273a40ffa459981146829a324e0848b4b \
--hash=sha256:90387104ee8400a7b4598253b4c406f8958f59fcf983a6cea2b50d59f7d63d0b \
--hash=sha256:905b0365b210c73afb0ebe9101a32572152dfd1c144c7e28968a331b9217b94a \
--hash=sha256:99353a06902c2e43b43e8ff74ee65a7d90307d82370604746738a1e0661ccca7 \
--hash=sha256:99a7f72fb6249302aa62245680754862a44179b545ded638cf1fef59befb57ef \
--hash=sha256:9f0b04c6b8584c2c193babcccc908b38ed29524b29dd464bc8801bf10d746a3a \
--hash=sha256:9fe611163f6303d1619bbcb653540a4d60f9e55e622d60a3108be0d5b441017a \
--hash=sha256:a3475b96f5908b3b16c47533daaa87380c491357d197564e0ba34ae75c0f3257 \
--hash=sha256:a6597ff2b61d121172f5844b53f21467f7082f5fb385a9a29c01414463f93b07 \
--hash=sha256:a7921c5a6d31b3d756ec980f2f47c0cfdbce0fc48c22a39347a895f41f4a6ea4 \
--hash=sha256:aa5129de4e174daccbc59d0a3b6d20eaf24417d59851c07ebb37aeb02947987c \
--hash=sha256:aeaefa96c768fc66818730b952a862235d68825c178f1b3ffd4efd7ad2edcb7c \
--hash=sha256:afbefa430092f71a9593a99ab6a4e7538bc9eabbf7bf94f91510d3503943edc4 \
--hash=sha256:aff9e4d82d082ff9513bdd6acd4f5bd359f5b2c870907d2b0a9c5e10d40c88fe \
--hash=sha256:b22bd8c974942477156be55a768f7aa37c46904c175be4e158b6a86e3a6b7ca8 \
--hash=sha256:b290fd8aa38422444d4b50d579de197557f182ef1068b75f5aa8558638b8d0a5 \
--hash=sha256:b2e4b27a6e15b04832fe9bf292b94b5ca156016bbc1ea9c2c20098a0320d6cf6 \
--hash=sha256:b583dc9070312190192631373c6c8ed277254aa6e6084b74bdd0a6d3b221608e \
--hash=sha256:b87843e225e74576437fd5b6a4c2205d422754f84a06942cfaf1dc32243e45a8 \
--hash=sha256:bc91a56697869546d1b8f0a3ff35224557ae7f881050e99f615e0119bf934b4e \
--hash=sha256:bd87e140e45399c818fac4247880b9ce719e4783d767e030a883a970be632275 \
--hash=sha256:bde737cff1a975b70652b62d626f7785e0480918dece11e8fef3c0cf057351c3 \
--hash=sha256:bdee52571a343d721fb2eb3b090a82d959ff37fc631e3f70422e0c2e029f3e76 \
--hash=sha256:bee2a6db3a7242ea309aa7ee8e2780726fed67ff4e5b40169f2c940e7eb09227 \
--hash=sha256:beeae3f27f62308f1ddbcfb0690bf44b10732f2ef43758f169d5e9303165d3f9 \
--hash=sha256:c50f36a62a22d350c96e49ad02d0da41dbd17ddc2e29750dbdba4323f85eb4a5 \
--hash=sha256:c607c90ba67533e1b2355b821fef6764d1dd2cbe26b8c1005ae84f7aea25ff79 \
--hash=sha256:c7b2a63fd6d5246349f3d3f37b14430d73ee7e8173154461785e43036ffa96ca \
--hash=sha256:c828a1ae702fc712978bda0320ba1b9893d99be0badf2647f693cc01cf0f04fa \
--hash=sha256:c85de1136429c524e55cfa4e033b4a7940ac5c8ee4d9401cc2d1bf48154bbc7b \
--hash=sha256:c98fa880d695de164b4135a52fd2e9cd7b7c90a9d8ac5e9e443a24a95ef9248e \
--hash=sha256:cae81479f77420d217def5f54b5b9d279804d17e982e0f2fa19b1d1e14ab5197 \
--hash=sha256:d034140032870024e6b9892c692fe2968493790dd57208b2c37e3fb35f6df3ab \
--hash=sha256:d120c38a42c234dc9a8c5de7ceaaf899cf33561956acb4941653f8bdc657aa79 \
--hash=sha256:d4827615da15cd59784ce39d3388275ec093ae3ee8d7f0c089b76fa87af756c2 \
--hash=sha256:d49e2314c373f4c2b39446fb1a45ed333c850e09d0c59ac79b72eb3b95397363 \
--hash=sha256:d52610d51e265a51518692045e372a4c363056130d922a7351429ac9f27e70b0 \
--hash=sha256:d64317d2587c70324b79861babb9c09f71fbb780bad212018874b2c013d8600e \
--hash=sha256:d77153e14b709fd8b8af6f66a3afbb9ed6e9fc5ccf0b6b7e1ced7b036a228782 \
--hash=sha256:d7e091d464ac59d2c7ad8e7e08105eaf9dafbc3883fd7265ffccc2baad6ac925 \
--hash=sha256:dd333073e0cacdc3089525c7df7d39b211bcdf31fc2824e49d01c6b6187b07d0 \
--hash=sha256:e5d8efac84c9afcb40914ab49ba063d94f5dbdf5066db4482c66a992f47a3a3b \
--hash=sha256:f135c702ac42262573fe9714dfe99c944b4ba307af5eb507abef1667e2cbbced \
--hash=sha256:f13711b1a5ba512d647a0e4ba79280d3a9a045aaf7e0cc6fbe96b91d4cdf6b0c \
--hash=sha256:f4f1231b7dec408e8670264ce63e9c71409d9583dd21d32c163e25213ee2a344 \
--hash=sha256:fa3ed2a29a9e9d2d488b4da81dcb54720ac3104a20bf0bd273f1e4648aff5af9 \
--hash=sha256:fb3096c30df99fd01c7bf8e544f392103d0795b9f98ba71a8054bcbf56b255f1
# via -r requirements-build.txt

2
requirements-build.txt Normal file
View File

@ -0,0 +1,2 @@
# Pinned renderer; client installation still uses only the Python standard library.
Pillow==12.0.0

View File

@ -96,7 +96,7 @@ def render(folder):
for index, token in enumerate(tokens, 1):
label = f'tokens[{index}]'
keys(token, {'id', 'name', 'description', 'artwork', 'number', 'uuid', 'rarity',
'type', 'mana_cost', 'colors', 'power', 'toughness', 'tablerow', 'properties', 'alternatives'}, label)
'type', 'mana_cost', 'colors', 'power', 'toughness', 'tablerow', 'properties', 'alternatives', 'render'}, label)
identifier = filename(token.get('id'), f'{label}.id')
name = filename(token.get('name'), f'{label}.name')
number = token.get('number', identifier)
@ -108,12 +108,21 @@ def render(folder):
if value in seen[key]:
raise ValueError(f'{label}: duplicate {key}: {value}')
seen[key].add(value)
description = text(token.get('description'), f'{label}.description').strip()
picture = text(token.get('artwork'), f'{label}.artwork')
if 'render' in token:
if (not picture.startswith('artwork/') or '..' in Path(picture).parts
or Path(picture).suffix != '.png' or Path(picture).as_posix() != picture):
raise ValueError(f'{label}: rendered artwork must be a PNG path under artwork/')
if picture in artwork:
raise ValueError(f'{label}: generated artwork would overwrite another image: {picture}')
from render_cards import render_card
artwork[picture] = render_card(folder, token)
if picture not in artwork:
raise ValueError(f'{label}: artwork must name an existing image under artwork/: {picture}')
card = ET.SubElement(cards, 'card')
ET.SubElement(card, 'name').text = name
ET.SubElement(card, 'text').text = text(token.get('description'), f'{label}.description').strip()
ET.SubElement(card, 'text').text = description
card_type = text(token.get('type', 'Token'), f'{label}.type')
mana = token.get('mana_cost', '')
colors = token.get('colors', '')

93
scripts/render_cards.py Normal file
View File

@ -0,0 +1,93 @@
"""Deterministic Pillow text overlays for TOML-defined reminder cards."""
from io import BytesIO
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
FONTS = Path(__file__).resolve().parents[1] / 'assets/fonts'
def wrap(draw, text, font, width):
lines = []
for paragraph in text.split('\n'):
if not paragraph.strip():
lines.append('')
continue
line = ''
for word in paragraph.split():
if draw.textlength(word, font=font) > width:
raise ValueError(f'Word cannot fit the text panel: {word}')
candidate = f'{line} {word}'.strip()
if draw.textlength(candidate, font=font) > width:
lines.append(line)
line = word
else:
line = candidate
lines.append(line)
return lines
def render_card(folder, token):
options = token['render']
allowed = {'template', 'box', 'title', 'footer', 'font_size', 'min_font_size', 'title_size', 'color'}
if not isinstance(options, dict) or options.keys() - allowed:
raise ValueError('render must be a table with only supported layout options')
relative = options.get('template')
if not isinstance(relative, str):
raise ValueError('render.template is required')
template = folder / relative
if not relative.startswith('templates/') or '..' in Path(relative).parts or template.resolve() != template.absolute():
raise ValueError('render.template must be a non-symlink file inside templates/')
with Image.open(template) as original:
image = original.convert('RGBA')
draw = ImageDraw.Draw(image)
box = options.get('box', [100, 150, 650, 1050])
if (not isinstance(box, list) or len(box) != 4 or any(type(v) is not int for v in box)
or not 0 <= box[0] < box[2] <= image.width or not 0 <= box[1] < box[3] <= image.height):
raise ValueError('render.box must be [left, top, right, bottom] inside the template')
left, top, right, bottom = box
width = right - left
sizes = {name: options.get(name, default) for name, default in
[('font_size', 28), ('min_font_size', 22), ('title_size', 44)]}
if any(type(v) is not int or not 8 <= v <= 200 for v in sizes.values()) or sizes['min_font_size'] > sizes['font_size']:
raise ValueError('Invalid render font sizes (8–200, minimum <= preferred)')
title = options.get('title', token['name'])
body = token['description'].strip()
footer = options.get('footer', '')
if not isinstance(title, str) or not title.strip() or not isinstance(footer, str):
raise ValueError('render.title and render.footer must be strings; title must not be empty')
title_font = ImageFont.truetype(str(FONTS / 'DejaVuSerif-Bold.ttf'), sizes['title_size'], layout_engine=ImageFont.Layout.BASIC)
title_lines = wrap(draw, title, title_font, width)
title_step = sum(title_font.getmetrics()) + 4
title_height = len(title_lines) * title_step
footer_font = ImageFont.truetype(str(FONTS / 'DejaVuSerif.ttf'), 16, layout_engine=ImageFont.Layout.BASIC)
footer_lines = wrap(draw, footer, footer_font, width) if footer else []
footer_height = len(footer_lines) * 23
body_top = top + title_height + 35
available = bottom - body_top - (footer_height + 25 if footer else 0)
fitted = None
for size in range(sizes['font_size'], sizes['min_font_size'] - 1, -1):
font = ImageFont.truetype(str(FONTS / 'DejaVuSerif.ttf'), size, layout_engine=ImageFont.Layout.BASIC)
try:
lines = wrap(draw, body, font, width)
except ValueError:
continue
step = sum(font.getmetrics()) + 5
if len(lines) * step <= available:
fitted = (font, lines, step)
break
if fitted is None:
raise ValueError(f'{token["name"]}: reminder text does not fit; shorten it or enlarge render.box (minimum font size is enforced)')
color = options.get('color', '#192b3b')
for index, line in enumerate(title_lines):
x = left + (width - draw.textlength(line, font=title_font)) / 2
draw.text((x, top + index * title_step), line, font=title_font, fill=color, anchor='lt')
draw.line((left + 35, body_top - 20, right - 35, body_top - 20), fill='#ad772b', width=2)
font, lines, step = fitted
for index, line in enumerate(lines):
draw.text((left, body_top + index * step), line, font=font, fill=color, anchor='lt')
for index, line in enumerate(footer_lines):
draw.text((left, bottom - footer_height + index * 23), line, font=footer_font, fill=color, anchor='lt')
output = BytesIO()
image.save(output, format='PNG', optimize=False, compress_level=9)
return output.getvalue()

31
sets/TKR/reminders.toml Normal file
View File

@ -0,0 +1,31 @@
# Paraphrased from the official Comprehensive Rules effective 2026-11-06.
# https://media.wizards.com/2026/downloads/MagicCompRules%2020261106.txt
# CR 101.4, 117.4–117.5, 603.3–603.3b, 605.4a.
[[tokens]]
id = "reminder-trigger-order"
name = "Reminder - Trigger Order"
artwork = "artwork/reminders/reminder-trigger-order.png" # Generated; do not create this by hand.
type = "Emblem"
description = """
Triggers wait until a player would get priority. Finish resolving the current spell or ability, then handle state-based actions.
STACK IN APNAP ORDER
The active player (whose turn it is) stacks their triggers first. Other players follow in turn order. Each player chooses the order of their own triggers.
TWO PASSES
First stack triggers not caused by another ability triggering. Then repeat APNAP for those remaining triggers. Recheck state-based actions and new triggers before priority.
RESOLVE TOP FIRST
When everyone passes consecutively, resolve the top item only. Players get priority again before the next item resolves.
Triggered mana abilities skip the stack.
"""
[tokens.render]
template = "templates/reminders/reminder-larger.png"
title = "TRIGGER ORDER"
box = [100, 155, 655, 1100]
font_size = 27
min_font_size = 23
title_size = 36
footer = "CR 101.4 · 117.4–5 · 603.3b · 605.4a\nRules reminder • 6 November 2026"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

@ -0,0 +1,69 @@
import importlib.util
from io import BytesIO
from pathlib import Path
import sys
import tempfile
import unittest
from unittest.mock import patch
from PIL import Image
SCRIPTS = Path(__file__).resolve().parents[1] / 'scripts'
SPEC = importlib.util.spec_from_file_location('renderer', SCRIPTS / 'render_cards.py')
renderer = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(renderer)
class RenderTests(unittest.TestCase):
def setUp(self):
self.temporary = tempfile.TemporaryDirectory()
self.addCleanup(self.temporary.cleanup)
self.folder = Path(self.temporary.name)
(self.folder / 'templates').mkdir()
Image.new('RGB', (800, 1200), '#eee0bd').save(self.folder / 'templates/reminder.png')
self.token = {'name': 'Reminder', 'description': 'First paragraph.\n\nSecond paragraph.',
'render': {'template': 'templates/reminder.png', 'box': [50, 50, 650, 1000]}}
def test_repeatable_render_and_preserved_background(self):
before = (self.folder / 'templates/reminder.png').read_bytes()
data = renderer.render_card(self.folder, self.token)
self.assertEqual(data, renderer.render_card(self.folder, self.token))
image = Image.open(BytesIO(data))
self.assertEqual(image.size, (800, 1200))
self.assertEqual(image.getpixel((799, 1199)), (238, 224, 189, 255))
self.assertNotEqual(image.crop((50, 50, 650, 1000)).getextrema()[0][0], 238)
self.assertEqual(before, (self.folder / 'templates/reminder.png').read_bytes())
self.token['description'] = 'Changed from TOML.'
self.assertNotEqual(data, renderer.render_card(self.folder, self.token))
def test_overflow_fails_instead_of_clipping(self):
self.token['description'] = 'Too much text. ' * 2000
with self.assertRaisesRegex(ValueError, 'does not fit'):
renderer.render_card(self.folder, self.token)
def test_invalid_layout_and_template_rejected(self):
for changes in ({'box': [0, 0, 900, 100]}, {'min_font_size': 100},
{'template': '../outside.png'}, {'unknown': 'typo'}):
with self.subTest(changes=changes):
token = dict(self.token, render=dict(self.token['render'], **changes))
with self.assertRaises(ValueError):
renderer.render_card(self.folder, token)
def test_generated_reminder_enters_xml_and_artwork_without_templates(self):
spec = importlib.util.spec_from_file_location('generator', SCRIPTS / 'generate_xml.py')
generator = importlib.util.module_from_spec(spec)
spec.loader.exec_module(generator)
import xml.etree.ElementTree as ET
with patch.object(sys, 'path', [str(SCRIPTS)] + sys.path):
generated = generator.planned_files(SCRIPTS.parent / 'sets')
path = Path('TKR/artwork/reminders/reminder-trigger-order.png')
self.assertTrue(generated[path].startswith(b'\x89PNG'))
self.assertFalse(any('templates' in p.parts for p in generated))
root = ET.fromstring(generated[Path('TKR/01.customtokens.xml')])
card = next(c for c in root.findall('./cards/card') if c.findtext('name') == 'Reminder - Trigger Order')
self.assertIn('APNAP', card.findtext('text'))
self.assertTrue(card.find('set').get('picurl').endswith('/reminder-trigger-order.png'))
if __name__ == '__main__':
unittest.main()