Thursday, March 28, 2013

ATF Tools and Ant

I recently started tinkering with the ATF Tools provided by Adobe. The problem I have with it (as is) is that you have to use the command line in order to compress individual images. This is a pain in the butt and it is quite time consuming. I need a way to utilize Ant to automate this for me. Doing some looking around turned up the Ant Apply task. Unfortunately looking through the documentation is not straight forward for me. I did some more research and tinkering until I got something which worked. Below is what I came up with:

<project name="ATF Test">
 
 <!-- The location of the atf tools -->
 <property name="ATF_TOOLS" location="C:/home/bin/adobe/atftools/windows" />

 <target name="Create ATF Files" depends="PNG 2 ATF, Move ATF Bin" description="Converts png files to atf files" />
 
 <target name="PNG 2 ATF">
  <png2atf from="${basedir}/template/assets" to="${basedir}/template/assets" />
 </target>
 
 <!-- Move the atf files to a different location -->
 <target name="Move ATF Bin">
  <move todir="${basedir}/bin/assets">
   <fileset dir="${basedir}/template/assets" includes="**/*.atf" />
  </move>
 </target>

 <!-- 
  Converts all .png files to .atf files.
   @param from  The source directory containing the .png files to convert.
   @param to  The target directory to put the generated .atf files that have been created.
   
   @see http://wiki.starling-framework.org/manual/atf_textures
   @see http://www.adobe.com/devnet/flashruntimes/articles/atf-users-guide.html
   @see http://www.adobe.com/devnet/flashruntimes/articles/introducing-compressed-textures.html
 -->
 <macrodef name="png2atf">
  <attribute name="from" />
  <attribute name="to" />
  <sequential>
   <apply executable="${ATF_TOOLS}/png2atf.exe">
    <arg value="-i" />
    <srcfile />
    <arg value="-o" />
    <targetfile />
    <fileset dir="@{from}" includes="**/*.png" />
    <mapper type="glob" from="*.png" to="@{to}/*.atf" />
   </apply>
  </sequential>
 </macrodef>
</project>
I don't know if this is the best way to do it. My version creates the atf images in the same directory as the png image file. After all the png images are converted, I move the atf files over to a different directory for use in the application. I would like to have it where it creates the atf files in the destination directory, but I thought this was good enough at the time.

No comments: