Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latex template visual improvements #171

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dungeonsheets/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def carrying_weight(self):
if self.shield:
weight += 6
weight += sum([self.cp, self.sp, self.ep, self.gp, self.pp]) / 50
return round(weight, 2)
return round(weight)

@property
def equipment_text(self):
Expand All @@ -839,11 +839,13 @@ def equipment_text(self):
for item in self.magic_items:
sub_list += item.name + ", "
eq_list += [sub_list[:-2]]
cw, cc = self.carrying_weight, self.carrying_capacity
eq_list += [f"**Weight:** {cw} lb\n\n**Capacity:** {cc} lb"]

return "\n\n".join(eq_list)

@property
def weight_and_capacity_text(self):
cw, cc = self.carrying_weight, self.carrying_capacity
return f"**Weight:** {cw} lb **Capacity:** {cc} lb"

@property
def proficiencies_by_type(self):
prof_dict = {}
Expand Down Expand Up @@ -927,7 +929,7 @@ def spell_casting_info(self):
prepared = s in self.spells_prepared
level_info = level_names[s.level]
info_there = spell_list.get(level_info, [])
spell_list[level_info] = info_there + [(s.name, prepared)]
spell_list[level_info] = info_there + [(re.sub(r"\$", r"\$", str(s)), prepared)]
spell_info["list"] = spell_list
return spell_info

Expand Down
19 changes: 6 additions & 13 deletions dungeonsheets/forms/MSavage_template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
% Headline
\CharacterName{[[ char.name ]]}

% adds only main class and total level to prevent overflow
\Class{[[ char.primary_class.name ]] [[ char.level ]]}
\Class{[[ char.classes_and_levels ]]}
\Background{[[ char.background ]]}
\PlayerName{[[ char.player_name ]]}
\Race{[[ char.race ]]}
Expand Down Expand Up @@ -187,7 +186,7 @@
[%- endfor -%]
}

\Equipment{[[ char.equipment_text| boxed ]]}
\Equipment{[[ char.equipment_text| boxed -]] \\ \footnotesize{[[ char.weight_and_capacity_text| boxed ]]}}

\PersonalityTraits{[[ char.personality_traits ]]}

Expand All @@ -212,7 +211,7 @@
% background

\CharacterAppearance{[[ portrait ]]
[[ char.appearance_text ]]
[[- char.appearance_text -]]
}
\AdditionalFeaturesAndTraits{[[ char.additional_description ]]}

Expand All @@ -224,12 +223,6 @@

\OrganizationName{[[ char.org_name ]]}

[% if char.is_spellcaster %]
%Magic
[[ char | spellsheetparser ]]
[% endif %]


\begin{document}
\newgeometry{left=0cm,right=0cm,top=0cm,bottom=0cm}
\onecolumn
Expand All @@ -243,10 +236,10 @@
\pdfbookmark[0]{Background Sheet}{Background Sheet}
\renderbackgroundsheet

[% if char.is_spellcaster %]
[% if char.is_spellcaster -%]
% SPELLCASTING PAGE
\pdfbookmark[0]{Spellcasting Sheet}{Spellcasting Sheet}
\spellsheetchoice
[% endif %]
[[ char | spellsheetparser ]]
[%- endif -%]

