2010-03-13 22:10:45 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 08:40:48 +01:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2010-03-13 22:10:45 +01:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_CONFIG_H_
|
|
|
|
#define _GLEST_GAME_CONFIG_H_
|
|
|
|
|
2012-04-20 03:04:05 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
#include "properties.h"
|
2010-03-16 22:44:22 +01:00
|
|
|
#include <vector>
|
|
|
|
#include "game_constants.h"
|
2011-03-04 21:26:47 +01:00
|
|
|
#include <SDL.h>
|
2010-09-07 07:25:40 +02:00
|
|
|
#include "leak_dumper.h"
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
using Shared::Util::Properties;
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Config
|
|
|
|
//
|
|
|
|
// Game configuration
|
|
|
|
// =====================================================
|
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
enum ConfigType {
|
|
|
|
cfgMainGame,
|
|
|
|
cfgUserGame,
|
2012-07-06 18:29:49 +02:00
|
|
|
cfgTempGame,
|
2010-06-12 20:27:39 +02:00
|
|
|
cfgMainKeys,
|
2012-07-06 18:29:49 +02:00
|
|
|
cfgUserKeys,
|
|
|
|
cfgTempKeys
|
2010-06-12 20:27:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Config {
|
2010-03-13 22:10:45 +01:00
|
|
|
private:
|
2011-11-23 19:02:00 +01:00
|
|
|
|
2010-06-12 20:27:39 +02:00
|
|
|
std::pair<Properties,Properties> properties;
|
2012-07-06 18:29:49 +02:00
|
|
|
Properties tempProperties;
|
2010-06-12 20:27:39 +02:00
|
|
|
std::pair<ConfigType,ConfigType> cfgType;
|
2011-03-04 23:54:04 +01:00
|
|
|
std::pair<string,string> fileNameParameter;
|
2010-06-12 20:27:39 +02:00
|
|
|
std::pair<string,string> fileName;
|
|
|
|
std::pair<bool,bool> fileLoaded;
|
|
|
|
|
|
|
|
static map<ConfigType,Config> configList;
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2010-12-09 21:41:11 +01:00
|
|
|
static const char *glest_ini_filename;
|
|
|
|
static const char *glestuser_ini_filename;
|
|
|
|
|
2011-11-23 19:02:00 +01:00
|
|
|
static map<string,string> customRuntimeProperties;
|
|
|
|
|
2011-05-01 05:12:36 +02:00
|
|
|
public:
|
2011-11-23 19:02:00 +01:00
|
|
|
|
2011-05-01 05:12:36 +02:00
|
|
|
static const char *glestkeys_ini_filename;
|
|
|
|
static const char *glestuserkeys_ini_filename;
|
|
|
|
|
2011-11-23 19:02:00 +01:00
|
|
|
static const char *ACTIVE_MOD_PROPERTY_NAME;
|
|
|
|
|
2013-01-27 23:10:24 +01:00
|
|
|
static const char *colorPicking;
|
|
|
|
static const char *selectBufPicking;
|
2013-02-11 23:51:36 +01:00
|
|
|
static const char *frustumPicking;
|
2013-01-27 23:10:24 +01:00
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
protected:
|
2011-11-23 19:02:00 +01:00
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
Config();
|
2010-06-12 20:27:39 +02:00
|
|
|
Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist);
|
2011-05-04 01:34:25 +02:00
|
|
|
bool tryCustomPath(std::pair<ConfigType,ConfigType> &type, std::pair<string,string> &file, string custom_path);
|
2010-09-09 23:07:39 +02:00
|
|
|
static void CopyAll(Config *src,Config *dest);
|
2011-01-03 21:59:18 +01:00
|
|
|
vector<pair<string,string> > getPropertiesFromContainer(const Properties &propertiesObj) const;
|
2012-03-31 22:58:33 +02:00
|
|
|
static bool replaceFileWithLocalFile(const vector<string> &dirList, string fileNamePart, string &resultToReplace);
|
2010-09-09 23:07:39 +02:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
public:
|
2011-11-23 19:02:00 +01:00
|
|
|
|
2010-06-12 21:49:00 +02:00
|
|
|
static Config &getInstance(std::pair<ConfigType,ConfigType> type = std::make_pair(cfgMainGame,cfgUserGame) ,
|
2010-12-09 21:41:11 +01:00
|
|
|
std::pair<string,string> file = std::make_pair(glest_ini_filename,glestuser_ini_filename) ,
|
2010-06-12 21:49:00 +02:00
|
|
|
std::pair<bool,bool> fileMustExist = std::make_pair(true,false) );
|
2010-06-12 20:27:39 +02:00
|
|
|
void save(const string &path="");
|
2010-09-09 23:07:39 +02:00
|
|
|
void reload();
|
2010-03-13 22:10:45 +01:00
|
|
|
|
|
|
|
int getInt(const string &key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
bool getBool(const string &key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
float getFloat(const string &key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
const string getString(const string &key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
|
|
|
|
int getInt(const char *key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
bool getBool(const char *key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
float getFloat(const char *key,const char *defaultValueIfNotFound=NULL) const;
|
|
|
|
const string getString(const char *key,const char *defaultValueIfNotFound=NULL) const;
|
2011-06-26 03:55:08 +02:00
|
|
|
//char getCharKey(const char *key) const;
|
|
|
|
SDLKey getSDLKey(const char *key) const;
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2012-07-06 18:29:49 +02:00
|
|
|
void setInt(const string &key, int value, bool tempBuffer=false);
|
|
|
|
void setBool(const string &key, bool value, bool tempBuffer=false);
|
|
|
|
void setFloat(const string &key, float value, bool tempBuffer=false);
|
|
|
|
void setString(const string &key, const string &value, bool tempBuffer=false);
|
2010-03-13 22:10:45 +01:00
|
|
|
|
2010-03-21 06:33:13 +01:00
|
|
|
vector<string> getPathListForType(PathType type, string scenarioDir = "");
|
2010-03-16 22:44:22 +01:00
|
|
|
|
2011-01-03 21:59:18 +01:00
|
|
|
vector<pair<string,string> > getMergedProperties() const;
|
|
|
|
vector<pair<string,string> > getMasterProperties() const;
|
|
|
|
vector<pair<string,string> > getUserProperties() const;
|
2011-03-04 23:54:04 +01:00
|
|
|
void setUserProperties(const vector<pair<string,string> > &valueList);
|
|
|
|
|
|
|
|
string getFileName(bool userFilename) const;
|
2011-01-03 21:59:18 +01:00
|
|
|
|
2011-06-26 03:55:08 +02:00
|
|
|
SDLKey translateStringToSDLKey(const string &value) const;
|
2011-03-04 21:26:47 +01:00
|
|
|
|
2010-03-13 22:10:45 +01:00
|
|
|
string toString();
|
2011-11-23 19:02:00 +01:00
|
|
|
|
|
|
|
static string getCustomRuntimeProperty(string key) { return customRuntimeProperties[key]; }
|
|
|
|
static void setCustomRuntimeProperty(string key, string value) { customRuntimeProperties[key] = value; }
|
2012-03-29 20:14:25 +02:00
|
|
|
|
|
|
|
static string findValidLocalFileFromPath(string fileName);
|
2010-03-13 22:10:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|