<!--$Id$
	ANT Build Task

	Compiles ActionScript files into an SWF output

	Note: This build script requires MTSAC that will handle the class compiling. 
	It will need to	be available through the system PATH or compiling will fail.
	
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	
	http://www.mozilla.org/MPL/

	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	Author: Cameron Manderson <cam@mink.net.au>
-->
<project name="t2tea" default="compile" basedir=".">

	<!-- Ant Properties -->
	<property name="lib.dir" location="lib" />
	<property name="src.dir" location="src" />
	<property name="target.dir" location="build" />

	<!-- Prepare our properties -->
	<target name="properties" description="Setup properties for target ant tasks">
		<property name="as2ant.jar" value="${lib.dir}/as2ant.jar" />
		<!-- MTASC SWF output properties -->
		<property name="mtasc.main.class" value="T2Tea.as" />
		<property name="mtasc.output" value="${target.dir}/${ant.project.name}.swf" />
		<property name="mtasc.width" value="960" />
		<property name="mtasc.height" value="600" />
		<property name="mtasc.framerate" value="30" />
		<property name="mtasc.bgcolor" value="000000" />
		<!-- Output the properties -->
		<echo>
			MTSAC Output Configuration
			-------------------------------------------------------------------------
			Main File: ${mtasc.main.class}
			Output File: ${mtasc.output}
			Width: ${mtasc.width}
			Height: ${mtasc.height}
			Framerate: ${mtasc.framerate}
			Background Color: ${mtasc.bgcolor}
			-------------------------------------------------------------------------
		</echo>
	</target>

	<!-- Prepare our build targets -->
	<target name="init" depends="properties" description="Prepares the filesystem for compiling tasks">
		<echo>Preparing for the local environment</echo>
		<echo>Making the ${target.dir} (if required)</echo>
		<mkdir dir="${target.dir}" />
		<echo>Checking for required ANT MTASC tasks</echo>
		<condition property="mtasc.ok">
			<available file="${as2ant.jar}" />
		</condition>
		<fail unless="mtasc.ok">
			Unable to locate {$as2ant.jar}
		</fail>
		<taskdef name="mtasc" classname="org.as2lib.ant.Mtasc" classpath="${lib.dir}/as2ant.jar" />
	</target>

	<!-- MTASC Build Task" -->
	<target name="compile" depends="init" description="Compile to build path using MTASC compiler">
		<echo>
			Compiling ${ant.project.name} project using MTASC compiler
			Note: MTSAC needs to be present in your system classpath
		</echo>
		<echo>Creating SWF project output</echo>
		<mtasc src="${src.dir}/${mtasc.main.class}" classpath="${src.dir}" swf="${mtasc.output}" main="true" header="${mtasc.width}:${mtasc.height}:${mtasc.framerate}:${mtasc.bgcolor}" />
		<echo>Compiling SRC classes into the SWF project output</echo>
		<mtasc classpath="${src.dir}" swf="${mtasc.output}" split="true">
			<!-- Build our source paths -->
			<srcset dir="${src.dir}">
				<include name="**/*.as" />
				<!-- Don't recompile our main class -->
				<exclude name="**/${mtasc.main.class}" />
			</srcset>
		</mtasc>
		<echo>Compiled target build directory</echo>
		<echo>${mtasc.output}</echo>
	</target>

	<!-- Deploy the project to the stage -->
	<target name="deploy" depends="compile" description="Deploy the project">
		<echo>TODO: Setup deploy tasks (if required)</echo>
	</target>

	<!-- Clean out our build target -->
	<target name="clean" description="Clean the build folder">
		<echo>Cleaning target build paths</echo>
		<delete dir="${target.dir}" />
	</target>
</project>