]> git.localhorst.tv Git - l2e.git/blobdiff - src/main.cpp
added dump option
[l2e.git] / src / main.cpp
index 6be5e7ceeba8a92487b2f4637b0e27305066b999..00fea98dfba5506231f60141c4763b902a024fb6 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "app/Application.h"
+#include "app/Arguments.h"
 #include "app/Input.h"
 #include "battle/BattleState.h"
 #include "battle/Hero.h"
@@ -25,6 +26,7 @@
 #include "graphics/Menu.h"
 #include "graphics/SimpleAnimation.h"
 #include "graphics/Sprite.h"
+#include "loader/Compiler.h"
 #include "loader/Interpreter.h"
 #include "loader/ParsedSource.h"
 #include "loader/Parser.h"
 #include <ctime>
 #include <exception>
 #include <iostream>
+#include <string>
 #include <SDL.h>
 #include <SDL_image.h>
 
 using app::Application;
+using app::Arguments;
 using app::Input;
 using battle::BattleState;
 using battle::Hero;
@@ -59,6 +63,7 @@ using graphics::Gauge;
 using graphics::Menu;
 using graphics::SimpleAnimation;
 using graphics::Sprite;
+using loader::Compiler;
 using loader::Interpreter;
 using loader::ParsedSource;
 using loader::Parser;
@@ -71,6 +76,8 @@ using std::cerr;
 using std::cout;
 using std::endl;
 using std::exception;
+using std::string;
+using std::vector;
 
 int main(int argc, char **argv) {
        const int width = 800;
@@ -89,8 +96,10 @@ int main(int argc, char **argv) {
                Gauge::CreateTypeDescription();
                Hero::CreateTypeDescription();
                Ikari::CreateTypeDescription();
+               Interpreter::CreateTypeDescriptions();
                Item::CreateTypeDescription();
                graphics::MenuProperties::CreateTypeDescription();
+               Monster::CreateTypeDescription();
                PartyLayout::CreateTypeDescription();
                SimpleAnimation::CreateTypeDescription();
                Spell::CreateTypeDescription();
@@ -98,15 +107,50 @@ int main(int argc, char **argv) {
                Stats::CreateTypeDescription();
                common::TargetingMode::CreateTypeDescription();
 
+               Arguments args;
+               args.Read(argc, argv);
+
                ParsedSource source;
-               Parser("test-data/test.l2s", source).Parse();
-               Parser("test-data/ikaris.l2s", source).Parse();
-               Parser("test-data/items.l2s", source).Parse();
-               Parser("test-data/spells.l2s", source).Parse();
-               Parser("test-data/constants.l2s", source).Parse();
+
+               for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
+                       string filePath(*i);
+                       switch (filePath[filePath.size() - 1]) {
+                               case 'o':
+                                       // TODO: load object file
+                                       break;
+                               case 's':
+                                       Parser(filePath, source).Parse();
+                                       break;
+                               default:
+                                       throw std::runtime_error("don't know what to do with " + filePath);
+                       }
+               }
+
+//             Parser("test-data/test.l2s", source).Parse();
+//             Parser("test-data/ikaris.l2s", source).Parse();
+//             Parser("test-data/items.l2s", source).Parse();
+//             Parser("test-data/spells.l2s", source).Parse();
+//             Parser("test-data/constants.l2s", source).Parse();
+
                Interpreter intp(source);
                intp.ReadSource();
 
+               switch (args.DetectRunLevel()) {
+                       case Arguments::COMPILE:
+                       {
+                               std::ofstream testOut(args.OutfilePath());
+                               Compiler(intp).Write(testOut);
+                               return 0;
+                       }
+                       case Arguments::DUMP:
+                       {
+                               std::cout << source << std::endl;
+                               return 0;
+                       }
+                       case Arguments::PLAY:
+                               break;
+               }
+
                int battleResId(TypeDescription::GetTypeId("BattleResources"));
                int heroId(TypeDescription::GetTypeId("Hero"));
                int itemId(TypeDescription::GetTypeId("Item"));