mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-05-19 04:33:26 +02:00
Added a bunch of spells, and a tools for parsing the json spells list.
This commit is contained in:
+11
-1
@@ -11,6 +11,16 @@ Installation
|
|||||||
|
|
||||||
$ pip install dungeonsheets
|
$ pip install dungeonsheets
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
Dungeon sheets requires **at least python 3.6**. This is mostly due
|
||||||
|
to the liberal use of f-strings_. If you want to use it with
|
||||||
|
previous versions of python 3, you'll probably have to replace all
|
||||||
|
the f-strings with the older ``.format()`` method or string
|
||||||
|
interpolation.
|
||||||
|
|
||||||
|
.. _f-strings: https://www.python.org/dev/peps/pep-0498/
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
@@ -18,7 +28,7 @@ Each character is described by a python file, which gives many
|
|||||||
attributes associated with the character. See examples_ for more
|
attributes associated with the character. See examples_ for more
|
||||||
information about the character descriptions.
|
information about the character descriptions.
|
||||||
|
|
||||||
.. _examples:
|
.. _examples: https://github.com/canismarko/dungeon-sheets/tree/master/examples
|
||||||
|
|
||||||
The PDF's can then be generated using the ``makesheets`` command.
|
The PDF's can then be generated using the ``makesheets`` command.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
OUTFILE = 'spells_new.py'
|
||||||
|
INFILE = '/home/mwolf/Documents/dungeons_and_dragons/spells.json'
|
||||||
|
|
||||||
|
data = json.load(open(INFILE, mode='r'))
|
||||||
|
|
||||||
|
components_re = re.compile('([VSM])?[, ]*([VSM])?[, ]*([VSM])?[, ]*'
|
||||||
|
'(?:\(([-a-zA-Z ,.0-9;’—()]+)\))?')
|
||||||
|
|
||||||
|
def parse_components(string):
|
||||||
|
result = components_re.match(string)
|
||||||
|
components = tuple(r for r in result.groups()[0:3] if r is not None)
|
||||||
|
materials = result.groups()[3]
|
||||||
|
if 'M' in components:
|
||||||
|
assert materials is not None
|
||||||
|
if materials is None:
|
||||||
|
materials = ''
|
||||||
|
return components, materials
|
||||||
|
|
||||||
|
print(parse_components('V'))
|
||||||
|
print(parse_components('V, S'))
|
||||||
|
print(parse_components('S, V'))
|
||||||
|
print(parse_components("V, S, M (a tiny strip of white cloth)"))
|
||||||
|
|
||||||
|
with open(OUTFILE, mode='w') as out:
|
||||||
|
|
||||||
|
for spell_name, spell in data.items():
|
||||||
|
# Read the components list to determine which components there are
|
||||||
|
class_name = ''.join([s.capitalize() for s in spell_name.split()])
|
||||||
|
# Process the components
|
||||||
|
try:
|
||||||
|
components, materials = parse_components(spell["components"])
|
||||||
|
except AssertionError:
|
||||||
|
print(spell_name, spell)
|
||||||
|
new_s = (f'class {class_name}(Spell):\n'
|
||||||
|
f' """{spell["description"]}"""\n'
|
||||||
|
f' name = "{spell_name}"\n'
|
||||||
|
f' level = {spell["level"]}\n'
|
||||||
|
f' casting_time = "{spell["casting_time"]}"\n'
|
||||||
|
f' components = {components}\n'
|
||||||
|
f' materials = "{materials}"\n'
|
||||||
|
f' duration = "{spell["duration"]}"\n'
|
||||||
|
f' magic_school = "{spell["school"].capitalize()}"\n'
|
||||||
|
f' classes = ()\n'
|
||||||
|
'\n\n')
|
||||||
|
# print(new_s)
|
||||||
|
out.write(new_s)
|
||||||
+2746
-2
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user