From 37af2efd792718b8e9a34d20116849d73c9e6ff6 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Sat, 9 May 2020 13:24:35 +0200 Subject: Added cardGen folder, with a script to generate DnD cards. --- cardGen/Health_potion.png | Bin 0 -> 91783 bytes cardGen/README.md | 31 +++++++++++++ cardGen/dndCard.sh | 108 ++++++++++++++++++++++++++++++++++++++++++++++ cardGen/example.txt | 6 +++ cardGen/template.tex | 76 ++++++++++++++++++++++++++++++++ 5 files changed, 221 insertions(+) create mode 100644 cardGen/Health_potion.png create mode 100644 cardGen/README.md create mode 100755 cardGen/dndCard.sh create mode 100644 cardGen/example.txt create mode 100644 cardGen/template.tex diff --git a/cardGen/Health_potion.png b/cardGen/Health_potion.png new file mode 100644 index 0000000..7cf3b87 Binary files /dev/null and b/cardGen/Health_potion.png differ diff --git a/cardGen/README.md b/cardGen/README.md new file mode 100644 index 0000000..7458396 --- /dev/null +++ b/cardGen/README.md @@ -0,0 +1,31 @@ +# dndCard.sh + +Takes some fields from an input file and builds a pdf or image of a card from them. A background +image can be provided; if not, the background will have a plain color. The template is fully +editable or others could be created, just bare in mind that the words between `@`, such as `@name@` +or `@icon@`, are what the script searches for to insert the text and image file names. Don't leave +commented lines since they are uncommented when no background image is found. Related to this, the +lines containing `%bg%` are deleted when no background image is found. + +Usage: + +``` +dndCard.sh [-t templateFile] [-b bodyFile] inputFile +``` + +Example of body file: + +``` +name#Health potion +typetext#Consumable +hint#(Restores 2d4+1 HP) +body#Can be uncorked and drank as an action. The potion restores 2d4+1 HP. It can also be given to other characters in a moment of need. Many other useful properties of the potion could be listed here. +flavor#The potion's red liquid glimmers when agitated. +icon#potion-ball.png +``` + +Example of output, with no image background and using +[an icon](https://game-icons.net/1x1/lorc/potion-ball.html) +from the amazing source [game-icons.net](https://game-icons.net/): + +![Potion card example](Health_potion.png) diff --git a/cardGen/dndCard.sh b/cardGen/dndCard.sh new file mode 100755 index 0000000..c55d753 --- /dev/null +++ b/cardGen/dndCard.sh @@ -0,0 +1,108 @@ +#!/bin/sh +# +# dndCard.sh +# +# Usage: dndCard.sh [-t templateFile] [-b bodyFile] inputFile +# +# Takes some fields from an input file and builds a pdf or image of a card from them. +# +# templateFile indicates the latex template to use. Defaults to template.tex and +# should be provided if such file is not in the working directory +# +# bodyFile indicates a file where the body text is stored, for convenience, +# since this field is usually the longer and should be on one line. +# +# Example input file: +# name#Name of item +# typetext#Type of item +# hint#Hint about the type: a short hint about its effect +# body#Extended description of the item +# flavor#Some free form text for flavor +# icon#Icon file, will default to icon.png +# bgimg#Background file of the image, will default to bg.png +# template#LaTeX template file to use. Will default to template.tex +# +# Dependencies +# A LaTeX distribution which provides the xelatex executable, such as Tex Live +# +# Optional depencencies +# ImageMagick: Uses convert to decorate corners of icon and generate image +# Poppler: Uses pdftoppm to convert pdf to image if ImageMagick is available + +if ! type xelatex >/dev/null; then + echo "There is no xelatex executable in your path. Install a LaTeX + distribution, such as Tex Live, to use this script." + exit 1 +fi + +hasImageMagick="$(type convert)" +hasPdftoppm="$(type pdftoppm)" + +body="" +templateFile="" + +while echo "$1" | grep '^-'; do + case "$1" in + + "-b") + body="$(cat "$2")" + shift 2 + ;; + + "-t") + templateFile="$2" + shift 2 + ;; + + esac +done + +[ -z "$1" ] && echo "Usage: dndCard.sh [-t template] [-b bodyFile] inputFile" && exit 1 + +input="$1" + +name="$(grep '^name' "$input" | awk -F# '{print $2}' )" +typetext="$(grep '^typetext' "$input" | awk -F# '{print $2}')" +hint="$(grep '^hint' "$input" | awk -F# '{print $2}')" +flavor="$(grep '^flavor' "$input" | awk -F# '{print $2}')" +icon="$(grep '^icon' "$input" | awk -F# '{print $2}')" +bgimg="$(grep '^bgimg' "$input" | awk -F# '{print $2}')" +[ -z "$body" ] && body="$(grep '^body' "$input" | awk -F# '{print $2}')" +[ -z "$templateFile" ] && templateFile="$(grep '^template' "$input" | awk -F# '{print $2}')" + +[ -z "$templateFile" ] && templateFile="template.tex" +[ -z "$icon" ] && icon="icon.png" +[ -z "$bgimg" ] && bgimg="bg.png" + +if [ -n "$hasImageMagick" ]; then + iconTarget="/tmp/dndCardIcon.png" + convert "$icon" \( +clone -alpha extract -draw 'fill black polygon 0,0 0,35 35,0 fill white circle 15,15 15,0' \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) -alpha off -compose CopyOpacity -composite "$iconTarget" + icon="$iconTarget" +fi + +sourceText="$(sed -e "s|@name@|${name}|"\ + -e "s|@type@|${typetext}|"\ + -e "s|@hint@|${hint}|"\ + -e "s|@body@|${body}|"\ + -e "s|@flavor@|${flavor}|"\ + -e "s|@icon@|${icon}|"\ + -e "s|@bgimg@|${bgimg}|"\ + "$templateFile")" + +if [ ! -f "$bgimg" ]; then + sourceText=$(echo "$sourceText" | sed -e 's/^%//' -e '/%bg%/d') +fi + +echo "$sourceText" | xelatex >xelatex.log + +fileName="$(echo "$name" | sed 's| |_|g')" + +[ -f texput.aux ] && rm texput.aux +[ -f texput.log ] && rm texput.log +mv texput.pdf "${fileName}.pdf" + +if [ -n "$hasImageMagick" ] && [ -n "$hasPdftoppm" ] && [ -f "${fileName}.pdf" ]; then + pdftoppm "${fileName}.pdf" output + convert output-1.ppm "${fileName}.png" + rm output-*.ppm +fi diff --git a/cardGen/example.txt b/cardGen/example.txt new file mode 100644 index 0000000..997ef5b --- /dev/null +++ b/cardGen/example.txt @@ -0,0 +1,6 @@ +name#Health potion +typetext#Consumable +hint#(Restores 2d4+1 HP) +body#Can be uncorked and drank as an action. The potion restores 2d4+1 HP. It can also be given to other characters in a moment of need. Many other useful properties of the potion could be listed here. +flavor#The potion's red liquid glimmers when agitated. +icon#potion-ball.png diff --git a/cardGen/template.tex b/cardGen/template.tex new file mode 100644 index 0000000..dff4cc7 --- /dev/null +++ b/cardGen/template.tex @@ -0,0 +1,76 @@ +\documentclass[17pt,a4paper,extrafontsizes]{memoir} + +\usepackage{multicol} +\usepackage[spanish]{babel} +\setlength{\columnsep}{-4mm} + +\setstocksize{176mm}{126mm} +\setpagecc{176mm}{126mm}{*} +\settypeblocksize{156mm}{94mm}{*} +\setulmargins{10mm}{*}{*} +\setlrmargins{14mm}{*}{*} +\usepackage{xcolor} + +\setheadfoot{0.2pt}{0.2pt} +\setheaderspaces{2pt}{*}{*} + +\checkandfixthelayout[fixed] + +\pagestyle{empty} + +\usepackage{eso-pic,graphicx} +\usepackage{auto-pst-pdf} + +\usepackage{aurical} +\usepackage{chancery} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} + +%\definecolor{vellumParchment}{RGB}{235, 213, 179} + +\begin{document} + +%\pagecolor{vellumParchment} + +\Fontauri{} + +\noindent +{\Large @name@} + +\rmfamily + +\begin{multicols}{2} + \noindent + {\includegraphics[height=40mm]{@icon@}} + \\ + + \vfill + + \noindent + @type@\\ + {\footnotesize{}@hint@}\\ +\end{multicols} + +\vspace{-14mm} + +\begin{adjustwidth}{-4mm}{0mm} + \begin{center} + \rule{1.1\textwidth}{.6mm} + \end{center} +\end{adjustwidth} + +\begin{Spacing}{0.90} + \small + @body@ + \vfill + \begin{center} + \rule{.6\textwidth}{.4mm}\\ + \vspace{2mm} + @flavor@ + \end{center} +\end{Spacing} + +\AddToShipoutPictureBG*{\includegraphics[width=\paperwidth,height=\paperheight]{@bgimg@}} %bg% +\clearpage %bg% + +\end{document} -- cgit v1.2.1