Skip to content
Collin Heist edited this page Feb 20, 2023 · 4 revisions

Background

The creative process of creating a custom CardType is detailed on the Maker's wiki here. This page is instead dedicated to explaining how to modify your local custom CardType to become a remote CardType that exists on this repository (and can be used by others).

By nature of the Maker having to download and execute card types hosted on this repository, rather than them existing at runtime, there are a few specific modifications to your CardType classes required.

Assets

The main difference is how assets are referred to and stored. This primarily applies to fonts, and reference images. Since a user using a non-standard CardType will not have access to the font files and reference images (as they're not a part of the TitleCardMaker repository), these assets need to be specified as RemoteFile objects, and uploaded alongside the CardType Python file, so they can be downloaded at runtime.

The basic structure of this, in Python, is:

SOME_FILE = str(RemoteFile('MY_USERNAME', 'FILENAME.ext'))

This looks for and downloads the file at {this repository}/MY_USERNAME/FILENAME.ext. It is important to use the str() (string) of the object, because that returns the user-localized path to where that asset/file is downloaded.

Example

Take the example of my example CardType called BetterStandardTitleCard, located at CollinHeist/BetterStandardTitleCard (here). I am using a non-standard font (Comic Sans), and so I have uploaded that font file within my user folder at CollinHeist/Comic Sans MS.ttf. In order for this Card to download and use that font file, I have specified the file as such:

TITLE_FONT = str(RemoteFile('CollinHeist', 'Comic Sans MS.ttf'))

Reference Directory

If you want your CardType to utilize assets that are found within the TitleCardMaker repository (such as fonts, gradient images, etc.), then it's important to use the correct path. Once downloaded from this Repository, the card is written to /modules/.objects/, so the /modules/ref directory is determined as follows:

REF_DIRECTORY = Path(__file__).parent.parent / 'ref'

This would make the reference assets, such as the Gradient image, accessible at:

GRADIENT_IMAGE = REF_DIRECTORY / 'GRADIENT.png'

Class Structure

Below is pseudo-UML class diagram of the necessary for the custom card types. Only the UserCardType is the responsibility of you, the card creator, the rest of these elements are built-in to TCM.

classDiagram

class ImageMagick {>>service>>}
class ImageMagickInterface {
    <<interface>>
    escape_chars()
    run()
    run_get_output()
    delete_intermediate_files()
    print_command_history()
}
class ImageMaker {
    <<Abstract>>
    __init__()*
    image_magick
    get_image_dimensions()
    get_text_dimensions()
    reduce_file_size()
    convert_svg_to_png()
    create()*
}
class BaseCardType {
    <<Abstract>>
    resize_and_style
    style
    DEFAULT_FONT_CASE = 'upper'
    EPISODE_TEXT_FORMAT = 'EPISODE [episode_number]'
    USES_UNIQUE_SOURCES = True
    BLUR_PROFILE = '0x60'
    TITLE_CHARACTERISTICS*
    ARCHIVE_NAME*
    TITLE_FONT*
    TITLE_COLOR*
    FONT_REPLACEMENTS*
    USES_SEASON_TITLE*
    __init__(blur, grayscale)*
    modify_extras()
    is_custom_font()*
    is_custom_season_titles()*
    create()*
}
class UserCardType {
    Abstract Properties*
    Abstract Methods*
}
class RemoteFile {
    __init__(username, filename)
    __str__()
}

ImageMaker --> ImageMagickInterface : IM Commands
ImageMagickInterface --> ImageMagick : Piped Commands
ImageMagickInterface <-- ImageMagick : stdout\nstderr
ImageMagickInterface <-- ImageMaker : Contains
ImageMaker <-- BaseCardType : SubClasses
BaseCardType <-- UserCardType : SubClasses
UserCardType --> "*" RemoteFile : Contains
Loading
Clone this wiki locally