From d110ef6cdafa6ea2338f74f11ae1a156dd39f7ae Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Sun, 11 Jul 2021 23:03:36 -0500 Subject: [PATCH] Bug fixes and EPUB CSS improvements. --- dungeonsheets/classes/druid.py | 2 ++ dungeonsheets/epub.py | 19 +++++----- .../forms/character_sheet_template.html | 36 +++++++++---------- .../forms/druid_shapes_template.html | 12 +++---- dungeonsheets/forms/dungeonsheets_epub.css | 36 ++++++++++++++++--- dungeonsheets/make_sheets.py | 9 ++--- dungeonsheets/readers.py | 1 + 7 files changed, 73 insertions(+), 42 deletions(-) diff --git a/dungeonsheets/classes/druid.py b/dungeonsheets/classes/druid.py index 794cb22..0a6fb93 100644 --- a/dungeonsheets/classes/druid.py +++ b/dungeonsheets/classes/druid.py @@ -329,6 +329,8 @@ class Druid(CharClass): valid_swim = max_swim is None or shape.swim_speed <= max_swim valid_fly = max_fly is None or shape.fly_speed <= max_fly can_assume = shape.is_beast and valid_cr and valid_swim and valid_fly + if shape.name == "Spider": + assert can_assume return can_assume @property diff --git a/dungeonsheets/epub.py b/dungeonsheets/epub.py index 94f87b0..9677b66 100644 --- a/dungeonsheets/epub.py +++ b/dungeonsheets/epub.py @@ -36,9 +36,9 @@ def create_epub( book.set_language("en") # Add the css files css_template = jinja_env.get_template("dungeonsheets_epub.css") - dl_widths = { # Width for dl lists, in 'em' units + dl_widths = { # Width for dl lists, in 'em' units "character-details": 11, - "combat-stats": 18, + "combat-stats": 15, "proficiencies": 8.5, "faction": 6, "spellcasting": 12.5, @@ -118,13 +118,17 @@ class HeadingParser(HTMLParser): def handle_endtag(self, tag): this_level = self.heading_level(tag) - if this_level is not None and this_level == self._curr_level: + if this_level is not None and this_level == self._curr_level and self._curr_id is not None: heading = { "level": this_level, "id": self._curr_id, "title": self._curr_title, } self.headings.append(heading) + # Reset the current values + self._curr_level = None + self._curr_id = None + self._curr_title = None def handle_data(self, data): # Save the title @@ -151,10 +155,6 @@ def toc_from_headings( A sequence of table-of-contents links. """ - # [(, - # [(, - # [, - # ])])] # Parse the HTML parser = HeadingParser() parser.feed(html) @@ -278,7 +278,10 @@ def rst_to_html(rst, top_heading_level=0): def to_heading_id(inpt: str) -> str: """Take a string and make it suitable for use as an HTML header id.""" - return inpt.replace(" ", "-").replace("'", "") + bad_characters = ["'", "(", ")", "&", "/", "+", ",", "=", ] + for c in bad_characters: + inpt = inpt.replace(c, "") + return inpt.replace(" ", "-") diff --git a/dungeonsheets/forms/character_sheet_template.html b/dungeonsheets/forms/character_sheet_template.html index 762e992..97935ff 100644 --- a/dungeonsheets/forms/character_sheet_template.html +++ b/dungeonsheets/forms/character_sheet_template.html @@ -33,9 +33,9 @@
[[ character.hair ]] 
-

Combat Statistics

+

Combat Statistics

-
+
Armor Class
[[ character.armor_class ]]
Initiative
@@ -138,33 +138,33 @@

Additional Treasure

- +
[[ character.treasure ]] - +

Personality Traits

- +
[[ character.personality_traits ]] - +

Ideals

- +
[[ character.ideals ]] - +

Bonds

- +
[[ character.bonds ]] - +

Flaws

- +
[[ character.flaws ]] - +

Appearance

@@ -175,18 +175,18 @@
[[ character.faction_name ]] 
- +
[[ character.allies ]] - +

Additional Features & Traits

- +
[[ character.other_feats_traits ]] - +

Backstory

- +
[[ character.backstory ]] - +
diff --git a/dungeonsheets/forms/druid_shapes_template.html b/dungeonsheets/forms/druid_shapes_template.html index 69753f6..d01b71d 100644 --- a/dungeonsheets/forms/druid_shapes_template.html +++ b/dungeonsheets/forms/druid_shapes_template.html @@ -2,11 +2,9 @@ [% for shape in character.all_wild_shapes|sort(attribute='challenge_rating') %] - - +

[[ shape.name ]]

- [% if shape.description %]

[[ shape.description ]]

[% endif %] @@ -45,10 +43,10 @@
Immunities
[[ shape.condition_immunities ]] 
- +
[[ shape.__doc__ | rst_to_html(top_heading_level=2) ]] - +
- [% endfor %] + -
+[% endfor %] diff --git a/dungeonsheets/forms/dungeonsheets_epub.css b/dungeonsheets/forms/dungeonsheets_epub.css index 276b537..a98872a 100644 --- a/dungeonsheets/forms/dungeonsheets_epub.css +++ b/dungeonsheets/forms/dungeonsheets_epub.css @@ -1,7 +1,32 @@ +[% if use_dnd_decorations %] +/* With fancy decorations */ h1, h2, h3, h4, h5, h6 { - color: #58180d; + color: #58180d; + font-family: sans-serif; +} +body { + background: #ECDDB4; +} +table { + background: #ECEEE3; +} +tr:nth-child(even) { + background: #CDD290; +} +th { + font-family: sans-serif } + +[% else %] +/* Without Fancy decorations */ + +th { + border-style: solid; + border-width: 0px; + border-bottom-width: 1px; +} +[% endif %] /* End fancy decorations */ /* Spell lists */ @@ -63,7 +88,7 @@ dl.[[ class ]] dd { /* For showing beasts */ .known-beast-disabled { - color: lightgrey; + opacity: 0.33; } /* Errors in rst conversion or missing content */ @@ -85,10 +110,11 @@ table { margin-bottom: 10px; } +table p { + margin: 0px; +} + th { - border-style: solid; - border-width: 0px; - border-bottom-width: 1px; padding-left: 5px; padding-right: 5px; text-align: center; diff --git a/dungeonsheets/make_sheets.py b/dungeonsheets/make_sheets.py index 6b42a57..db9e8d9 100755 --- a/dungeonsheets/make_sheets.py +++ b/dungeonsheets/make_sheets.py @@ -9,7 +9,7 @@ import re from pathlib import Path from multiprocessing import Pool, cpu_count from itertools import product -from typing import Union, Sequence, Optional, Literal, List +from typing import Union, Sequence, Optional, List from dungeonsheets import ( character as _char, @@ -210,6 +210,7 @@ def make_gm_sheet( char_file = gm_file.parent / char_file char_file = char_file.resolve() # Load the character file + log.debug(f"Loading party member: {char_file}") character_props = readers.read_sheet_file(char_file) member = _char.Character.load(character_props) party.append(member) @@ -304,7 +305,7 @@ def make_gm_sheet( def make_character_content( character: Character, - content_format: Literal["tex", "html"], + content_format: str, fancy_decorations: bool = False,) -> List[str]: """Prepare the inner content for a character sheet. @@ -323,7 +324,7 @@ def make_character_content( character The character to render content for. content_format - Which markup syntax to use. + Which markup syntax to use, "tex" or "html". fancy_decorations Use fancy page layout and decorations for extra sheets, namely the dnd style file for *tex*, or extended CSS for *html*. @@ -436,7 +437,7 @@ def make_character_sheet( character=character, basename=char_base, flatten=flatten ) pages.append(char_pdf) - Person_pdf = create_personality_pdf_template( + person_pdf = create_personality_pdf_template( character=character, basename=person_base, flatten=flatten ) pages.append(person_pdf) diff --git a/dungeonsheets/readers.py b/dungeonsheets/readers.py index b75d6d0..4e1b228 100644 --- a/dungeonsheets/readers.py +++ b/dungeonsheets/readers.py @@ -74,6 +74,7 @@ class BaseCharacterReader: The path to the file that will be imported. """ + print(filename) self.filename = filename def __call__(self, filename):