Skip to content

Commit

Permalink
feat: added CardConjurer support
Browse files Browse the repository at this point in the history
Cardconjurer is a generic card editor that can support MTG pretty well.

Changes:
 - Added Model entities
 - Added CLI to parse and render a card
  • Loading branch information
Guibod committed Feb 19, 2023
1 parent 9423a7f commit d96babf
Show file tree
Hide file tree
Showing 22 changed files with 2,341 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Plans

users/installation
users/cli
users/cardconjurer

.. toctree::
:maxdepth: 1
Expand Down
51 changes: 51 additions & 0 deletions docs/source/reference/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,54 @@ Models
Deck
DeckList
CardTypes


Card Conjurer
-------------

`Card Conjurer <https://cardconjurer.com>`_ is a card editor service that provides a unique file format to describe a card image. Each card is described in a JSON file that extends a template. Template may vary from MTG copycat to brand new card frame.

.. list-table::
:header-rows: 1

* - Feature
- Support
* - Template
- ✅ (read-only)
* - Card
- ✅ (read-only)
* - Card Generation
- 🟠 Working for the most part, but inline symbols are not supported

.. list-table::

* - .. figure:: ./cardconjurer.sample.png

Fig 1. Card Conjurer generated image

- .. figure:: ./cardconjurer.mightstone.png

Fig 2. Mightstone generated image


CardConjurer Client
~~~~~~~~~~~~~~~~~~~

.. autoclass:: mightstone.services.cardconjurer.CardConjurer
:members:

Models
~~~~~~

.. currentmodule:: mightstone.services.cardconjurer.models

.. autosummary::
:toctree: _autosummary
:recursive:

Card
Template
Image
Text
Group

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/reference/cardconjurer.sample.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions docs/source/users/cardconjurer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
===============
Card Generation
===============

**mightstone** provides a CardConjurer file format renderer (and parser). As for everything in mightstone, data is parsed into Pydantic objects, and accessed asynchronously.

mightstone don’t support card alteration from an existing json file for the moment.

.. literalinclude:: ../../../examples/card_conjurer.py
:language: python

It is possible to generate your image from our CLI interface:

.. code-block:: bash
python -m src.mightstone.cli cardconjurer render ./tests/mightstone/services/cardconjurer/Dimirova\ Smiley.json ./out.png --base-url="https://card-conjurer-assets.s3.us-east-1.amazonaws.com"
Assets and template availability
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By design CardConjurer tries to decentralize template from their core tool. As is, Card Conjurer does not provide any mean to generate Magic The Gathering alike cards. Instead, you need to build your own template (or get your hands on) that reproduces MTG design. Mightstone won’t provide you any template.

The file format allow a card JSON data to point its parent template, and assets location. Every asset paths are relative to the parent template location. Most of the time, you’ll lose the path to the assets, that’s why you need to provide ``asset_root_url`` explicitly.
16 changes: 16 additions & 0 deletions examples/card_conjurer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import asyncio

from mightstone.services.cardconjurer import CardConjurer

cc = CardConjurer()


async def run():
card = await cc.card("my_card.json")
# You might need to define the remote server if the card was
# remotely built and no asset are present locally
card.asset_root_url = "https://card-conjurer-assets.s3.us-east-1.amazonaws.com"
await cc.render(card, "my_card.png")


asyncio.run(run())
204 changes: 200 additions & 4 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ aiostream = "^0.4.5"
aiosqlite = "^0.18.0"
appdirs = "^1.4.4"
requests = "^2.28.2"
pillow = "^9.4.0"
cairosvg = "^2.6.0"

[tool.poetry.group.docs]
optional = true
Expand Down Expand Up @@ -75,6 +77,7 @@ pyinstaller = "^4.1"
pylint-pydantic = "^0.1.6"
toml = "^0.10.2"
pytest-asyncio = "^0.20.3"
pixelmatch = "^0.3.0"

[build-system]
requires = ["poetry_core>=1.0.0"]
Expand Down
Binary file added src/mightstone/assets/LiberationMono-Regular.ttf
Binary file not shown.
Empty file.
2 changes: 2 additions & 0 deletions src/mightstone/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import mightstone

from ..services.cardconjurer.commands import cardconjurer
from ..services.edhrec.commands import edhrec
from ..services.mtgjson.commands import mtgjson
from ..services.scryfall.commands import scryfall
Expand Down Expand Up @@ -46,3 +47,4 @@ def version(verbose):
cli.add_command(mtgjson)
cli.add_command(scryfall)
cli.add_command(edhrec)
cli.add_command(cardconjurer)

0 comments on commit d96babf

Please sign in to comment.