From: Ricardo Cruz Date: Wed, 5 May 2004 16:07:20 +0000 (+0000) Subject: Made leveleditor to start in a specific file when ran as: X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=fced930eb4dc92cfcb0240b4ddbb5babeb66b231;p=supertux.git Made leveleditor to start in a specific file when ran as: 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 --- diff --git a/src/globals.cpp b/src/globals.cpp index 632f383e2..6e02cb0ea 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -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; diff --git a/src/globals.h b/src/globals.h index d9d82cdc3..df3cad3a5 100644 --- a/src/globals.h +++ b/src/globals.h @@ -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; diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 5463689e5..c87aeacd9 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -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; } diff --git a/src/leveleditor.h b/src/leveleditor.h index 939159bf5..b0b664360 100644 --- a/src/leveleditor.h +++ b/src/leveleditor.h @@ -34,7 +34,7 @@ enum { SQUARE }; -int leveleditor(int levelnb); +int leveleditor(char* filename = NULL); void newlevel(void); void selectlevel(void); void le_savelevel(); diff --git a/src/setup.cpp b/src/setup.cpp index 040f9be42..e0cd7bb61 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -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 ) diff --git a/src/supertux.cpp b/src/supertux.cpp index facb42a3e..750f65025 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -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) { diff --git a/src/title.cpp b/src/title.cpp index d82aba476..8f9b46bad 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -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: