Spellbook Generator Prototype

Creating game materials? Monsters, spells, classes, adventures? This is the place!
Pholus
Posts: 32
Joined: Tue Mar 06, 2018 8:31 pm

Spellbook Generator Prototype

Post Sat Jun 08, 2019 7:49 pm

Okay, I went away for a couple of months but this weekend my son is recovering from ACL surgery and I have a lot of time sitting on my keester waiting to readjust a leg brace, add ice, change positions, and on and on and on as needed. So I decided to scratch my itch a bit more...

This is I wanted to do with my spell lists, though what I am showing is pretty crude compared to what it could be. In March I had created and contributed pdfs of all the spells on cards organized by source and class, one file per combination. They printed out at several pages EACH and nobody wants to print that all off for the handful of spells you actually want for your game. What I *actually* envisioned in the long term was a program that would generate just the handful of spell cards relevant for any given character!

I am very sorry to use such odd programming choices, but you go with what you know. I am writing this on Linux, in perl, generating output files which then must be run through LaTeX. If this was for my use alone, it might be crude but it works for me and I would be done! But I think this is useful and certainly could be turned into an online tool as well -- and I want to see if there was any interest or potential collaborators.

I have attached a tarfile with my prototype perl script and a directory with the 926 spells from the rulebook, Libram Magica and all the supplements. To see what the output looks like I have attached a pdf generated for Zelinth from Morgansfort. The steps I took to run the script and create the pdf are included in the terminal transcript attachment. My menus are definitely tedious but in that tediousness is a flexibility as well -- I could generate a spellbook with spells from different sources or even classes in its current form. It should be trivial to be able to add your own spells to the database - they just need to follow the filename formats!
Attachments
SpellbookTerminalTranscript.txt
(6.91 KiB) Downloaded 24 times
Make_Spellbook.tgz
(333.75 KiB) Downloaded 26 times
zelinth_spellbook.pdf
(79.68 KiB) Downloaded 32 times
User avatar
chiisu81
Posts: 2709
Joined: Fri Aug 19, 2011 3:05 pm
Location: TX, USA

Re: Spellbook Generator Prototype

Post Mon Jun 10, 2019 10:41 am

I hope you don't mind, I moved the terminal transcript to a text file attachment.
Pholus
Posts: 32
Joined: Tue Mar 06, 2018 8:31 pm

Re: Spellbook Generator Prototype

Post Mon Jun 10, 2019 2:06 pm

Not at all! I should have thought of it...but was intent on trying to show what I was trying to do via example run.

Cheers!
User avatar
Solomoriah
Site Admin
Posts: 7684
Joined: Thu Nov 13, 2008 8:15 pm
Location: LaBelle, Missouri
Contact:

Re: Spellbook Generator Prototype

Post Mon Jun 10, 2019 8:58 pm

Y'know, I've had good luck with generating LibreOffice/OpenOffice files with Python; I suspect Perl would work as well. An ODT file is just a zip containing a bunch of files, one of which is content.xml, the actual text contents (with some layout) of the document. What I've done is to create a basic document with the styles etc. that I want, then unzipped it and manually parsed the XML, creating "boilerplate" that I put in my script. The script generates a new content.xml and zips it into an ODT file along with copies of the rest of the files found in the original ODT. Voila! Formatted document output from a script.

I used this technique on a recent dungeon, which I doubt I'll publish (due to some limitations that I worked around a lot in play). The dungeon had a LOT of rooms, and I generated most of them programmatically.
My personal site: www.gonnerman.org
borgar
Posts: 68
Joined: Thu Apr 20, 2017 4:58 am
Location: Oslo, Norway

Re: Spellbook Generator Prototype

Post Thu Jun 13, 2019 6:54 am

Not sure why perl should be considered such an odd programming language. It has it's quirks (like a quite horrible syntax) but the text processing capability is really exceptional. And though it's not as popular as it was was a decade or two ago it's hardly obscure.

