GM notes can now include arbitrary additional sections as attributes.

This commit is contained in:
Mark Wolfman
2021-07-24 17:40:01 -05:00
parent a1a5d7783a
commit 6bfaddf821
8 changed files with 77 additions and 4 deletions
+23 -1
View File
@@ -50,7 +50,8 @@ Random Tables
=============
Random tables can be used in-game to make decisions on-the-fly. These
tables can be included in the PDF using ``random_tables``. Currently the following random tables are available.
tables can be included in the PDF using ``random_tables``. Currently
the following random tables are available.
- **"conjure animals"** - A list of options to choose from when a
player casts the *Conjure Animals* spell.
@@ -60,3 +61,24 @@ tables can be included in the PDF using ``random_tables``. Currently the followi
random_tables = ["conjure animals"]
Adding Arbitrary Content
========================
Additional content can be included in arbitrary sections that get
added to the end of the GM notes output. In addition to the attributes
described above, suitable extra attributes in the notes (``.py``) file
will be rendered as a new section, with a heading based on the name of
the attribute and a body with the content parsed as restructured
text. Attributes that begin with an underscore ("_") or those that are
not a string will be ignored.
For example, the following entry will be rendered as a new section
with the heading "The Bar Fight":
.. code-block:: python
the_bar_fight = (
"If the characters decide to go to the *Alliance Friendly Bar*, "
"they will probably have to fight their way out against 5 enemies "
"(3 Veteran, 2 Soldier)."
)
+1 -1
View File
@@ -60,7 +60,7 @@ def create_epub(
)
book.add_item(css)
# Add paper background
with open(Path(__file__).parent / "forms/paper.jpg", mode="rb") as fp:
with open(Path(__file__).parent / "forms/paper-low-res.jpg", mode="rb") as fp:
bg_img = fp.read()
paper = epub.EpubItem(
file_name="images/paper.jpg",
@@ -7,6 +7,7 @@ h1, h2, h3, h4, h5, h6 {
body {
/* background: #f4ecdb; */
background-image: url("../images/paper.jpg");
background-size: 100%;
}
table {
/* background: #ECEEE3; */
@@ -0,0 +1,3 @@
<h1 id="[[ title | to_heading_id ]]">[[ title ]]</h1>
[[ rst | rst_to_html ]]
+4
View File
@@ -0,0 +1,4 @@
\pdfbookmark[0]{[[ title ]]}{[[ title ]]}
\section*{[[ title ]]}
[[ rst | rst_to_latex ]]
Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

+19 -2
View File
@@ -117,6 +117,15 @@ def create_random_tables_content(
)
def create_extra_gm_content(rst: str, title: str, suffix: str, use_dnd_decorations: bool=False):
"""Create content for arbitrary additional text provided in a GM sheet."""
template = jinja_env.get_template(f"extra_gm_content.{suffix}")
full_title = title.replace("_", " ").title()
return template.render(
rst=rst, title=full_title, use_dnd_decorations=use_dnd_decorations
)
def make_sheet(
sheet_file: File,
flatten: bool = False,
@@ -258,6 +267,16 @@ def make_gm_sheet(
use_dnd_decorations=fancy_decorations,
)
)
# Parse any extra homebrew attributes, etc.
gm_props.pop("dungeonsheets_version")
gm_props.pop("sheet_type")
extra_gm_attrs = []
for attr, text in gm_props.items():
if isinstance(text, str):
extra_gm_attrs.append(attr)
content.append(create_extra_gm_content(rst=text, title=attr, suffix=content_suffix, use_dnd_decorations=fancy_decorations))
for attr in extra_gm_attrs:
gm_props.pop(attr)
# Add the closing TeX
content.append(
jinja_env.get_template(f"postamble.{format_suffixes[output_format]}").render(
@@ -265,8 +284,6 @@ def make_gm_sheet(
)
)
# Warn about any unhandled sheet properties
gm_props.pop("dungeonsheets_version")
gm_props.pop("sheet_type")
if len(gm_props.keys()) > 0:
msg = f"Unhandled attributes in '{str(gm_file)}': {','.join(gm_props.keys())}"
log.warning(msg)
+26
View File
@@ -5,14 +5,40 @@ monsters, etc.
"""
# This line (or one like it) is required in order for dungeonsheets to
# recognize the file.
dungeonsheets_version = "0.15.0"
# Specifying ``sheet_type = "gm"`` gives us GM notes instead of a
# player character sheet.
sheet_type = "gm"
# A short description of what happened last time, etc.
summary = """The party is about the enter the dungeon of *eternal tortuosity*."""
# A descriptive title to appear at the top of the document.
session_title = "Objects in Space - Session 1"
# Dungeonsheets supports a rudimentary version of cascading sheets. In
# this case, details for the whole campaign can be defined once, then
# sheets can be generated for each specific session using the
# *parent_sheets* attribute.
parent_sheets = ["gm-campaign-notes.py"]
# Defining a *monsters* attribute will include their stat blocks in
# the output
monsters = ["aboleth", "wolf", "giant eagle", "Vashta Nerada", "priest"]
# Arbitrary sections can be added to the GM notes. Any attribute that
# is a string and whose name doesn't start with an underscore ("_")
# will be included as a separate section
BBEG_motivation = (
"""Hans Gruber is after the $640 in bearer bonds stored in *Nakatomi
plaza*."""
)
the_bar_fight = (
"If the characters decide to go to the *Alliance Friendly Bar*, "
"they will probably have to fight their way out against 5 enemies "
"(3 Veteran, 2 Soldier)."
)