mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-06-07 13:15:53 +02:00
Allow importing of homebrew material stored in a separate module.
This commit is contained in:
@@ -310,7 +310,10 @@ files:
|
|||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
import my_homebrew
|
from dungeonsheets import import_homebrew
|
||||||
|
|
||||||
|
|
||||||
|
my_homebrew = import_homebrew("my_campaign.py")
|
||||||
|
|
||||||
weapons = ["shortsword", my_homebrew.DullSword]
|
weapons = ["shortsword", my_homebrew.DullSword]
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ __all__ = (
|
|||||||
"race",
|
"race",
|
||||||
"background",
|
"background",
|
||||||
"spells",
|
"spells",
|
||||||
|
"import_homebrew"
|
||||||
)
|
)
|
||||||
|
|
||||||
from dungeonsheets import background, features, race, spells, weapons, mechanics
|
from dungeonsheets import background, features, race, spells, weapons, mechanics
|
||||||
from dungeonsheets.character import Character
|
from dungeonsheets.character import Character
|
||||||
|
from dungeonsheets.homebrew import import_homebrew
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
"""Tools useful for defining homebrew content."""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
import importlib.util
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
|
def import_homebrew(filepath: Union[str, Path]):
|
||||||
|
"""Import a module file containing homebrew content.
|
||||||
|
|
||||||
|
This is intended to be used in a character/GM sheet to load in
|
||||||
|
homebrew content defined in an external file.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
==========
|
||||||
|
filepath
|
||||||
|
The location of the python file containing the homebrew content.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
=======
|
||||||
|
mod
|
||||||
|
The imported module of homebrew content.
|
||||||
|
|
||||||
|
"""
|
||||||
|
spec = importlib.util.spec_from_file_location("module.name", filepath)
|
||||||
|
mod = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(mod)
|
||||||
|
return mod
|
||||||
@@ -7,3 +7,5 @@ from dungeonsheets.infusions import Infusion
|
|||||||
from dungeonsheets.weapons import Weapon
|
from dungeonsheets.weapons import Weapon
|
||||||
from dungeonsheets.armor import Armor, Shield
|
from dungeonsheets.armor import Armor, Shield
|
||||||
from dungeonsheets.magic_items import MagicItem
|
from dungeonsheets.magic_items import MagicItem
|
||||||
|
from dungeonsheets.monsters import Monster
|
||||||
|
from dungeonsheets.stats import Ability
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ Modify this file as you level up and then re-generate the character
|
|||||||
sheet by running ``makesheets`` from the command line.
|
sheet by running ``makesheets`` from the command line.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from dungeonsheets import mechanics
|
from dungeonsheets import mechanics, import_homebrew
|
||||||
|
|
||||||
|
# Load the module containing the homebrew content.
|
||||||
|
campaign = import_homebrew("homebrew_campaign.py")
|
||||||
|
|
||||||
dungeonsheets_version = "0.9.4"
|
dungeonsheets_version = "0.9.4"
|
||||||
|
|
||||||
@@ -93,7 +96,7 @@ class LegoShield(mechanics.Shield):
|
|||||||
base_armor_class = 114
|
base_armor_class = 114
|
||||||
|
|
||||||
|
|
||||||
weapons = (DullSword, "rusty_shiv") # Example: ('shortsword', 'longsword')
|
weapons = (DullSword, "rusty_shiv", campaign.BrightSword) # Example: ('shortsword', 'longsword')
|
||||||
magic_items = (RobeOfBreadSummoning, "staff_of_the_arbor_abode")
|
magic_items = (RobeOfBreadSummoning, "staff_of_the_arbor_abode")
|
||||||
armor = PlasticArmor # Eg "leather armor"
|
armor = PlasticArmor # Eg "leather armor"
|
||||||
shield = LegoShield # Eg "shield"
|
shield = LegoShield # Eg "shield"
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
"""This file defines some homebrew mechanics that can be imported into
|
||||||
|
character sheets using ``dungeonsheets.import_homebrew``. See
|
||||||
|
``homebrew.py`` for an example of how these homebrew mechanics can be
|
||||||
|
used.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from dungeonsheets import mechanics
|
||||||
|
|
||||||
|
|
||||||
|
class BrightSword(mechanics.Weapon):
|
||||||
|
"""Give you enemies the old razzle-dazzle."""
|
||||||
|
name = "Brightsword"
|
||||||
Reference in New Issue
Block a user