Moved some console commands' implementations nearer to target classes
[supertux.git] / src / level.cpp
index e9f8ccd..30e19e6 100644 (file)
 #include <memory>
 #include <stdexcept>
 
-#include "video/screen.h"
-#include "lisp/parser.h"
-#include "lisp/lisp.h"
-#include "lisp/list_iterator.h"
-#include "lisp/writer.h"
-#include "level.h"
-#include "physic.h"
-#include "sector.h"
-#include "tile.h"
-#include "resources.h"
-#include "file_system.h"
-#include "object/gameobjs.h"
-#include "object/camera.h"
-#include "object/tilemap.h"
-#include "object/coin.h"
+#include "video/screen.hpp"
+#include "msg.hpp"
+#include "lisp/parser.hpp"
+#include "lisp/lisp.hpp"
+#include "lisp/list_iterator.hpp"
+#include "lisp/writer.hpp"
+#include "level.hpp"
+#include "physic.hpp"
+#include "sector.hpp"
+#include "tile.hpp"
+#include "resources.hpp"
+#include "file_system.hpp"
+#include "object/gameobjs.hpp"
+#include "object/camera.hpp"
+#include "object/tilemap.hpp"
+#include "object/coin.hpp"
 
 // test
-#include "flip_level_transformer.h"
+#include "flip_level_transformer.hpp"
 
 using namespace std;
 
@@ -70,13 +71,6 @@ Level::load(const std::string& filepath)
     level->get("version", version);
     if(version == 1) {
       load_old_format(*level);
-
-#if 0
-      // test for now
-      FlipLevelTransformer* transformer = new FlipLevelTransformer();  
-      transformer->transform(this);
-#endif
-     
       return;
     }
 
@@ -86,7 +80,7 @@ Level::load(const std::string& filepath)
       if(token == "version") {
         iter.value()->get(version);
         if(version > 2) {
-          std::cerr << "Warning: level format newer than application.\n";
+          msg_warning << "level format newer than application" << std::endl;
         }
       } else if(token == "name") {
         iter.value()->get(name);
@@ -97,7 +91,7 @@ Level::load(const std::string& filepath)
         sector->parse(*(iter.lisp()));
         add_sector(sector);
       } else {
-        std::cerr << "Unknown token '" << token << "' in level file.\n";
+        msg_warning << "Unknown token '" << token << "' in level file" << std::endl;
         continue;
       }
     }
@@ -123,12 +117,7 @@ Level::load_old_format(const lisp::Lisp& reader)
 void
 Level::save(const std::string& filename)
 {
-  std::string filepath = "levels/" + filename;
-  int last_slash = filepath.find_last_of('/');
-  FileSystem::fcreatedir(filepath.substr(0,last_slash).c_str());
-  filepath = user_dir + "/" + filepath;
-  ofstream file(filepath.c_str(), ios::out);
-  lisp::Writer* writer = new lisp::Writer(file);
+  lisp::Writer* writer = new lisp::Writer(filename);
 
   writer->write_comment("Level made using SuperTux's built-in Level Editor");
 
@@ -150,7 +139,6 @@ Level::save(const std::string& filename)
   writer->end_list("supertux-level");
 
   delete writer;
-  file.close();
 }
 
 Level::~Level()