[Script] Automate graphics conversion and compiling

Topics on software tools like TileStudio, comments on documentation and tutorials (or the lack of) should go here.
Post Reply
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

[Script] Automate graphics conversion and compiling

Post by nicksen782 »

I wrote a menu-driven batch file to automate gconvert, compile the game, and run it in the emulator. But still I had to go and manually change values to set the transparent pixels to 0xfe. Not anymore!

Converting graphics with each change can be a pain. You have to open it it in GIMP, change the color settings and then save it. Then you have to run gconvert, then go through and do a find/replace to set the transparent regions. This Windows batch file makes this much easier!

The XVI32 hex-editor can be scripted so the transparency conversion can be automatic! It just replaces the color values. In my case, I use a dark gray color (MS Paint) (HEX 0x5b) and convert that value to 0xfe. If you use a different color just look up 0, x, 5, and b on an ASCII chart and find the hex values. You should only need to change the last two values.

Makeit.bat

Code: Select all

@echo off
SET initidir=%cd%
SET datadir=..\data
SET binsdir=..\..\..\bin
SET emulator=..\..\..\bin\uzem2.exe

:: Run or compile?
if [%1] EQU [] (
 echo.
) ELSE (
   echo Will now run the specified game...
   %emulator% %1
   exit
  )

:MENU
CLS
echo *************************************************************************
echo             Welcome to the MAKEIT program.             
echo     Function                  Description 
echo     ---------------           ------------------------     
echo     (1)  Gconvert             Convert graphics assets (use first!)
echo     (2)  Compile              Compile program then run Uzem
echo     (3)  Gconvert and Compile Do options 1 and then 2
echo     (4)  EXIT                 Exit out of this program
echo.
echo   Chose your option from the list above.
echo.
echo *************************************************************************
echo.
:WHATchoice 
  set /p whichchoice={ Press the NUMBER of the choice that you want. }

cls
echo.


  if '%whichchoice%'=='1' GOTO OPTION-1
  if '%whichchoice%'=='2' GOTO OPTION-2
  if '%whichchoice%'=='3' GOTO OPTION-3
  if '%whichchoice%'=='4' GOTO OPTION-4
  GOTO MENU
  

:OPTION-1
  :: Run Gconvert
  echo. 
  echo.
  echo Running gconvert for TILES
  cd %datadir%
  %binsdir%\gconvert.exe convert_tiles.xml
  echo.
  
  echo Running gconvert for SPRITES
  cd %datadir%
  %binsdir%\gconvert.exe convert_sprites.xml
  echo.

  echo.
  echo Running XVI32.exe with script to replace the transparent regions.
  echo REMEMBER: Dark gray (0x5b) will be replaced with 0xfe !
  %binsdir%\XVI32.exe %datadir%\sprites.inc /S=%binsdir%\universalrepl.xsc "30 78 35 62" "30 78 66 65"
  echo Done converting graphics!!  
  pause
GOTO END



:OPTION-2
 :: COMPILE
 :: Delete anything left over from previous compile.
 if exist *.hex del *.hex /q
 if exist *.epp del *.eep /q 
 if exist *.elf del *.elf /q 
 if exist *.lss del *.lss /q 
 if exist *.map del *.map /q 
 if exist *.o   del *.o   /q 
 if exist *.uze del *.uze /q 
 if exist *.eep del *.eep /q 
 if exist *.eep del *.eep /q 
 echo.
 
 :: Compile the program. The "Makefile" will be used.
 echo.
 echo Compiling program...
 cd %initidir%
 make
 echo.
 
 :: Remove all resulting files other than the .hex or .uze file. 
 if exist *.epp del *.eep /q 
 if exist *.elf del *.elf /q 
 if exist *.lss del *.lss /q 
 if exist *.map del *.map /q 
 if exist *.o   del *.o   /q 
 if exist *.eep del *.eep /q 
 if exist *.eep del *.eep /q 
 if exist dep rmdir dep /s /q
 echo.
 
 echo List of .HEX files:
 FOR /F %%I IN ('DIR *.hex /B') DO SET newrom=%%I
 echo %newrom%
 pause
 
 echo Starting Uzem emulator
 echo.
 
 %emulator% %newrom%
GOTO END

:OPTION-3
  CALL :OPTION-1
  CALL :OPTION-2
  GOTO END
:OPTION-4
:END
universalrepl.xsc

Code: Select all

REM goto begin of file (always zero-based)
ADR 0
REM in above example %1 is 0A
REM and %2 is 0D 0A
REPLACEALL %1 BY %2
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: [Script] Automate graphics conversion and compiling

Post by uze6666 »

Why not use the translucent color right away in your source picture? The rgb value is (221,255,255). The full uzebox palette is available as a GIF in the SVN trunk under gfx/color_table.gif. Not sure, but I think you can also import the photoshop palette file gfx/uzebox.act straight in Gimp. Btw, using Gimp and layers you can have the lowest layer be filled the translucent color and have the sprite pixel on another layer. That's how I work with photoshop.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: [Script] Automate graphics conversion and compiling

Post by nicksen782 »

The script is still helpful for automating gconvert, make, and uzem. What do you think of the rest?
Why not use the translucent color right away in your source picture? The rgb value is (221,255,255).
So, 0xFE is (221, 255, 255) in RGB? That allowed me to create a custom color. It's a shade of blue. That was really helpful and what I originally wanted to do. THANK YOU.
The full uzebox palette is available as a GIF in the SVN trunk under gfx/color_table.gif.
Yeah, I've seen this .gif. I wasn't sure what to do with it though. How do I use it?
Not sure, but I think you can also import the photoshop palette file gfx/uzebox.act straight in Gimp.
Yes, the uzebox.act can be imported into GIMP. I use the GIMP to convert my edited PNG files (in MS PAINT) to the PNG format that gconvert uses. Each edit via MS Paint requires another conversion with GIMP. I really would like to know how to script the conversion.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: [Script] Automate graphics conversion and compiling

Post by uze6666 »

Yeah, I've seen this .gif. I wasn't sure what to do with it though. How do I use it?
you could use it a as a palette for paint programs that has a color picker.
Yes, the uzebox.act can be imported into GIMP. I use the GIMP to convert my edited PNG files (in MS PAINT) to the PNG format that gconvert uses. Each edit via MS Paint requires another conversion with GIMP. I really would like to know how to script the conversion.
why not edit right in gimp then? also I was thinking about extending gconvert with new formats. That would somewhat solve your problem.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: [Script] Automate graphics conversion and compiling

Post by nicksen782 »

why not edit right in gimp then? also I was thinking about extending gconvert with new formats. That would somewhat solve your problem.
I have not learned how to use GIMP yet. I can convert the color palette, and I recently learned how to change all of one color to another. I'm not really creating my own graphics at this point, just arranging and converting them. PNG-8 is easy enough so long as it gets created correctly. Also, the image itself needs to be divisible by 8. Learned by accident. :shock:

I have noticed a potential bug in GIMP when saving PNG files. If you don't have enough colors then it may save the image with a bit depth of 4 and gconvert needs 8. My solution was to just create a tile (unused) that had enough colors. I have a rainbow tile and now GIMP gives me the 8 bit depth.

And I used the RGB code that you gave me and I no longer need to use that hex editor script to change the transparent bytes to 0xFE. Although in researching the Makefile, I found that I could set the transparent color to something other that 0xFE... which I'm not doing, but I found it. Thanks!
Post Reply