Bay 12 Games Forum

Please login or register.

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

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

madk

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

Scripts are already allowed to take whatever arguments that Python will allow them to take, though there's not currently a mechanism for allowing *args. (But that's okay, because it's exactly the same thing to just pass a list or other iterable as a named argument.) I don't believe it's practical to have an "uninstall" functionality - making the changes is much easier than reversing them. Instead the user would be expected to keep backups, and if they decide they want to remove some mod or change the load order they would need to re-run the manager with the updated settings.

I understand the documentation is shitty - I'm working on that - but it you might look into how it works before speculating about how to change it. You may find that many of the things you're asking for are there already.

For me, concern regarding ease-of-use is more to do with making it so that users won't need to have programming knowledge to use the mod manager. Eventually I'd like this to mean having easy ini or ini-like configuration files as an option, perhaps even a more graphical interface that could abstract aspects of configuration and management. For usability from the perspective of modders, I believe what I have is a solid foundation. There are improvements I want to make but the essentials are present if not a little buggy in places. Also worth nothing that it's my on the todo list to write diff-based mod functionality into PyDwarf as a mod itself that accepts existing diff-based mods as input and merges them as best it can. (I believe this would actually be simple compared to the querying functionality that's at the core of PyDwarf.)
« Last Edit: May 23, 2015, 09:55:55 pm by madk »
Logged

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #16 on: May 26, 2015, 08:38:56 am »

I'm interested in helping modders to rewrite their mods using PyDwarf. If you have a mod you'd like to end up in the official repo, please let me know! I'll work with you closely to make sure everything gets done smoothly.

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: PyDwarf: Edit your raws with the power of Python
« Reply #17 on: May 26, 2015, 10:17:10 pm »

Ignore me, I asked a dumb question that I answered myself by looking at the code more
« Last Edit: May 26, 2015, 10:24:10 pm by Button »
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #18 on: May 27, 2015, 01:49:42 pm »

I wrote a PyDwarf script which is able to fairly intelligently merge modified raws provided the DF versions all line up. (Understanding changes based on disparate vanilla raws would be a highly nontrivial problem.) It should be listed as the first script to run and given, as an argument, paths to each file or directory that should be merged and applied.

https://github.com/pineapplemachine/PyDwarf/blob/master/scripts/pineapple/pydwarf.diff.py

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #19 on: May 29, 2015, 09:42:04 pm »

There's a tutorial now! And I've generally gone through a lot effort to make PyDwarf more accessible to users and modders.

https://github.com/pineapplemachine/PyDwarf/blob/master/tutorial.md

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: Edit your raws with the power of Python
« Reply #20 on: June 03, 2015, 06:35:45 am »

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #21 on: June 03, 2015, 11:00:33 am »

Hey madk,

Does this support changing individual tokens within tags?
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #22 on: June 03, 2015, 11:21:02 am »

Hey madk,

Does this support changing individual tokens within tags?

Could you elaborate? I always understood the terms "token" and "tag" to be synonymous when speaking of the raws.

Do you mean changing the arguments of a token? i.e. a token being like [VALUE:ARGUMENT_0:ARGUMENT_1:...:ARGUMENT_n]? If so then absolutely. A raws.token object has a value attribute, corresponding to the first item in the list delimited by colons, and an args attribute which is a list of all the other items. There are also helper methods like token.nargs(), token.getarg(), and token.setarg() for things like convenience and input sanitization.
« Last Edit: June 03, 2015, 12:22:51 pm by madk »
Logged

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #23 on: June 03, 2015, 11:37:17 am »

Could you elaborate? I always understood the terms "token" and "tag" to be synonymous when speaking of the raws.

Do you mean changing the arguments of a token? i.e. a token being like [VALUE:ARGUMENT_0:ARGUMENT_1:...:ARGUMENT_n]? If so then absolutely. A raws.token object has a value attribute, corresponding to the first item in the list delimited by semicolons, and an args attribute which is a list of all the other items. There are also helper methods like token.nargs(), token.getarg(), and token.setarg() for things like convenience and input sanitization.

Yes, that's what I meant. I can't speak to the nomenclature, but my understanding has been that a tag is a full [...], and a token is anything between the [ and ], separated by :s, including the part you've designated VALUE.

Are the arguments identified only by their index? How would one go about, say, setting all the time ranges in all GROWTH_PRINT tags to ALL? Or is the range identified as a single "range-type" argument, even though it's got a semicolon in?
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #24 on: June 03, 2015, 11:50:42 am »

Are the arguments identified only by their index? How would one go about, say, setting all the time ranges in all GROWTH_PRINT tags to ALL? Or is the range identified as a single "range-type" argument, even though it's got a semicolon in?

As an effort to make PyDwarf itself as version-agnostic as possible, there is very little implicit handling of anything. None so far of arguments: Everything separated by a colon is a separate argument as far as PyDwarf is concerned, neither does PyDwarf try to discern names or purposes for arguments; they are identified only by their indexes. Here's an example of how to do what you're thinking of:

Code: [Select]
>>> import raws
>>> df = raws.dir(path="raw")
>>> quarrybush = df.getobj('PLANT:BUSH_QUARRY')
>>> growthprint = quarrybush.get('GROWTH_PRINT')
>>> print growthprint
[GROWTH_PRINT:0:6:7:0:0:NONE]
>>> print growthprint.args
['0', '6', '7', '0', '0', 'NONE']
>>> growthprint.args[4] = 'ALL'
>>> growthprint.args[5] = '1'
>>> print growthprint
[GROWTH_PRINT:0:6:7:0:ALL:1]
>>> print growthprint.args
['0', '6', '7', '0', 'ALL', '1']

On nomenclature: "token", "value", "args" seemed to me like the most appropriate terms, coming from my experience with parsers.
« Last Edit: June 03, 2015, 12:22:37 pm by madk »
Logged

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #25 on: June 03, 2015, 01:45:15 pm »

Are the arguments identified only by their index? How would one go about, say, setting all the time ranges in all GROWTH_PRINT tags to ALL? Or is the range identified as a single "range-type" argument, even though it's got a semicolon in?

As an effort to make PyDwarf itself as version-agnostic as possible, there is very little implicit handling of anything. None so far of arguments: Everything separated by a colon is a separate argument as far as PyDwarf is concerned, neither does PyDwarf try to discern names or purposes for arguments; they are identified only by their indexes. Here's an example of how to do what you're thinking of:

Code: [Select]
>>> import raws
>>> df = raws.dir(path="raw")
>>> quarrybush = df.getobj('PLANT:BUSH_QUARRY')
>>> growthprint = quarrybush.get('GROWTH_PRINT')
>>> print growthprint
[GROWTH_PRINT:0:6:7:0:0:NONE]
>>> print growthprint.args
['0', '6', '7', '0', '0', 'NONE']
>>> growthprint.args[4] = 'ALL'
>>> growthprint.args[5] = '1'
>>> print growthprint
[GROWTH_PRINT:0:6:7:0:ALL:1]
>>> print growthprint.args
['0', '6', '7', '0', 'ALL', '1']

OK, although that doesn't really address my question because you started with NONE and went to ALL, I see from your example that I could accomplish what I would be looking for with a slice.

Your example does bring up another question though - what about growths with multiple GROWTH_PRINTs?

Code: [Select]
[GROWTH:LEAVES]
[GROWTH_NAME:apple leaf:apple leaves]
[GROWTH_ITEM:PLANT_GROWTH:NONE:LOCAL_PLANT_MAT:LEAF]
[GROWTH_DENSITY:1000]
[GROWTH_HOST_TILE:BRANCHES_AND_TWIGS]
[GROWTH_HOST_TILE:SAPLING]
[GROWTH_TIMING:0:300000]
[GROWTH_PRINT:0:6:2:0:0:0:209999:1]
[GROWTH_PRINT:0:6:6:0:1:210000:239999:1] autumn color
[GROWTH_PRINT:0:6:4:0:1:240000:269999:1]
[GROWTH_PRINT:0:6:4:0:0:270000:300000:1]
[GROWTH_DROPS_OFF]

There are 4 growth prints which vary only in their args. Can I change the color (args 2-4 inclusive 0-based) of the 2nd GROWTH_PRINT without touching the others?

Quote
On nomenclature: "token", "value", "args" seemed to me like the most appropriate terms, coming from my experience with parsers.

Based on my experience with parsers, I've always considered a token to be the smallest unit of meaning. Each argument in a function is considered a separate token, so it seems odd to talk about a token containing args. A tag is more like a statement than a token. But you do you. :)
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #26 on: June 03, 2015, 02:03:45 pm »

Could you elaborate? I always understood the terms "token" and "tag" to be synonymous when speaking of the raws.

Do you mean changing the arguments of a token? i.e. a token being like [VALUE:ARGUMENT_0:ARGUMENT_1:...:ARGUMENT_n]? If so then absolutely. A raws.token object has a value attribute, corresponding to the first item in the list delimited by semicolons, and an args attribute which is a list of all the other items. There are also helper methods like token.nargs(), token.getarg(), and token.setarg() for things like convenience and input sanitization.

Yes, that's what I meant. I can't speak to the nomenclature, but my understanding has been that a tag is a full [...], and a token is anything between the [ and ], separated by :s, including the part you've designated VALUE.

Are the arguments identified only by their index? How would one go about, say, setting all the time ranges in all GROWTH_PRINT tags to ALL? Or is the range identified as a single "range-type" argument, even though it's got a semicolon in?

Token and tag are synonymous. The VALUE token/tag has one argument, which is the word you're looking for.

Button

  • Bay Watcher
  • Plants Specialist
    • View Profile
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #27 on: June 03, 2015, 02:34:45 pm »

Could you elaborate? I always understood the terms "token" and "tag" to be synonymous when speaking of the raws.

Do you mean changing the arguments of a token? i.e. a token being like [VALUE:ARGUMENT_0:ARGUMENT_1:...:ARGUMENT_n]? If so then absolutely. A raws.token object has a value attribute, corresponding to the first item in the list delimited by semicolons, and an args attribute which is a list of all the other items. There are also helper methods like token.nargs(), token.getarg(), and token.setarg() for things like convenience and input sanitization.

Yes, that's what I meant. I can't speak to the nomenclature, but my understanding has been that a tag is a full [...], and a token is anything between the [ and ], separated by :s, including the part you've designated VALUE.

Are the arguments identified only by their index? How would one go about, say, setting all the time ranges in all GROWTH_PRINT tags to ALL? Or is the range identified as a single "range-type" argument, even though it's got a semicolon in?

Token and tag are synonymous. The VALUE token/tag has one argument, which is the word you're looking for.

Well, if that's the definition then that's the definition, but it's an extraordinarily unhelpful one for performing lexical analysis.
« Last Edit: June 03, 2015, 02:46:34 pm by Button »
Logged
I used to work on Modest Mod and Plant Fixes.

Always assume I'm not seriously back

madk

  • Bay Watcher
    • View Profile
    • pineapplemachine
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #28 on: June 03, 2015, 03:00:51 pm »

OK, although that doesn't really address my question because you started with NONE and went to ALL, I see from your example that I could accomplish what I would be looking for with a slice.

Your example does bring up another question though - what about growths with multiple GROWTH_PRINTs? ... There are 4 growth prints which vary only in their args. Can I change the color (args 2-4 inclusive 0-based) of the 2nd GROWTH_PRINT without touching the others?

I'm not sure I understand what you mean, then. Can you provide some sort of pseudocode example of what you would expect to be able to do?

As for multiple GROWTH_PRINTs, they could be handled like this:

Code: [Select]
>>> pomegranate = df.getobj('PLANT:POMEGRANATE')
>>> print pomegranate
[PLANT:POMEGRANATE]
>>> growths = pomegranate.allprop('GROWTH_PRINT')
>>> print growths
[
                [GROWTH_PRINT:0:6:2:0:0:0:209999:1],
                [GROWTH_PRINT:0:6:6:0:1:210000:239999:1],  autumn color
                [GROWTH_PRINT:0:6:4:0:1:240000:269999:1],
                [GROWTH_PRINT:0:6:4:0:0:270000:300000:1],
                [GROWTH_PRINT:5:5:4:0:1:60000:119999:2],
                [GROWTH_PRINT:'%':'%':4:0:1:120000:200000:3]]
>>> growths[1].args[2] = 'some value'
>>> growths[1].args[3] = 'some other value'
>>> growths[1].args[4] = 'some other value again'
>>> print growths
[
                [GROWTH_PRINT:0:6:2:0:0:0:209999:1],
                [GROWTH_PRINT:0:6:some value:some other value:some other value a
gain:210000:239999:1],  autumn color
                [GROWTH_PRINT:0:6:4:0:1:240000:269999:1],
                [GROWTH_PRINT:0:6:4:0:0:270000:300000:1],
                [GROWTH_PRINT:5:5:4:0:1:60000:119999:2],
                [GROWTH_PRINT:'%':'%':4:0:1:120000:200000:3]]

It might be helpful to see PyDwarf's querying functionality as a bunch of methods that look for tokens in a linked list, starting with some particular token, that match some particular conditions, and ceasing to accumulate matching tokens on some condition. Because that's exactly what it is. All of the querying methods are built on top of a generalized query method that takes filter objects and an iterable collection of tokens as arguments. For example, the method allprop as used in the above code starts from the current token and returns everything with a value of 'GROWTH_PRINT' until it encounters the next token with a value of 'PLANT'. And each of the token objects in the list returned can be operated on in any way from adding more tokens before or after, removing the token, or accessing/modifying its attributes e.g. its arguments.

If you navigate a terminal to your PyDwarf directory, try entering python and entering the same commands as above. (Don't forget to import raws and df = raws.dir(path="..."). You will need to change the path in raws.dir(path="...") to refer to actual raws on your machine.) Screw around with them as you see fit, and the workings should become more apparent.

Well, if that's the definition then that's the definition, but it's an extraordinarily unhelpful one for performing lexical analysis.

Given the raws snippet [CREATURE:DWARF] a lexical scanner would break it down into these elements: '[', 'CREATURE', ':', 'DWARF', ']'. These are formally called lexemes, but are typically referred to as tokens in the context of lexical scanners. In no context that I know of would tokens conventionally refer to 'CREATURE' and 'DWARF' only. The term I've most frequently seen to refer to the tags/tokens in raws is token, for example this wiki page. The first item in the list delimited by colons represents the purpose of the token, and value seemed to me a reasonable term to use. The others elaborate on the first in much the same way as arguments passed to some procedure.
« Last Edit: June 03, 2015, 03:12:46 pm by madk »
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: PyDwarf: A powerful modding utility and mod manager
« Reply #29 on: June 03, 2015, 03:28:17 pm »

Well, if that's the definition then that's the definition, but it's an extraordinarily unhelpful one for performing lexical analysis.

Given the raws snippet [CREATURE:DWARF] a lexical scanner would break it down into these elements: '[', 'CREATURE', ':', 'DWARF', ']'. These are formally called lexemes, but are typically referred to as tokens in the context of lexical scanners. In no context that I know of would tokens conventionally refer to 'CREATURE' and 'DWARF' only. The term I've most frequently seen to refer to the tags/tokens in raws is token, for example this wiki page. The first item in the list delimited by colons represents the purpose of the token, and value seemed to me a reasonable term to use. The others elaborate on the first in much the same way as arguments passed to some procedure.

Generally "token" is used to refer to a lexeme with attached meta-data (location in the file, type, ect).
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS
Pages: 1 [2] 3 4 5