Made leveleditor to start in a specific file when ran as:
authorRicardo Cruz <rick2@aeiou.pt>
Wed, 5 May 2004 16:07:20 +0000 (16:07 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Wed, 5 May 2004 16:07:20 +0000 (16:07 +0000)
supertux --leveleditor levelname.stl
Unfortanely, it crashes when creating the Objects menu. I don't think it is related with my code, so here is the commit.

SVN-Revision: 997

src/globals.cpp
src/globals.h
src/leveleditor.cpp
src/leveleditor.h
src/setup.cpp
src/supertux.cpp
src/title.cpp

index 632f383..6e02cb0 100644 (file)
@@ -58,7 +58,7 @@ float game_speed = 1.0f;
 
 int joystick_num = 0;
 char* level_startup_file = 0;
-bool launch_worldmap_mode = false;
+bool launch_leveleditor_mode = false;
 
 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
 char *st_dir, *st_save_dir;
index d9d82cd..df3cad3 100644 (file)
@@ -67,7 +67,7 @@ extern bool show_fps;
 /** The number of the joystick that will be use in the game */
 extern int joystick_num;
 extern char* level_startup_file;
-extern bool launch_worldmap_mode;
+extern bool launch_leveleditor_mode;
 
 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
 extern char* st_dir;
index 5463689..c87aeac 100644 (file)
@@ -66,6 +66,7 @@
 /* crutial ones (main loop) */
 int le_init();
 void le_quit();
+int le_load_level(char *filename);
 void le_drawlevel();
 void le_drawinterface();
 void le_checkevents();
@@ -183,11 +184,12 @@ void le_set_defaults()
   }
 }
 
-int leveleditor(int levelnb)
+int leveleditor(char* filename)
 {
   int last_time, now_time, i;
 
-  le_level = levelnb;
+  le_level = 1;
+  
   if(le_init() != 0)
     return 1;
 
@@ -201,6 +203,10 @@ int leveleditor(int levelnb)
   while (SDL_PollEvent(&event))
   {}
 
+  if(filename != NULL)
+    if(le_load_level(filename))
+      return 1;
+
   while(true)
   {
     last_time = SDL_GetTicks();
@@ -322,22 +328,8 @@ int leveleditor(int levelnb)
         default:
           if(i >= 1)
           {
-            le_level_subset->load(level_subsets.item[i-1]);
-            leveleditor_menu->get_item_by_id(MNID_SUBSETSETTINGS).kind = MN_GOTO;
-            le_level = 1;
-            le_world.arrays_free();
-            delete le_current_level;
-            le_current_level = new Level;
-            if(le_current_level->load(le_level_subset->name, le_level) != 0)
-            {
-              le_quit();
-              return 1;
-            }
-            le_set_defaults();
-            le_current_level->load_gfx();
-            le_world.activate_bad_guys();
-
-            Menu::set_current(NULL);
+            if(le_load_level(level_subsets.item[i-1]))
+             return 1;
           }
           break;
         }
@@ -413,6 +405,27 @@ int leveleditor(int levelnb)
   return done;
 }
 
+int le_load_level(char *filename)
+{
+le_level_subset->load(filename);
+leveleditor_menu->get_item_by_id(MNID_SUBSETSETTINGS).kind = MN_GOTO;
+le_level = 1;
+le_world.arrays_free();
+delete le_current_level;
+le_current_level = new Level;
+if(le_current_level->load(le_level_subset->name, le_level) != 0)
+  {
+    le_quit();
+    return 1;
+  }
+le_set_defaults();
+le_current_level->load_gfx();
+le_world.activate_bad_guys();
+
+Menu::set_current(NULL);
+
+return 0;
+}
 
 void le_init_menus()
 {
@@ -599,6 +612,7 @@ int le_init()
 
   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 
+
   return 0;
 }
 
index 939159b..b0b6643 100644 (file)
@@ -34,7 +34,7 @@ enum {
   SQUARE
 };
 
-int leveleditor(int levelnb);
+int leveleditor(char* filename = NULL);
 void newlevel(void);
 void selectlevel(void);
 void le_savelevel();
index 040f9be..e0cd7bb 100644 (file)
@@ -969,9 +969,9 @@ void parseargs(int argc, char * argv[])
                         << "  Start-Button: " << joystick_keymap.start_button << std::endl;
             }
         }
-      else if (strcmp(argv[i], "--worldmap") == 0)
+      else if (strcmp(argv[i], "--leveleditor") == 0)
         {
-          launch_worldmap_mode = true;
+          launch_leveleditor_mode = true;
         }
       else if (strcmp(argv[i], "--datadir") == 0 
                || strcmp(argv[i], "-d") == 0 )
index facb42a..750f650 100644 (file)
@@ -46,10 +46,9 @@ int main(int argc, char * argv[])
   st_menu();
   loadshared();
 
-  if (launch_worldmap_mode)
+  if (launch_leveleditor_mode && level_startup_file)
     {
-      WorldMapNS::WorldMap worldmap;
-      worldmap.display();
+    leveleditor(level_startup_file);
     }
   else if (level_startup_file)
     {
index d82aba4..8f9b46b 100644 (file)
@@ -299,7 +299,7 @@ void title(void)
                   generate_contrib_menu();
                   break;
                 case MNID_LEVELEDITOR:
-                  leveleditor(1);
+                  leveleditor();
                   Menu::set_current(main_menu);
                   break;
                 case MNID_CREDITS: