Organize custom sets and add packaging and mock deployment

This commit is contained in:
Dandaedre 2026-11-10 11:10:10 +01:00
parent 5eb708a3db
commit 9723f20991
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
10 changed files with 198 additions and 2 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/dist/
__pycache__/
*.pyc

26
AGENTS.md Normal file
View File

@ -0,0 +1,26 @@
# Repository instructions
## Purpose and layout
- Maintain custom Cockatrice sets and artwork with the eventual goal of automatic
installation and updates.
- Edit sources in `sets/<SET_CODE>/`, with XML at the set folder root and images
in `artwork/`. Preserve original imports in `archives/` when useful.
- 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
explicitly requested. Keep their behavior consistent.
- Update README.md when layout or supported behavior changes. Distinguish working
features from planned installation and updates.
## Validation and commits
- Run the builder after source or packaging changes. Check Bash syntax and run
the preview after changing deploy.sh. Validate deploy.ps1 using PowerShell
when available, and report when unavailable.
- You shall make a Git commit for every completed modification or user request
that changes this repository. Group edits for one request into a coherent commit
with a descriptive message after appropriate validation.
- Commit only files belonging to the request and preserve unrelated user changes.
Do not amend or rewrite existing commits unless requested.
- If a commit cannot be created, report the blocker rather than claiming success.

View File

@ -1,3 +1,72 @@
# cockatrice-custom-tokens
# Cockatrice custom sets and tokens
A collection of custom Magic: The Gathering tokens for Cockatrice, with an easy-to-use installer to automatically download, install, and update token artwork.
This project aims to automatically add and keep up to date the custom Cockatrice
sets stored in this repository, including token artwork.
Currently implemented: editable set sources, reproducible ZIP packaging, and mock
deployment previews. Automatic downloading, installation, and updates are planned.
## Layout
```text
sets/TKR/
01.customtokens.xml Custom useful tokens set
artwork/
Command_zone.png Original artwork
Command_zone_updated.png Updated artwork
archives/customtokens.zip Original imported XML archive
scripts/build.py ZIP builder and basic XML validation
dist/ Generated ZIPs (ignored by Git)
deploy.sh Bash deployment preview
deploy.ps1 PowerShell deployment preview
AGENTS.md Contributor and agent instructions
```
## Add or update sets
1. Create `sets/<SET_CODE>/`, matching the code declared in the XML.
2. Extract incoming XML directly into that folder and put images in `artwork/`.
Keep original import archives in `archives/` when useful.
3. Edit these sources, rebuild packages, and run a deployment preview.
4. Commit the completed change. Do not hand-edit generated ZIPs.
The TKR XML is preserved from the original archive, including its remote artwork
URL. The local artwork is bundled for future installer support; these mocks do
not configure Cockatrice to use it.
## Build packages
Requires Python 3 with no third-party dependencies:
```sh
python3 scripts/build.py
```
On Windows, use `py -3 scripts/build.py`. The builder checks each set's XML root
and declared set code, then creates `dist/<SET_CODE>.zip`. Each archive contains
that set's XML and artwork under `<SET_CODE>/`. Stable ordering and timestamps
make builds reproducible. These are distribution bundles, not installers.
The original imported ZIP is preserved in `archives/`.
## Mock deployment
Bash:
```sh
./deploy.sh
```
PowerShell:
```powershell
./deploy.ps1
```
Both commands locate sources relative to the script and print files that a future
installer would deploy. They do not download, install, copy, or delete anything.
Actual installation and automatic updates still need configurable Cockatrice
paths, safe replacement behavior, and tracking of files managed by the installer.
## License
See [LICENSE](LICENSE) for the repository license.

BIN
archives/customtokens.zip Normal file

Binary file not shown.

14
deploy.ps1 Normal file
View File

@ -0,0 +1,14 @@
# Preview only: no files are installed or changed.
$ErrorActionPreference = 'Stop'
$SetsPath = Join-Path $PSScriptRoot 'sets'
if (-not (Test-Path -LiteralPath $SetsPath -PathType Container)) {
throw 'sets directory is missing.'
}
Write-Output 'MOCK deployment: preview only; no files will be changed.'
Get-ChildItem -LiteralPath $SetsPath -Recurse -File |
Sort-Object FullName |
ForEach-Object {
$RelativePath = $_.FullName.Substring($PSScriptRoot.Length + 1)
Write-Output "Would deploy: $RelativePath"
}
Write-Output 'Automatic installation and updates are not implemented yet.'

13
deploy.sh Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Preview only: no files are installed or changed.
set -euo pipefail
root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
if [[ ! -d "$root/sets" ]]; then
printf 'Error: sets directory is missing.\n' >&2
exit 1
fi
printf 'MOCK deployment: preview only; no files will be changed.\n'
while IFS= read -r -d '' file; do
printf 'Would deploy: %s\n' "${file#"$root/"}"
done < <(find "$root/sets" -type f -print0)
printf 'Automatic installation and updates are not implemented yet.\n'

40
scripts/build.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""Validate and reproducibly package the repository's custom sets."""
from pathlib import Path
import xml.etree.ElementTree as ET
from zipfile import ZIP_DEFLATED, ZipFile, ZipInfo
ROOT = Path(__file__).resolve().parents[1]
def main():
sets = sorted(path for path in (ROOT / "sets").iterdir() if path.is_dir())
if not sets:
raise SystemExit("No set directories found.")
# Validate all sets before writing packages.
for folder in sets:
xml_files = sorted(folder.glob("*.xml"))
if not xml_files:
raise SystemExit(f"{folder.name}: no XML files found")
for xml_file in xml_files:
root = ET.parse(xml_file).getroot()
codes = {node.text for node in root.findall("./sets/set/name")}
if root.tag != "cockatrice_carddatabase" or folder.name not in codes:
raise SystemExit(f"{xml_file}: expected Cockatrice set {folder.name}")
output = ROOT / "dist"
output.mkdir(exist_ok=True)
for folder in sets:
target = output / f"{folder.name}.zip"
with ZipFile(target, "w", compression=ZIP_DEFLATED) as archive:
for source in sorted(folder.rglob("*")):
if source.is_file():
entry = ZipInfo(source.relative_to(ROOT / "sets").as_posix())
entry.compress_type = ZIP_DEFLATED
entry.create_system = 3
entry.external_attr = 0o100644 << 16
archive.writestr(entry, source.read_bytes())
print(f"Built {target.relative_to(ROOT)}")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<cockatrice_carddatabase version="4">
<sets>
<set>
<name>TKR</name>
<longname>Custom useful tokens</longname>
<settype>Custom</settype>
<releasedate>2025-02-07</releasedate>
</set>
</sets>
<cards>
<card>
<name>Command Zone</name>
<text>At the start of the game, each player puts their commander face up into the command zone. A commander can be cast from the command zone for its normal costs, plus an additional two mana for each previous time it's been cast from the command zone this game. If your commander would be put into your library, hand, graveyard or exile from anywhere, you may return it to your command zone instead.</text>
<prop>
<layout>normal</layout>
<side>front</side>
<type>Emblem</type>
<maintype>Emblem</maintype>
<manacost>0</manacost>
<cmc>0</cmc>
<colors>C</colors>
<coloridentity>C</coloridentity>
<format-commander>legal</format-commander>
</prop>
<set rarity="common" uuid="99c2521c-917d-46be-8c93-9eb0b3f602ba" num="1" picurl="https://proxy.dandaedre.com/dropshare/Cards/Command_zone_updated.png">TKR</set>
<token>1</token>
<tablerow>3</tablerow>
</card>
</cards>
</cockatrice_carddatabase>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB