<!--
  ~ Copyright No One. 2014. ;P
  -->

<project name="GenreMashup" default="deployPC-64Bit" basedir="."
         xmlns:fx="javafx:com.sun.javafx.tools.ant">

    <!-- THE THREE BELOW TARGETS ARE THE INTENDED BUILD TARGETS-->

    <target name="deployForWindows64">
        <antcall target="deployPC-64Bit"/>
    </target>

    <target name="deployForWindows32">
        <antcall target="deployPC-32Bit"/>
    </target>

    <target name="deployForOSX">
        <antcall target="deployMac"/>
    </target>

    <!---->
    <!---->
    <!---->
    <!---->
    <!-- CHANGE STUFF ONLY BELOW HERE, UNLESS YOU'RE COMFY CHANGING MORE.-->

    <property name="initialClass" value="com.company.indie.MyGameApp"/>

    <property name="jarName" value="GameName"/>
    <property name="appName" value="GameName"/>
    <property name="appVendor" value="TeamIndie"/>
    <property name="copyrightInfo" value="This is my copyright information!"/>
    <property name="description" value="This is a description of the best game ever."/>

    <property name="pcIcon" value="icon256.ico"/>
    <property name="macIcon" value="icon256.icns"/>

    <!--These are folder paths for input and output-->
    <!--Input-->
        <property name="src" value="src"/>                          <!--Your source code-->
        <property name="natives" value="JNI/"/>                     <!--Any natives you have-->
        <property name="resources" value="Resources/"/>             <!--Images, sounds, music, etc-->
    <!--Output-->
        <property name="build" value="build"/>                      <!--A temp folder for compiling into-->
        <property name="jars" value="deploy_jars"/>                 <!--A temp folder for Jars created on the way-->
        <property name="deploy" value="deploy"/>                    <!--The final output folder of your deployment-->

    <!--Libraries built through other projects, for inclusion-->
    <property name="library1" value="lib/lwjgl.jar"/>               <!--For sample, used below as an externally included JAR-->
    <property name="library2" value="lib/jinput.jar"/>              <!--For sample, used below as an externally included JAR-->
    <property name="library3" value="lib/someCustomLibrary.jar"/>   <!--For sample, used below as a JAR to unzip and compile in-->

    <property name="jvmArg1" value="-Xmx400m"/>                     <!--COMMENTED OUT FROM USE BELOW. JVMARGS ARE NOT BEING PASSED AS DOWNLOADED-->
    <property name="jvmArg2" value="-Xmx400m"/>                     <!--COMMENTED OUT FROM USE BELOW. JVMARGS ARE NOT BEING PASSED AS DOWNLOADED-->


    <!-- Paths to JDKs, so you can choose what to use without changing the environment-->
    <property name="JDKWindows64bit" value="C:\Program Files\Java\jdk1.7.0_45"/>
    <property name="JDKWindows32bit" value="C:\Program Files (x86)\Java\jdk1.7.0_45"/>
    <property name="JDKMacOSX" value="/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"/>


    <!-- CHANGE STUFF ONLY ABOVE HERE, UNLESS YOU'RE COMFY CHANGING MORE.-->
    <!---->
    <!---->
    <!---->
    <!---->





    <!-- Typically, you'd deploy with whatever JRE is active in your system. These targets let you set a different one, though.-->
    <target name="deployPC-64Bit">
        <property name="deployFolderExtension" value="Windows64"/>
        <property name="cpSeperator" value=";"/>
        <property name="nativeExtension" value="dll"/>
        <property name="PC" value="true"/>
        <property name="iconName" value="${pcIcon}"/>
        <property name="jdkPath" value="${JDKWindows64bit}"/>
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                 uri="javafx:com.sun.javafx.tools.ant"
                 classpath=".:${JDKWindows64bit}\lib\ant-javafx.jar"/>
        <antcall target="deploy"/>
    </target>


    <target name="deployPC-32Bit">
        <property name="deployFolderExtension" value="Windows32"/>
        <property name="cpSeperator" value=";"/>
        <property name="nativeExtension" value="dll"/>
        <property name="PC" value="true"/>
        <property name="iconName" value="${pcIcon}"/>
        <property name="jdkPath" value="${JDKWindows32bit}"/>
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                 uri="javafx:com.sun.javafx.tools.ant"
                 classpath=".:${JDKWindows32bit}\lib\ant-javafx.jar"/>
        <antcall target="deploy"/>
    </target>

    <target name="deployMac">
        <property name="deployFolderExtension" value="Mac"/>
        <property name="cpSeperator" value=":"/>
        <property name="nativeExtension" value="jnilib"/>
        <property name="Mac" value="true"/>
        <property name="iconName" value="${macIcon}"/>
        <property name="jdkPath" value="${JDKMacOSX}"/>
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                 uri="javafx:com.sun.javafx.tools.ant"
                 classpath=".:${JDKMacOSX}/lib/ant-javafx.jar"/>
        <antcall target="deploy"/>
    </target>

    <target name="deploy">
        <!-- Compile Application -->
        <antcall target="compile"/>
        <antcall target="unzipFrameworks"/>
        <antcall target="incrementBuild"/>

        <!-- Define Application -->
        <fx:application id="gameName" mainClass="${initialClass}" toolkit="swing" name="${appName}"/> <!--The swing part just avoids  use of the JavaFX kit-->

        <!--JAR it up -->
        <antcall target="createJar"/>

        <!-- Obfuscate -->
        <antcall target="obfuscate"/>

        <!-- Generate Native Bundles -->
        <delete dir="${deploy}${deployFolderExtension}"/>
        <fx:deploy width="1920" height="1080" nativebundles="image"
                   outdir="${deploy}${deployFolderExtension}"
                   outfile="${jarName}">
            <fx:application refid="gameName"/>
            <fx:info title="${jarName}" vendor="${appVendor}"
                     copyright="${copyrightInfo}" description="${description}">
                <fx:icon href="${iconName}"/>   <!--Defined above. A .ico for Windows, or an .icns for OSX."-->
            </fx:info>
            <fx:preferences shortcut="true" menu="true" install="true"/>    <!--For this purpose, I couldn't find a reason not to. Seems not to apply.-->
            <fx:permissions elevated="true"/>                               <!--For this purpose, I couldn't find a reason not to. Seems not to apply.-->
            <fx:resources>
                <fx:fileset dir="${jars}" includes="${jarName}.jar" type="jar"/>
                <fx:fileset dir="." includes="${resources}/,${library1},${library2}"/>
                <fx:fileset dir="${natives}" type="data">
                    <include name="*.${nativeExtension}"/>
                </fx:fileset>
            </fx:resources>
            <fx:platform basedir="${jdkPath}">
                <fx:jvmarg value="jvmArg1"/>
                <fx:jvmarg value="jvmArg2"/>
            </fx:platform>
        </fx:deploy>

        <!-- Clean Up -->
        <antcall target="cleanup"/>
    </target>

    <target name="compile">
        <delete dir="${build}"/>
        <mkdir dir="${build}"/>
        <javac srcdir="${src}" destdir="${build}"
               classpath="${library1};${library2};${library3}"/>
    </target>

    <target name="unzipFrameworks">
        <unzip src="${library3}" dest="${build}"/>
    </target>

    <target name="incrementBuild">
        <propertyfile file="${jarName}.prp">
            <entry key="build" type = "int" default="0" operation="+"/>
            <entry key="date" type="date" value="now" pattern="MM/dd/y hh.mm a"/>
        </propertyfile>
        <copy file="${jarName}.prp" todir="${build}"/>
    </target>

    <target name="createJar">
        <delete dir="${jars}"/>
        <jar destfile="${jars}/${jarName}.jar">
            <fileset dir="${build}"/>
            <manifest>
                <attribute name="App-Title" value="${jarName}"/>
                <attribute name="App-Vendor" value="${appVendor}"/>
                <attribute name="Main-Class" value="${initialClass}"/>
                <attribute name="Class-Path" value="${library1} ${library2}"/>
                <attribute name="Permissions" value="all-permissions"/>
            </manifest>
        </jar>
    </target>

    <target name="obfuscate">
        <taskdef resource="proguard/ant/task.properties"  classpath="lib/proguard.jar"/>
        <move file="${jars}/${jarName}.jar" tofile="${jars}/${jarName}_raw.jar"/>
        <proguard optimize="false">
            -libraryjars    "${java.home}/lib/rt.jar"${cpSeperator}${lwjgl}${cpSeperator}${jinput}${cpSeperator}${jogg}${cpSeperator}${jorbis}${cpSeperator}${tritonusShare}${cpSeperator}${vorbisSPI}
            -injars         ${jars}/${jarName}_raw.jar
            -outjars        ${jars}/${jarName}.jar
            -keep public class ${initialClass} {
            public static void main(java.lang.String[]);
            }
            -keepclassmembers enum * {
            public static **[] values();
            public static ** valueOf(java.lang.String);
            }
        </proguard>
    </target>

    <target name="cleanup">
        <delete dir="${build}"/>
        <delete dir="${jars}"/>
    </target>

</project>