savagezen / dnd-tools

ARCHIVE - MOVED TO GITLAB | Interactive CLI tools for Dungeons and Dragons 5e
https://gitlab.com/savagezen/dnd-tools
GNU Affero General Public License v3.0
164 stars 34 forks source link

Code cleanup #10

Open lodenrogue opened 6 years ago

lodenrogue commented 6 years ago

How about abstracting some of these features into their own python file? Maybe (suggestion) using some object oriented programming features like polymorphism to simplify all those if, else statements?

savagezen commented 6 years ago

Thanks for the input! I am not familiar with polymorphism or (admittedly) other object oriented features, but will look into them. If you're willing, you're more than willing to do so yourself and make a pull request.

I am aware of the verbose nature of the program; particularly if additional libraries and source material continue to be added. A major stumbling block is that the program is made to install directly to a Linux binary and I am not (yet) knowledgeable as to how to make things other than the main script install. Though, taking a quick look at my PKGBUILD it doesn't appear too complicated, it will just take some experimenting to figure out.

raithwind commented 5 years ago

I don't know what you are doing to turn it into a linux binary, but would that still work if the python script references a config file for the tables? ex all the loot tables could be a json or something that you load in and then expand?

savagezen commented 5 years ago

I've had some time to think about this and, yes, it is possible. My concern previously was that implementing library files would break cross-platform compatibility (e.g. Linux wouldn't use the reference files but would install them and vice-versa for Windows).

However, the library files could be made (JSON or just a file containing a python dictionary / list) for different sources or content categories (weapons, items, art, etc...) or source books. Windows should read it fine as long as the python script in the source reads (imports) them correctly.

The job, then of installing those libraries on Linux doesn't have to fall on this script, but can easily be done by the PKGBUILD which packages the source for (Arch) Linux installation. Other distributions would have to use a more manual process, but the commands would all be referenced in the PKGBUILD.

raithwind commented 5 years ago

That sounds reasonable, and the inclusion of the os module would mean that you could have the files stored in a subdirectory and us os to handle the cross platform compatibility of reading from the subdir?