Erwan
- Updated options system
This commit is contained in:
@@ -4,6 +4,32 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <JGE.h>
|
||||
|
||||
const char* GameOptions::phaseInterrupts[] = {
|
||||
"interrupt ---",
|
||||
"interrupt Untap",
|
||||
"interrupt Upkeep",
|
||||
"interrupt Draw",
|
||||
"interrupt Main phase 1",
|
||||
"interrupt Combat begins",
|
||||
"interrupt Attackers",
|
||||
"interrupt Blockers",
|
||||
"interrupt Combat damage",
|
||||
"interrupt Combat ends",
|
||||
"interrupt Main phase 2",
|
||||
"interrupt End of turn",
|
||||
"interrupt Cleanup",
|
||||
"interrupt ---"
|
||||
};
|
||||
|
||||
GameOption::GameOption(int _value){
|
||||
value = _value;
|
||||
}
|
||||
|
||||
int GameOption::getIntValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
GameOptions* GameOptions::mInstance = NULL;
|
||||
|
||||
@@ -14,9 +40,6 @@ GameOptions * GameOptions::GetInstance(){
|
||||
}
|
||||
|
||||
GameOptions::GameOptions(){
|
||||
for(int i = 0; i < MAX_OPTIONS; i++){
|
||||
values[i] = 0;
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -24,12 +47,10 @@ int GameOptions::load(){
|
||||
std::ifstream file(OPTIONS_SAVEFILE);
|
||||
std::string s;
|
||||
if(file){
|
||||
for (int i = 0; i < MAX_OPTIONS; i++){
|
||||
if(std::getline(file,s)){
|
||||
values[i] = atoi(s.c_str());
|
||||
}else{
|
||||
//TODO error management
|
||||
}
|
||||
while(std::getline(file,s)){
|
||||
int found =s.find("=");
|
||||
string name = s.substr(0,found);
|
||||
values[name] = GameOption(atoi(s.substr(found+1).c_str()));
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -38,10 +59,11 @@ int GameOptions::load(){
|
||||
|
||||
int GameOptions::save(){
|
||||
std::ofstream file(OPTIONS_SAVEFILE);
|
||||
char writer[10];
|
||||
char writer[1024];
|
||||
if (file){
|
||||
for (int i = 0; i < MAX_OPTIONS; i++){
|
||||
sprintf(writer,"%i\n", values[i]);
|
||||
map<string, GameOption>::iterator it;
|
||||
for ( it=values.begin() ; it != values.end(); it++ ){
|
||||
sprintf(writer,"%s=%d\n", it->first.c_str(), it->second.getIntValue());
|
||||
file<<writer;
|
||||
}
|
||||
file.close();
|
||||
|
||||
Reference in New Issue
Block a user