// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef R2_CONFIG_VAR_H
#define R2_CONFIG_VAR_H
#include"../interface_v3/lua_object.h"
#include"editor.h"
namespaceR2
{
// base class for he config file variables
classCConfigVarBase
{
public:
CConfigVarBase(constchar*varName);
protected:
mutableuint32_TimeStamp;// If this date is not the same than the config file date, then we know the
// value should be updated (so, more a counter than a timestamp, actually)
std::string_VarName;
private:
// not copyable
CConfigVarBase(constCConfigVarBase&/* other */){nlassert(0);}
CConfigVarBase&operator=(constCConfigVarBase&/* other */){nlassert(0);return*this;}
public:
staticuint32&getConfigFileTimeStamp();
};
/** Quick access to variables defined inside r2_config.lua.
*
*Variablesareupdatedwhentheeditorisreseted.
*Theyareusuallycreatedatglobalscope.
*
*Example:
*
*CConfigVarRGBACV_CreatureDefaultColor("CreatureDefaultColor",CRGBA(255,255,255,0)));// r2_config.lua may contains a 'CreatureDefaultColor' config value
nlwarning("Trying to access the config file value '%s' of type '%s' from r2_config.lua, but the file hasn't been parsed yet, or its parsing failed, using default value.",_VarName.c_str(),getConfigVarTypename(_Default).c_str());
_Value=_Default;
}
else
{
CLuaObjectluaValue=config[_VarName];
if(!getConfigVarValue(luaValue,_Value))
{
nlwarning("Can't retrieve value of R2 config var '%s', of type '%s', using default value",_VarName.c_str(),getConfigVarTypename(_Default).c_str());