\end{document}
81 changes: 55 additions & 26 deletions dungeonsheets/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def rst_to_latex(rst, top_heading_level: int=0, format_dice: bool = True, use_dn

return tex


def rst_to_boxlatex(rst):
"""Adapted rst translation from dungeonsheets latex module, removing
dice parsing and indentation."""
Expand All @@ -262,6 +263,7 @@ def rst_to_boxlatex(rst):
tex = tex.replace('\n\n', ' \\\\\n')
return tex


def msavage_spell_info(char):
"""Generates the spellsheet for msavage template."""
headinfo = char.spell_casting_info["head"]
Expand Down Expand Up @@ -310,33 +312,60 @@ def msavage_spell_info(char):
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z"]

# spellList is a dict.
# The keys in spellList are the level names, the values are lists of tuples:
# Each tuple consists of two elements: a spell name and a boolean for prepared.
# So: spellList = {levelname : [(spellname, preparedbool), ]}
spellList = char.spell_casting_info["list"]
# As default, assume fullcaster character and set spellsheet accordingly
tex4="\\newcommand{\spellsheetchoice}{\\renderspellsheet}"
for k, v in spellList.items():
slots_max = fullcaster_sheet_spaces[k]
halfcaster_slots_max = halfcaster_sheet_spaces[k]
only_low_level = all((char.spell_slots(level) == 0 for level in range(6, 10)))
# Determine which sheet to use (caster or half-caster).
# Prefer caster, unless we have no spells > 5th level and
# would overflow the caster sheet, then use half-caster.
if len(v) > slots_max and only_low_level:
slots_max=halfcaster_slots_max
tex4="\\newcommand{\spellsheetchoice}{\\renderhalfspellsheet}"
if len(v) > slots_max:
vsel = sorted(v, key=lambda x: x[1], reverse=True)
else:
vsel = v[:]
for spinfo, slot in zip(vsel[:slots_max], comp_letters):
slot_command = "\\"+k+'Slot'+slot
slot_command_name = slot_command+"{"+spinfo[0]+"}"
if k == "Cantrip":
texT = texT + [slot_command_name]
continue
slot_command_prep = slot_command+"Prepared"+"{"+str(spinfo[1])+"}"
texT = texT + [slot_command_name, slot_command_prep]
tex3 = "\n".join(texT) + '\n'
return "\n".join([tex1, tex2, tex3, tex4])
# Default, assume fullcaster character and associated spellsheet.
fullcaster = True
# Determine which sheet to use (fullcaster or halfcaster).
# Only use halfcaster when we have no spells > 5th level and
# would overflow the fullcaster sheet.
# Keep the same sheet for overflow pages, if any.
only_low_level = all((char.spell_slots(level) == 0 for level in range(6, 10)))
if (any(len(spellList[key]) > fullcaster_sheet_spaces[key] for key in spellList.keys())
and only_low_level):
fullcaster = False

def AddSpellPage(fullcaster = True):
texT = []
for k, v in spellList.items():
spells_this_level_and_page = len(v)
if fullcaster:
spellsheet_command = "\\renderspellsheet"
slots_max = fullcaster_sheet_spaces[k]
else:
spellsheet_command = "\\renderhalfspellsheet"
slots_max = halfcaster_sheet_spaces[k]
for spinfo, slot in zip(v[:slots_max], comp_letters):
spellList[k].remove(spinfo)
slot_command = "\\"+k+'Slot'+slot
slot_command_name = slot_command+"{"+spinfo[0]+"}"
if k == "Cantrip":
texT = texT + [slot_command_name]
continue
slot_command_prep = slot_command+"Prepared"+"{"+str(spinfo[1])+"}"
texT = texT + [slot_command_name, slot_command_prep]
# Set remaining slots empty
for empty_slot in comp_letters[spells_this_level_and_page:slots_max]:
slot_command = "\\"+k+'Slot'+empty_slot
slot_command_name = slot_command+"{}"
if k == "Cantrip":
texT = texT + [slot_command_name]
continue
slot_command_prep = slot_command+"Prepared{False}"
texT = texT + [slot_command_name, slot_command_prep]
if (not len(spellList[k]) == 0
and not spellList[k][0][0] == "--- Overflow ---"):
spellList[k].insert(0, ("--- Overflow ---", False))
return "\n".join(texT) + '\n\n' + spellsheet_command + '\n\n'

tex3 = ""
while any(spellList.values()):
tex3 = tex3 + AddSpellPage(fullcaster)
return "\n".join([tex1, tex2, tex3])


def RPGtex_monster_info(char):
"""Generates the headings for the monster block info in the DND latex style"""
Expand Down
2 changes: 1 addition & 1 deletion dungeonsheets/make_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def msavage_sheet(character, basename, debug=False):
if re.search(r"" + character.portrait, str(image[0])):
character.images.remove(image)
break
portrait_command = r"\includegraphics[width=5.75cm]{" + character.portrait + "}"
portrait_command = r"{\centering \includegraphics[width=5.75cm,height=7.85cm,keepaspectratio]{" + character.portrait + "} \\\\ \\noindent}"

# Move symbol image a bit left, if applicable
if character.symbol:
Expand Down
Loading