diff --git a/Minesweeper2D.cbp b/Minesweeper2D.cbp index 12a6b0da4cc1451af9a61a7e5b1d0d1a99c7429c..b219b4266aca9f51b4c94575dee04542462d4753 100644 --- a/Minesweeper2D.cbp +++ b/Minesweeper2D.cbp @@ -48,6 +48,7 @@ <Add option="-lSDL_gfx" /> <Add option="-lSDL_image" /> <Add option="-lSDL_ttf" /> + <Add option="-liniparser" /> </Linker> <Unit filename="button.c"> <Option compilerVar="CC" /> diff --git a/makefile b/makefile index 209c9b3730b2222f7d3e144fc4336e4e7971feb3..3160080ebe2915dcfec9213c4c5696b3e52b4238 100644 --- a/makefile +++ b/makefile @@ -4,7 +4,7 @@ HEADERS = button.h colors.h enums.h field.h game.h highscore.h init.h input.h la CC = gcc CFLAGS = -O2 `sdl-config --cflags` -LDFLAGS = -lm `sdl-config --libs` -lSDL_ttf -lSDL_gfx -lSDL_image -lSDL_mixer +LDFLAGS = -lm `sdl-config --libs` -lSDL_ttf -lSDL_gfx -lSDL_image -lSDL_mixer -liniparser .PHONY: all clean diff --git a/settings.c b/settings.c index 73faa42fe14e31d9f9318c0b902b97de75531734..dd6a57352d95454fefd8f4b56678b829a729411c 100644 --- a/settings.c +++ b/settings.c @@ -14,18 +14,23 @@ You should have received a copy of the GNU General Public License along with Minesweeper2D. If not, see <http://www.gnu.org/licenses/>.*/ #include "settings.h" +#include "iniparser.h" +#include <assert.h> void loadSettings(Settings* settings){ - FILE* fp; - fp=fopen("settings.set","rt"); - if(fp==NULL){ - printf("[Error]Cannot load settings!"); - exit(1); + dictionary* data = iniparser_load("settings.ini"); + + if(data == NULL){ + fprintf(stderr, "[ERROR] Cannot load settings."); + assert(-1); }else{ - fscanf(fp,"RESOLUTION: %d x %d\n",&settings->resolution.width,&settings->resolution.height); - fscanf(fp,"COLORDEPTH: %d\n",&settings->mode.bpp); - fscanf(fp,"ORIENTATION: %x\n",&settings->mode.state); + settings->resolution.width = iniparser_getint(data, "Resolution:width", 600); + settings->resolution.height = iniparser_getint(data, "Resolution:height", 600); + settings->mode.bpp = iniparser_getint(data, "Mode:depth", 32); + settings->mode.state = iniparser_getint(data, "Mode:state", WINDOWED); } - fclose(fp); + + + iniparser_freedict(data); } diff --git a/settings.ini b/settings.ini new file mode 100644 index 0000000000000000000000000000000000000000..c16e3a836d36afef21a81ebba560e22fa48428aa --- /dev/null +++ b/settings.ini @@ -0,0 +1,7 @@ +[Resolution] +width = 800 +heigh = 600 + +[Mode] +depth = 32 +state = 0x10000000 \ No newline at end of file diff --git a/settings.set b/settings.set deleted file mode 100644 index ed7f60ae8c4b123949cc094128a40072e6bf1210..0000000000000000000000000000000000000000 --- a/settings.set +++ /dev/null @@ -1,3 +0,0 @@ -RESOLUTION: 800 x 600 -COLORDEPTH: 32 -ORIENTATION: 0x10000000