The ODF::lpOD modules look like it might give suitable ODT support in perl if that is required (though I haven't used this myself).

BTW, if you can split the content and the formatting it would be easier for someone else to help with creating other output formats (like HTML and ODT). If the LaTex "code" reasonably uniform across all spells it shouldn't be too hard to define a "meta format" for the spell description and have the LaTex code inserted as a separate step.
borgar
Posts: 68
Joined: Thu Apr 20, 2017 4:58 am
Location: Oslo, Norway

Re: Spellbook Generator Prototype

Post Thu Jun 13, 2019 7:04 am

I forgot to add that I can get the this to work using Cygwin (cygwin.org) which more or less install a unix system on Windows. I just made sure the installation included the _texlive_ packages.

texlive-collection-latex
texlive-collection-latexextra
texlive-collection-latexrecommended

BTW, I would not survive on Windows without Cygwin (being a Unix guy myself).

Borgar
Pholus
Posts: 32
Joined: Tue Mar 06, 2018 8:31 pm

Re: Spellbook Generator Prototype

Post Thu Jun 13, 2019 8:18 am

When it comes to unpacking an odt document the joke writes itself: "And I thought they smelled bad on the OUTSIDE!"

Just a joke, that's REALLY cool to be able to do that. I guess the next few steps are to try to find a card template I like (for libreoffice I have not had good luck with google though I can likely just use a 3 column layout document with custom borders), do some tests to figure out the boundaries of how I can place text in them to make sure it doesn't overrun, reformat my LaTeX snippets into something more user-friendly and customizable, then write the program in python this time (mostly because I'd like to make a self-contained windows executable for distribution so pyinstaller seems handy). Won't happen on the fly but this is definitely looking like a fun side project.
Pholus
Posts: 32
Joined: Tue Mar 06, 2018 8:31 pm

Re: Spellbook Generator Prototype

Post Thu Jun 13, 2019 8:21 am

borgar wrote:
Thu Jun 13, 2019 7:04 am

BTW, I would not survive on Windows without Cygwin (being a Unix guy myself).
I know, right? People think that since I do computers that Windows is natural. It's quite the opposite mostly because so much is hidden from you in the name of simplicity. I learned python, but after 20 years of perl (and my own massive legacy codebase of processing software) it's just my native language. Then again, for this application the ability to make a Windows executable seems to say python wins on the details this time... ;)
Pholus
Posts: 32
Joined: Tue Mar 06, 2018 8:31 pm

Re: Spellbook Generator Prototype

Post Thu Jun 13, 2019 8:53 am

Okay I am definitely able to create a simple card template (attached as cardtemplate.odt) with a simple content, duplicated it a bunch of times, and wrote it out. I used cut and paste to create nine "cards" in the template and then used zip to open the file. Everything was exactly as Solomariah described. That is pretty cool!

As an experiment for the generator I then took a "card" in content.xml and duplicated the xml blocks content.xml three more times (for a total of 12 cards), saved it, then zipped the subdirectory into "zip.odt." It opened nicely in libreoffice and added the new three cards.

That takes me to a glitch. It's funny because I have created some rather large documents in libreoffice for work and the only frustration I ever have with it is layout just like this. The three added cards come up with one extra space between each card that blows the alignment.

Oh well, it's my new shower problem for a while but if anyone knows how to make that newline go away that would be awesome!
Attachments
zip.odt
(27.01 KiB) Downloaded 18 times
cardtemplate.odt
(25.6 KiB) Downloaded 23 times
User avatar
Solomoriah
Site Admin
Posts: 7684
Joined: Thu Nov 13, 2008 8:15 pm
Location: LaBelle, Missouri
Contact:

Re: Spellbook Generator Prototype

Post Fri Jun 14, 2019 1:04 am

borgar wrote:
Thu Jun 13, 2019 6:54 am
Not sure why perl should be considered such an odd programming language. It has it's quirks (like a quite horrible syntax) but the text processing capability is really exceptional. And though it's not as popular as it was was a decade or two ago it's hardly obscure.
I had to go back and look... I didn't say that perl was an "odd language," I just said I use Python and perl should work as well. But yeah, the syntax is awful to read; Python is, IMO, much much better.

SO I just looked at zip.odt and I honestly have no idea how you built those "cards." I'd use single-cell tables, as they are pretty stable, relatively easy to style, and amenable to programmatic construction.
My personal site: www.gonnerman.org
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests