Help! Need a graf-foo.prf tool (again)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buzzkill
    Prophet
    • May 2008
    • 2939

    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 : [B]0x85:0x95[/B]
    ENDING SELECTION   : [B]0x85:0xFF[/B]
    
    MOVE SELECTION TO : [B]0x86:0x80[/B]
    
    GRAF-DVG-RESULT.PRF CREATED. FINISHED!
    In the above example, I'm moving everything in row 0x85, beginning at column 0x95, and dropping it down to the first position in the next row. The program should begin by calculating the difference between the 'starting selection' and 'move selection to' values (in this case it's +1:-21 decimal). It should read through and duplicate the prf sequentially, one line at a time, altering in-range value pairs by the difference as it finds them.

    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.
  • Blue Baron
    Adept
    • Apr 2011
    • 103

    #2
    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.)

    Comment

    • AnonymousHero
      Veteran
      • Jun 2007
      • 1393

      #3
      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 .

      Comment

      • AnonymousHero
        Veteran
        • Jun 2007
        • 1393

        #4
        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)
        (Be careful when copy/pasting this -- the whitespace must be preserved.)

        Comment

        • buzzkill
          Prophet
          • May 2008
          • 2939

          #5
          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.

          Comment

          • buzzkill
            Prophet
            • May 2008
            • 2939

            #6
            Originally posted by AnonymousHero
            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.)

            (Be careful when copy/pasting this -- the whitespace must be preserved.)
            Didn't work ... but I found found this...

            If you are using Windows, which also ships without GNU readline, you might want to consider using the pyreadline module instead, which is a readline replacement written in pure Python that interacts with the Windows clipboard.
            ... and installed this http://pypi.python.org/pypi/pyreadline

            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\[COLOR="DarkOrange"][B]__init__.py[/B][/COLOR]", line 9, in <module>
                import unicode_helper, logger, clipboard, lineeditor, modes, console
            ImportError: No module named unicode_helper
            __init__.py reads...

            # -*- coding: utf-8 -*-
            #************************************************* ****************************
            # Copyright (C) 2003-2006 Gary Bishop.
            # Copyright (C) 2006 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
            #
            # Distributed under the terms of the BSD License. The full license is in
            # the file COPYING, distributed as part of this software.
            #************************************************* ****************************
            import unicode_helper, logger, clipboard, lineeditor, modes, console
            from rlmain import *
            import rlmain
            Using Windows 7 with a slight headache. Am I missing something painfully obvious?
            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.

            Comment

            • ghengiz
              Adept
              • Nov 2011
              • 178

              #7
              Originally posted by buzzkill
              Using Windows 7 with a slight headache. Am I missing something painfully obvious?
              but using windows?
              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?

              Comment

              • buzzkill
                Prophet
                • May 2008
                • 2939

                #8
                Originally posted by ghengiz
                but using windows?
                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?
                I'm not sure of anything. I was hoping that installing the Python IDE and executing the program would work. Then I hoped that installing pyreadline would work.

                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.

                Comment

                • Blue Baron
                  Adept
                  • Apr 2011
                  • 103

                  #9
                  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.

                  Comment

                  • AnonymousHero
                    Veteran
                    • Jun 2007
                    • 1393

                    #10
                    You can just remove the "import readline" line.

                    It's not important.

                    Comment

                    • buzzkill
                      Prophet
                      • May 2008
                      • 2939

                      #11
                      Originally posted by Blue Baron
                      I just pushed a win32 C/C++ tool that I think will do what you want through files.
                      The above sample means move the pref file coordinates for any entry that uses a tile between the 2nd and 3rd to last tiles two tile to the right.
                      That's quite a mouthful. After several minutes of furiously burying my face into the palms of my hands, I figured it out. Being that is is essentially the same format I requested in this thread did help a little.

                      I give it a whirl very soon.
                      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.

                      Comment

                      • buzzkill
                        Prophet
                        • May 2008
                        • 2939

                        #12
                        Originally posted by buzzkill
                        I give it a whirl very soon.
                        Works as expected , at least so far.

                        It did mess up a little, when I specified a output file that didn't exist (assuming that it would create it). It spit up something about a bad input file and then closed/crashed, but it did create an output file, it renamed the source prf file to the specified output file name. A bit scary, but no harm done.

                        Having the log is very reassuring.

                        Thanks for this!!!
                        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.

                        Comment

                        Working...
                        😀
                        😂
                        🥰
                        😘
                        🤢
                        😎
                        😞
                        😡
                        👍
                        👎