From: Tobias Gläßer Date: Mon, 2 Feb 2004 22:16:25 +0000 (+0000) Subject: moved savelevel() code to level.h/c where it belongs to. :) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6d9952207d28e19d3448c9e0f8859be19d3acc88;p=supertux.git moved savelevel() code to level.h/c where it belongs to. :) SVN-Revision: 117 --- diff --git a/src/level.c b/src/level.c index 50aa6b6a8..b9f0ea47b 100644 --- a/src/level.c +++ b/src/level.c @@ -116,6 +116,57 @@ void loadlevel(st_level* plevel, char *subset, int level) } +/* Save data for level: */ + +void savelevel(st_level* plevel, char * subset, int level) +{ + FILE * fi; + char * filename; + int y; + char str[80]; + + /* Save data file: */ + + filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20) + strlen(subset)); + sprintf(filename, "%s/levels/%s/level%d.dat", DATA_PREFIX, subset, level); + fi = fopen(filename, "w"); + if (fi == NULL) + { + perror(filename); + st_shutdown(); + free(filename); + exit(-1); + } + free(filename); + + fputs(plevel->name, fi); + fputs("\n", fi); + fputs(plevel->theme, fi); + fputs("\n", fi); + sprintf(str, "%d\n", plevel->time_left); /* time */ + fputs(str, fi); + fputs(plevel->song_title, fi); /* song filename */ + fputs("\n",fi); + fputs(plevel->bkgd_image, fi); /* background image */ + sprintf(str, "\n%d\n", plevel->bkgd_red); /* red background color */ + fputs(str, fi); + sprintf(str, "%d\n", plevel->bkgd_green); /* green background color */ + fputs(str, fi); + sprintf(str, "%d\n", plevel->bkgd_blue); /* blue background color */ + fputs(str, fi); + sprintf(str, "%d\n", plevel->width); /* level width */ + fputs(str, fi); + + for(y = 0; y < 15; ++y) + { + fputs(plevel->tiles[y], fi); + fputs("\n", fi); + } + + fclose(fi); +} + + /* Unload data for this level: */ void unloadlevel(st_level* plevel) diff --git a/src/level.h b/src/level.h index 1b31fd2b4..a21a0b28d 100644 --- a/src/level.h +++ b/src/level.h @@ -34,6 +34,7 @@ typedef struct st_level /*It is easier to read the sources IMHO, if we don't wri texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2]; void loadlevel(st_level* plevel, char * subset, int level); +void savelevel(st_level* plevel, char * subset, int level); void unloadlevel(st_level* plevel); void loadlevelgfx(st_level* plevel); void unloadlevelgfx(); diff --git a/src/leveleditor.c b/src/leveleditor.c index c182c1d7d..7f014b11c 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -554,62 +554,6 @@ int xx, yy; bad_guys[i].base.alive = NO; } -/* Save data for this level: */ -void savelevel(void) -{ - FILE * fi; - char * filename; - int y; - char str[80]; - - /* Save data file: */ - - filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20) + strlen(level_subset)); - sprintf(filename, "%s/levels/%s/level%d.dat", DATA_PREFIX, level_subset, level); - fi = fopen(filename, "w"); - if (fi == NULL) - { - perror(filename); - st_shutdown(); - free(filename); - exit(-1); - } - free(filename); - - - /* sptrinf("# Level created by SuperTux built-in editor", fi); */ - - fputs(current_level.name, fi); - fputs("\n", fi); - fputs(current_level.theme, fi); - fputs("\n", fi); - sprintf(str, "%d\n", current_level.time_left); /* time */ - fputs(str, fi); - fputs(current_level.song_title, fi); /* song filename */ - fputs("\n",fi); - fputs(current_level.bkgd_image, fi); /* background image */ - sprintf(str, "\n%d\n", current_level.bkgd_red); /* red background color */ - fputs(str, fi); - sprintf(str, "%d\n", current_level.bkgd_green); /* green background color */ - fputs(str, fi); - sprintf(str, "%d\n", current_level.bkgd_blue); /* blue background color */ - fputs(str, fi); - sprintf(str, "%d\n", current_level.width); /* level width */ - fputs(str, fi); - - for(y = 0; y < 15; ++y) - { - fputs(current_level.tiles[y], fi); - fputs("\n", fi); - } - - fclose(fi); - - text_drawf(&gold_text, "SAVED!", 0, 240, A_HMIDDLE, A_TOP, 1, NO_UPDATE); - flipscreen(); - SDL_Delay(1000); -} - void showhelp() { SDL_Event event; diff --git a/src/leveleditor.h b/src/leveleditor.h index cd1bb38bf..a22be9af1 100644 --- a/src/leveleditor.h +++ b/src/leveleditor.h @@ -1,6 +1,5 @@ int level_editor_started; int leveleditor(); -void savelevel(void); void newlevel(void); void selectlevel(void); diff --git a/src/menu.c b/src/menu.c index 7971f7a0a..8431cdb3a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -24,6 +24,7 @@ #include "screen.h" #include "setup.h" #include "sound.h" +#include "scene.h" #include "leveleditor.h" #include "gameloop.h" #include "timer.h" @@ -390,7 +391,10 @@ int menu_leveleditor(void) if(menuaction == MN_HIT) /* Save the current level in the level-editor. */ { show_menu = 0; - savelevel(); + savelevel(¤t_level,"default",level); + text_drawf(&gold_text, "SAVED!", 0, 240, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + flipscreen(); + SDL_Delay(1000); } } else