broken RemoveParticle
[Lilanci.git] / config.c
blob34bcfaa9d9f7b0a675d29160f0a11a088f82e276
1 #include "config.h"
2 #include <stdio.h>
3 #include <SDL/SDL_keysym.h>
5 Config conf;
6 int loaded=0;
8 void DefaultConfig();
10 Config GetConfig(){
11 int e;
12 if(!loaded){
13 if((e=LoadConfig())){
14 printf("Config error:%d\n",e);
15 DefaultConfig();
16 printf("Writing default config\n");
17 SaveConfig();
19 loaded=1;
21 return conf;
24 void SetConfig(const Config c){
25 conf=c;
28 //return values
29 //0 -O.K.
30 //1 -conf.txt doesn't exists
31 //2..8 missing values
32 int LoadConfig(){
33 FILE *fp;
35 fp=(FILE*)fopen(CONFIG_FILENAME, "r");
36 if(fp==0)
37 return 1;
38 if(fscanf(fp,"%u", &conf.screen_width)==EOF)return 2;
39 if(fscanf(fp,"%u", &conf.screen_height)==EOF)return 3;
40 if(fscanf(fp,"%u", &conf.fullscreen)==EOF)return 3;
41 if(fscanf(fp,"%u", &conf.texture_lod)==EOF)return 3;
43 if(fscanf(fp,"%u", &conf.pl1_key_up)==EOF)return 4;
44 if(fscanf(fp,"%u", &conf.pl1_key_down)==EOF)return 5;
45 if(fscanf(fp,"%u", &conf.pl1_key_left)==EOF)return 6;
46 if(fscanf(fp,"%u", &conf.pl1_key_right)==EOF)return 7;
47 if(fscanf(fp,"%u", &conf.pl1_key_fire)==EOF)return 8;
48 if(fscanf(fp,"%u", &conf.pl1_key_suicide)==EOF)return 8;
49 if(fscanf(fp,"%u", &conf.pl1_key_switch)==EOF)return 8;
51 if(fscanf(fp,"%u", &conf.pl2_key_up)==EOF)return 4;
52 if(fscanf(fp,"%u", &conf.pl2_key_down)==EOF)return 5;
53 if(fscanf(fp,"%u", &conf.pl2_key_left)==EOF)return 6;
54 if(fscanf(fp,"%u", &conf.pl2_key_right)==EOF)return 7;
55 if(fscanf(fp,"%u", &conf.pl2_key_fire)==EOF)return 8;
56 if(fscanf(fp,"%u", &conf.pl2_key_suicide)==EOF)return 8;
57 if(fscanf(fp,"%u", &conf.pl2_key_switch)==EOF)return 8;
58 fclose(fp);
60 return 0;
63 //0-O.K.
64 //1-cannot open for writing
65 int SaveConfig(){
66 FILE *fp;
68 fp=(FILE*)fopen(CONFIG_FILENAME, "w");
69 if(fp==0)
70 return 1;
71 if(fprintf(fp,"%u\n", conf.screen_width)<0)return 2;
72 if(fprintf(fp,"%u\n", conf.screen_height)<0)return 3;
73 if(fprintf(fp,"%u\n", conf.fullscreen)<0)return 3;
74 if(fprintf(fp,"%u\n", conf.texture_lod)<0)return 3;
76 if(fprintf(fp,"%u\n", conf.pl1_key_up)<0)return 4;
77 if(fprintf(fp,"%u\n", conf.pl1_key_down)<0)return 5;
78 if(fprintf(fp,"%u\n", conf.pl1_key_left)<0)return 6;
79 if(fprintf(fp,"%u\n", conf.pl1_key_right)<0)return 7;
80 if(fprintf(fp,"%u\n", conf.pl1_key_fire)<0)return 8;
81 if(fprintf(fp,"%u\n", conf.pl1_key_suicide)<0)return 8;
82 if(fprintf(fp,"%u\n", conf.pl1_key_switch)<0)return 8;
84 if(fprintf(fp,"%u\n", conf.pl2_key_up)<0)return 4;
85 if(fprintf(fp,"%u\n", conf.pl2_key_down)<0)return 5;
86 if(fprintf(fp,"%u\n", conf.pl2_key_left)<0)return 6;
87 if(fprintf(fp,"%u\n", conf.pl2_key_right)<0)return 7;
88 if(fprintf(fp,"%u\n", conf.pl2_key_fire)<0)return 8;
89 if(fprintf(fp,"%u\n", conf.pl2_key_suicide)<0)return 8;
90 if(fprintf(fp,"%u\n", conf.pl2_key_switch)<0)return 8;
91 fclose(fp);
93 return 0;
96 void DefaultConfig(){
97 conf.screen_width=800;
98 conf.screen_height=600;
99 conf.fullscreen=0;
100 conf.texture_lod=0;
102 conf.pl1_key_up=SDLK_UP;
103 conf.pl1_key_down=SDLK_DOWN;
104 conf.pl1_key_left=SDLK_LEFT;
105 conf.pl1_key_right=SDLK_RIGHT;
106 conf.pl1_key_fire=SDLK_RCTRL;
107 conf.pl1_key_suicide=SDLK_F12;
108 conf.pl1_key_switch=SDLK_RSHIFT;
110 conf.pl2_key_up=SDLK_w;
111 conf.pl2_key_down=SDLK_s;
112 conf.pl2_key_left=SDLK_a;
113 conf.pl2_key_right=SDLK_d;
114 conf.pl2_key_fire=SDLK_LCTRL;
115 conf.pl2_key_suicide=SDLK_F11;
116 conf.pl2_key_switch=SDLK_LSHIFT;