![]() |
#1 |
Prophet
Join Date: May 2008
Location: Indiana, USA
Posts: 2,939
Donated: $8
![]() |
Help! Need a graf-foo.prf tool (again)
Anybody want to write a little code for me? It seems like I make this request about once a year.
Need a program that will read a typical graf-???.prf file and re-assign the hex values as specified by the user. Typically this program would be used to create a blank space in the tile sheet where I could then insert new tiles, while keeping them organized, near tiles of the same type. It's easy enough to move the tiles around. It's incredibly hard to make the prf changes necessitated by such a move. The program will ask for a range of values to be altered, starting hex address : ending hex address, and then request a third hex address specifying where the values will 'end up'. Given the current prf file format, the program can make the assumption that first value on any given line is the vertical axis (y) and the second is the horizontal (x), not that it matters much as long as the values are handled as pairs. Bare bones, it can assume that there is only one prf file present and therefore should read any prf file in it's own directory and exactly duplicate it line for line, substituting the altered values in place of the originals. It would output the results to a second file appended with -result.prf. Ideally, it will preform this task for each and every prf file present in it's directory. Code:
SAMPLE OUTPUT: GRAF-DVG.PRF FILE FOUND! STARTING SELECTION : 0x85:0x95 ENDING SELECTION : 0x85:0xFF MOVE SELECTION TO : 0x86:0x80 GRAF-DVG-RESULT.PRF CREATED. FINISHED! Once again, bare bones, the programs doesn't need to check for user input error. If for some reason it can't complete it's task, it can just crash gracefully or output a file full of garbage, so long as it doesn't destroy the original file. This program needs to run in windows. Something that can run in a DOS box will be sufficient. Written in C or C++ would be even better, and written as obviously/simply as possible so that I might be able to tweak it with my limited C skills (but anything that does the job as specified here would be just great).
__________________
www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012. My banding life on Buzzkill's ladder. |
![]() |
![]() |
![]() |
#2 |
Adept
Join Date: Apr 2011
Posts: 103
![]() |
Several months ago I wrote some tools that might be close to what you want. one to split a tilesheet into individual tiles based on a pref file and another to build it back together based on a pref file.
They are in my github repository at github.com/blubaron. The tools would be in http://github.com/blubaron/tilesetpr.../tools/console. I think for the tile image names, it only looks at the part of the pref line before the coordinates, but it has been several months since I looked at it. Looking at your post again it seems like you want something that adjusts the pref file. The above tools affect the image file. I don't know about entering the ranges while the program is running, but I can certainly make a console program that loads the ranges/destination from a text file. However, I don't know when I will get to it. Hopefully someone else will do it first. (The source of the above tools in my github repository, which may help.) |
![]() |
![]() |
![]() |
#3 |
Veteran
Join Date: Jun 2007
Posts: 1,388
![]() |
I'm not sure about the exact transformation of values that you want, but I can easily whip the processing bit up in a little Python program.
Give me a few minutes ![]() |
![]() |
![]() |
![]() |
#4 |
Veteran
Join Date: Jun 2007
Posts: 1,388
![]() |
Here's a first stab. You'll need to install Python 3.x -- If you don't already have it, you can get it from http://python.org/download/releases/3.2.2/
EDIT: Do you want all the graf-* files transformed identically once the coordinates have been provided? If so, I could easily add a "loop over all graf-*.prf files" bit of code. (I'd change the output file name format to 'result-X.prf', but hopefully that would be OK.) Code:
#!/usr/bin/env python3 # # Notes: # # Always spits out upper-case hex digits; the current # graf-*.prf files seem to use inconsistent conventions for # this, so this would be non-trivial to work around. # import readline def xform_input(prompt, transform): """Input values from user, apllying a transformation to the input.""" while True: i = input(prompt) ti = transform(i) if ti is not None: return ti else: print("Could not understand input: %s" % (i,)) def xform_coordinate(s): fields = s.split(':') if len(fields) == 2: try: x = int(fields[0], 0) y = int(fields[1], 0) except ValueError as e: return None return (x,y) def hexify(x): return ("0x%02X" % x).encode('ascii') def transform_file(inf, outf, transform): with open(IN_FILE, "rb") as inf: with open(OUT_FILE, "wb") as outf: # transform for line in inf.readlines(): if line.startswith(b"F:"): fields = line.split(b':') # transform coordinates orig_x = int(fields[3], 0) orig_y = int(fields[4], 0) new_x,new_y = transform(orig_x, orig_y) # build new line and output new_fields = fields[0:3] + [hexify(new_x), hexify(new_y)] outf.write(b":".join(new_fields)) outf.write(b"\n") else: # output source line unchanged outf.write(line) # Here's the bit that actually does the transformation on # "coordinates" in the "F:" line. def transform(x,y): if ((x >= x1) and (x <= x2) and (y >= y1) and (y <= y2)): return (ox + (x - x1), oy + (y - y1)) else: return (x,y) # unchanged # Main driver program def main(): x1,y1 = xform_input("Starting selection: ", xform_coordinate) x2,y2 = xform_input("Ending selection: ", xform_coordinate) ox,oy = xform_input("Move selection to: ", xform_coordinate) IN_FILE="graf-dvg.prf" OUT_FILE="graf-dvg-result.prf" transform_file(IN_FILE, OUT_FILE, transform) |
![]() |
![]() |
![]() |
#5 |
Prophet
Join Date: May 2008
Location: Indiana, USA
Posts: 2,939
Donated: $8
![]() |
Thanks guys. I probably won't get a chance to check this stuff out till Mondy.
__________________
www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012. My banding life on Buzzkill's ladder. |
![]() |
![]() |
![]() |
#6 | |||
Prophet
Join Date: May 2008
Location: Indiana, USA
Posts: 2,939
Donated: $8
![]() |
Quote:
![]() Quote:
but it still doesn't work... I get this from Python IDLE Code:
Traceback (most recent call last): File "C:\Users\Rob\Desktop\New folder\prf tool.py", line 10, in <module> import readline File "C:\Python32\lib\site-packages\readline.py", line 5, in <module> from pyreadline.rlmain import Readline File "C:\Python32\lib\site-packages\pyreadline\__init__.py", line 9, in <module> import unicode_helper, logger, clipboard, lineeditor, modes, console ImportError: No module named unicode_helper Quote:
__________________
www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012. My banding life on Buzzkill's ladder. |
|||
![]() |
![]() |
![]() |
#7 | |
Adept
Join Date: Nov 2011
Location: Roaming in Terry Pratchett's Discworld
Posts: 178
![]() |
Quote:
![]() more seriously, have you checked the library path of python? perhaps it has not been correctly set (strange but possible), or windows is not aware of its value (a reboot should fix this). Or, the most obvious thing, are you sure unicode_helper is installed? |
|
![]() |
![]() |
![]() |
#8 | |
Prophet
Join Date: May 2008
Location: Indiana, USA
Posts: 2,939
Donated: $8
![]() |
Quote:
I fear that if I keep installing stuff without really knowing what the problem is, or what I'm doing, I'll get to a point where the actual solution will no longer work. A quick search revealed that unicode_helper is indeed present in Python32/Lib/site-packages/pyreadline
__________________
www.mediafire.com/buzzkill - Get your 32x32 tiles here. UT32 now compatible Ironband and Quickband 9/6/2012. My banding life on Buzzkill's ladder. |
|
![]() |
![]() |
![]() |
#9 |
Adept
Join Date: Apr 2011
Posts: 103
![]() |
I just pushed a win32 C/C++ tool that I think will do what you want through files. It is at http://github.com/blubaron/tilesetpr...ws/adjust_pref. there is a binary there. If you want to compile it you will need the winmain.cpp file in that directory and many of the files in tilesetpref/tree/master/tools/console/tile_common.
|
![]() |
![]() |
![]() |
#10 |
Veteran
Join Date: Jun 2007
Posts: 1,388
![]() |
You can just remove the "import readline" line.
It's not important. ![]() |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[3.3.x] Saving options/kemaps produces garbled prf file | PowerWyrm | Vanilla | 1 | November 28, 2011 10:20 |
x11-settings.prf not behaving like I would expect | ulrichvonbek | Vanilla | 10 | March 23, 2011 19:52 |
Tool-assisted Angband | Derakon | Vanilla | 8 | November 24, 2010 18:20 |
Saving PLAYER.prf *where* under Windows? | TJA | Vanilla | 2 | August 16, 2007 23:32 |