1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 /*!****************************************************************************
11  * \file    editor_main.cpp
12  * \author  Philip Vorsilak, gorzuate@allacrost.org
13  * \brief   Source file for editor's main() function: from here the editor is
14  *          started and exited.
15  *****************************************************************************/
16 
17 #ifdef __MACH__
18 	#include <unistd.h>
19 	#include <string>
20 #endif
21 
22 #include "editor.h"
23 #include "global.h"
24 
25 using namespace std;
26 using namespace hoa_editor;
27 
28 #if defined(main) && !defined(_WIN32)
29 	#undef main
30 #endif
31 
main(int argc,char ** argv)32 int main(int argc, char **argv)
33 {
34 #ifndef _WIN32
35 #ifndef __MACH__
36 	// Look for data files in DATADIR only if they are not available in the
37 	// current directory.
38 	if (ifstream("./dat/config/settings.lua") == NULL)
39 		chdir(DATADIR);
40 #endif
41 #endif
42 
43 #ifdef __MACH__
44 	string path;
45 	path = argv[0];
46 	// remove the binary name
47 	path.erase(path.find_last_of('/'));
48 	// remove the MacOS directory
49 	path.erase(path.find_last_of('/'));
50 	// remove the Contents directory
51 	path.erase(path.find_last_of('/'));
52 	// remove the Editor.app directory
53 	path.erase(path.find_last_of('/'));
54 	// we are now in a common directory containing both Allacrost and the Editor
55 	path.append ( "/Allacrost.app/Contents/Resources/" );
56 	chdir ( path.c_str() );
57 #endif
58 
59 	QApplication app(argc, argv);
60 	hoa_script::ScriptManager = hoa_script::ScriptEngine::SingletonCreate();
61 	hoa_script::ScriptManager->SingletonInitialize();
62 	hoa_global::GlobalManager = hoa_global::GameGlobal::SingletonCreate();
63 	hoa_defs::BindGlobalsToLua();
64 	hoa_global::GlobalManager->SingletonInitialize();
65 
66 	Editor* editor = new Editor();
67 	editor->setCaption("Hero of Allacrost Level Editor");
68 	app.setMainWidget(editor);
69 	editor->show();
70 	return app.exec();
71 }
72