/*
Tiamat - a role-playing game framework
AdventureStudio.java - main class for the Tiamat Adventure Studio
 
 Copyright  (C) 2006 Hugues Johnson
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.huguesjohnson.tiamat.tools.adventureStudio;

import java.io.File;

/** AdventureStudio - main class for the Tiamat Adventure Studio
 * @author Hugues Johnson
 */
public class AdventureStudio implements Runnable{
    private String filePath;
	
	/** constructor */
    public AdventureStudio(){
        this.filePath=null;
        Thread thread=new Thread(this);
        thread.start();
    }

	/** constructor */
    public AdventureStudio(String filePath){
        this.filePath=new String(filePath);
    	Thread thread=new Thread(this);
        thread.start();
    }
    
    
    /** exitHandler - override this if creating an instance of AdventureStudio in another class */
    public void exitHandler(){
        System.exit(0);
    }

    /** start the thread */
    @SuppressWarnings("serial")
	public void run(){
    	AdventureStudioFrame frame;
    	if(this.filePath!=null){
        	frame=new AdventureStudioFrame(this.filePath){
                public void exitEvent(){
                    exitHandler();
                }
            };    		
    	} else{
        	frame=new AdventureStudioFrame(){
                public void exitEvent(){
                    exitHandler();
                }
            };	
    	}
        frame.setVisible(true);
    }
    
    /** entry point for program */
    public static void main(String[] arguments){
        //check for command line arguments, only expected one is path
    	String filePath=null;
    	if((arguments!=null)&&(arguments.length>0)){
        	if((new File(arguments[0])).exists()){
        		filePath=arguments[0];
        	}
    	}
    	if(filePath!=null){
        	new AdventureStudio(filePath);
    	} else{
        	new AdventureStudio();
    	}
    }
}