1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#include <stdio.h>
#include "conf.h"
#include "spec.h"
#include "menu.h"
// open file?
// how does it work in browsers?
ConfCampaign conf_campaign=
{
0,0,0
};
ConfKeyboard conf_keyboard=
{
{'A','D','W','S','L','Q'}
};
ConfPlayer conf_player=
{
"Player 1",
0x00000000
};
ConfControl conf_control=
{
16,
16,
0,
1
};
struct ConfFile1
{
struct Campaign
{
int course;
int level;
} conf_campaign;
ConfKeyboard conf_keyboard;
ConfPlayer conf_player;
};
struct ConfFile2
{
ConfCampaign conf_campaign;
ConfKeyboard conf_keyboard;
ConfPlayer conf_player;
};
struct ConfFile3
{
ConfCampaign conf_campaign;
ConfKeyboard conf_keyboard;
ConfPlayer conf_player;
ConfControl conf_control;
};
void LoadConf()
{
FILE* f=0;
fopen_s(&f,conf_path(),"rb");
if (!f)
return;
int version=0;
int ret = fread(&version,4,1,f);
if (ret!=1)
{
fclose(f);
return;
}
if (version==1)
{
ConfFile1 conf;
int ret = fread(&conf,sizeof(ConfFile1),1,f);
fclose(f);
if (ret != 1)
return;
conf_campaign.passed = 0;
conf_campaign.course = 0;
conf_campaign.level = 0;
conf_keyboard = conf.conf_keyboard;
conf_player = conf.conf_player;
conf_control.mus_vol=16;
conf_control.sfx_vol=16;
conf_control.sticky=0;
conf_control.color=1;
}
if (version==2)
{
ConfFile2 conf;
int ret = fread(&conf,sizeof(ConfFile2),1,f);
fclose(f);
if (ret != 1)
return;
conf_campaign = conf.conf_campaign;
conf_keyboard = conf.conf_keyboard;
conf_player = conf.conf_player;
conf_control.mus_vol=16;
conf_control.sfx_vol=16;
conf_control.sticky=0;
conf_control.color=1;
}
if (version==3)
{
ConfFile3 conf;
int ret = fread(&conf,sizeof(ConfFile3),1,f);
fclose(f);
if (ret != 1)
return;
conf_campaign = conf.conf_campaign;
conf_keyboard = conf.conf_keyboard;
conf_player = conf.conf_player;
conf_control = conf.conf_control;
}
conf_campaign.course=0;
conf_campaign.level=0;
conf_campaign.passed=2;
LoadMenu();
}
void SaveConf()
{
FILE* f=0;
fopen_s(&f,conf_path(),"wb");
if (!f)
return;
int version = 3;
fwrite(&version,4,1,f);
ConfFile3 conf;
conf.conf_campaign = conf_campaign;
conf.conf_keyboard = conf_keyboard;
conf.conf_player = conf_player;
conf.conf_control = conf_control;
fwrite(&conf,sizeof(ConfFile3),1,f);
fclose(f);
write_fs();
}
char ConfMapInput(char c)
{
static const char m[6]=
{
KBD_LT,KBD_RT,KBD_UP,KBD_DN,13,27
};
while (1)
{
for (int i=0; i<6; i++)
{
if (conf_keyboard.map[i] == c)
return m[i];
}
if (c>='a' && c<='z')
c+='A'-'a';
else
break;
}
return c;
}
|