Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 5

Author Topic: PyDwarf 1.1.4: Werebeast  (Read 19450 times)

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
PyDwarf 1.1.4: Werebeast
« on: May 18, 2015, 07:37:53 pm »


For players, PyDwarf is an easy way to manage your preferred mods. Never worry about incompatible or obsolete mods again! (Or, at least, not nearly as often.) And for modders, PyDwarf is your new best friend. PyDwarf's mod manager exposes a very handy API for interacting with the raws. Here's an example of how effortless it is to customize raws even from a python console:

Code: [Select]
>>> import raws
>>> df = raws.dir('raw/objects')
>>> elf = df.getobj('CREATURE:ELF')
>>> description = elf.get('DESCRIPTION')
>>> print description
[DESCRIPTION:A medium-sized creature dedicated to the ruthless protection of nature.]
>>> description.setarg('A medium-sized creature undeserving of life.')
>>> df.write('raw/objects')

client-170:PyDwarf pineapple$ grep 'CREATURE:ELF' raw/objects/creature_standard.txt -A 4
[CREATURE:ELF]
    [DESCRIPTION:A medium-sized creature undeserving of life.]
    [NAME:elf:elves:elven]
    [CASTE_NAME:elf:elves:elven]
    [CREATURE_TILE:'e'][COLOR:3:0:0]

Here's just a few examples of the mods included with this release of PyDwarf:
Normally you'd be bound to run into compatibility issues when trying to install so many of these mods at once, and you'd surely have to wait for authors to update their mods before reinstalling everything whenever Dwarf Fortress updates. Not so with PyDwarf. PyDwarf is highly capable of avoiding conflicts between mods, and it cares little about which version of Dwarf Fortress you're modifying. Not only does PyDwarf make it much easier for the player to install mods, it also makes it easier for the modder to craft something excellent. Instead of editing text files on your own, PyDwarf allows you to write scripts which edit them for you: What this means for you is an enormous reduction in tedium.

Here's a step-by-step tutorial to guide you through your first time configuring and running PyDwarf, and here's another tutorial to help you get started creating your first mod. Also, here's a handy list of scripts with which PyDwarf comes packaged. And here's where all those scripts are actually located, in case you'd like to see what their innards look like.

PyDwarf is cross-platform. Only Python 2.7 is required to run PyDwarf.
« Last Edit: October 02, 2017, 05:18:33 am by madk »
Logged

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #1 on: May 18, 2015, 09:51:37 pm »

Looks pretty neat, naturally just as I'm getting comfortable screwing around in lua I'm looking at this trying to see how it works like:
Spoiler (click to show/hide)
Logged
Engraved here is a rendition of an image of the Dwarf Fortress learning curve. All craftsdwarfship is of the highest quality. It depicts an obsidian overhang which menaces with spikes of obsidian and tears. Carved on the overhang is an image of Toady One and the players. The players are curled up in a fetal position. Toady One is laughing. The players are burning.
The VectorCurses+1 tileset strikes the square set and the severed part sails off in an arc!

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #2 on: May 18, 2015, 10:57:08 pm »

Yeah, this'll probably be way better than find in files.

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #3 on: May 19, 2015, 03:14:09 am »

Looks pretty neat, naturally just as I'm getting comfortable screwing around in lua I'm looking at this trying to see how it works like:

Ha, as far as mod creation goes it may seem a bit complex but that's partly due to the fact I haven't made much in the way of documentation yet. If you know the basics of Python - which are easier to pick up than Lua, in my personal opinion - then PyDwarf should be really very easy to use as a modder. I'd like to also make things easier on users, too, though I'm not yet sure how I'm going to do that.

Yeah, this'll probably be way better than find in files.

I should hope so!

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #4 on: May 19, 2015, 01:14:52 pm »

Ohh! I spend a lot of time doing repetitive Notepad++ replace functions, so this could certainly come in handy. I'm not really a programming guy, so Python is the only language I've ever gotten a grasp on.

Here's a suggestion...why not structure your documentation like the PyGame documentation? You list a command, what the output is, what it's best use is and possible values for your arguments. It's really straightforward for newbies.

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #5 on: May 19, 2015, 01:43:05 pm »

Ohh! I spend a lot of time doing repetitive Notepad++ replace functions, so this could certainly come in handy. I'm not really a programming guy, so Python is the only language I've ever gotten a grasp on.

Here's a suggestion...why not structure your documentation like the PyGame documentation? You list a command, what the output is, what it's best use is and possible values for your arguments. It's really straightforward for newbies.

This will definitely be better-suited than find/replace. And making proper documentation is a priority, but I want to make the querying functionality more final before I start to document it, otherwise I'll be changing it too frequently to be practical. I'll mind to look into PyGame for an example of how to structure the docs.

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #6 on: May 20, 2015, 05:34:01 am »

I added a much more complex example script to help show just how powerful PyDwarf can be: https://github.com/pineapplemachine/PyDwarf/blob/master/scripts/pineapple/pydwarf.stoneclarity.py

Using the default settings, stoneclarity will cause ores and gems and such to assume standard appearances. Using this script, there'll be no more confusions for beginners like "Is that coal or is it a gem?" and "Why does cobaltite look like a metal?"
« Last Edit: May 21, 2015, 03:30:17 am by madk »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #7 on: May 20, 2015, 01:29:00 pm »

"Why does cobaltite look like a metal?"

(mostly because it is)

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #8 on: May 20, 2015, 01:45:55 pm »

"Why does cobaltite look like a metal?"

"Why does cobaltite look like something I can smelt?"

notfood

  • Bay Watcher
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #9 on: May 21, 2015, 12:24:38 am »

This is very handy. Thanks for sharing. I'm often overwhelmed by the amount of search and replace I have to do, this is going to make things easier.
Logged

Smurfton

  • Escaped Lunatic
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #10 on: May 23, 2015, 07:04:25 pm »

'd like to also make things easier on users, too, though I'm not yet sure how I'm going to do that.
To do this, create two functions, void install(string filename) and void uninstall(string filename). Both of them will need to be part of an object (Python allows objects, right?) for ease of use purposes. The object should contain a private variable which has a list of mods installed. You'll also need a copy of the raws for reverting purposes.
install() would accept a filename, open that file (which hopefully contains the mod), read it, and eval() the mod contents. Once the mod is installed, append the filename to the private list variable.

uninstall() would accept a filename, make sure that was in the list of installed mods, remove it from the list, copy the list to a temporary variable, delete the remainder of the list, copy the unmodified raws over, then run install() on every item. Alternate solution: have a version of install() that doesn't append to the installed list, and call that.

As an extra, you can overload (Python does that, right?) both so that if no arguments are given, install() is run on a specific folder, and uninstall copies over unmodified raws, and clears the list.

Probably a better way to do uninstall(), but that should work, as a start.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #11 on: May 23, 2015, 07:13:04 pm »

Python is object-oriented.

"Overloading" there seems to be referring to duck typing, which Python has. Or it refers to one function being able to operate on different types by defining a function of the same name for multiple types of arguments, which is not necessary since Python is dynamically-typed.

PeridexisErrant

  • Bay Watcher
  • Dai stihó, Hrasht.
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #12 on: May 23, 2015, 08:12:00 pm »

PTW.  If easier for users is a goal, maybe this could be incorporated as an upgrade to PyLNP's mod merger?  The only requirement is that it take whole modified raw files as inputs and outputs.

<snip>
Setting up default arguments is certainly a good idea, but the rest of the psudeocode is more C (or Java?) than Python.  A detailed response would be more nitpicks than productive.
Logged
I maintain the DF Starter Pack - over a million downloads and still counting!
 Donations here.

lethosor

  • Bay Watcher
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #13 on: May 23, 2015, 08:26:00 pm »

"Overloading" there seems to be referring to duck typing, which Python has. Or it refers to one function being able to operate on different types by defining a function of the same name for multiple types of arguments, which is not necessary since Python is dynamically-typed.
It sounds to me like Smurfton is referring to functions taking a variable number of arguments (which is also possible).

PTW
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #14 on: May 23, 2015, 08:31:15 pm »

Yeah, with *args and **kwargs.
Pages: [1] 2 3 ... 5