class
CSettingManager
{
private
:
std::map
<
std::
string
,std::
string
>
m_Settings;
std::
string
m_Filename;
public
:
void
Load(std::
string
server, std::
string
character);
void
Save(
void
);
const
std::
string
&
Get( std::
string
key,
const
std::
string
&
default_value
=
std::
string
() )
{
std::map
<
std::
string
,std::
string
>
::iterator itor
=
m_Settings.find(key);
if
( itor
==
m_Settings.end() )
{
Set(key,default_value);
return
default_value;
}
return
itor
->
second;
}
void
Set(std::
string
key,
const
std::
string
&
value)
{
m_Settings[key]
=
value;
}
template
<
class
T
>
T Get( std::
string
key, T default_value
=
T(
0
))
{
std::map
<
std::
string
,std::
string
>
::iterator itor
=
m_Settings.find(key);
if
( itor
==
m_Settings.end() )
{
Set
<
T
>
(key,default_value);
return
default_value;
}
return
boost::lexical_cast
<
T,std::
string
>
(itor
->
second);
}
template
<
class
T
>
void
Set(std::
string
key, T value)
{
m_Settings[key]
=
boost::lexical_cast
<
std::
string
,T
>
(value);
}
}
;
使用
void Load( void )
{
SmartAccelerate=m_Game.m_SettingMgr.Get("系统_智能加速",false);
MoveSpeed=m_Game.m_SettingMgr.Get("系统_移动速度",static_cast<DWORD>(0));
AttackSpeed=m_Game.m_SettingMgr.Get("系统_攻击速度",static_cast<DWORD>(0));
ShowMiniMap=m_Game.m_SettingMgr.Get("系统_显示实景地图",false);
AlwaysLongHit=m_Game.m_SettingMgr.Get("战士_刀刀刺杀",false);
AutoWideHit=m_Game.m_SettingMgr.Get("战士_智能半月",false);
WideHitLevel=m_Game.m_SettingMgr.Get("战士_智能半月数值",static_cast<int>(0));
AutoFireHit=m_Game.m_SettingMgr.Get("战士_自动烈火",false);
FireHitDelay=m_Game.m_SettingMgr.Get("战士_自动烈火间隔",static_cast<int>(0));
LoginScript=m_Game.m_SettingMgr.Get("脚本_上线脚本",std::string());
HpKeeper=m_Game.m_SettingMgr.Get("保护_HP保持",false);
HpKeepLevel=m_Game.m_SettingMgr.Get("保护_HP数值",static_cast<int>(0));
MpKeeper=m_Game.m_SettingMgr.Get("保护_MP保持",false);
MpKeepLevel=m_Game.m_SettingMgr.Get("保护_MP数值",static_cast<int>(0));
std::vector<std::string> sl;
std::string str=m_Game.m_SettingMgr.Get("保护_保护物品",std::string());
CGameMir::SplitString(str.c_str(),";",sl);
m_ProtectItems.clear();
for ( std::vector<std::string>::iterator pos=sl.begin(); pos!=sl.end(); ++pos )
{
std::vector<std::string> item;
CGameMir::SplitString(pos->c_str(),"/",item);
if ( item.size()<3 )
continue;
m_ProtectItems[item[0]] =
std::pair<int,int>(boost::lexical_cast<int>(item[1]),boost::lexical_cast<int>(item[2]));
}
}
void Save( void )
{
m_Game.m_SettingMgr.Set("系统_智能加速",SmartAccelerate);
m_Game.m_SettingMgr.Set("系统_移动速度",MoveSpeed);
m_Game.m_SettingMgr.Set("系统_攻击速度",AttackSpeed);
m_Game.m_SettingMgr.Set("系统_显示实景地图",ShowMiniMap);
m_Game.m_SettingMgr.Set("战士_刀刀刺杀",AlwaysLongHit);
m_Game.m_SettingMgr.Set("战士_智能半月",AutoWideHit);
m_Game.m_SettingMgr.Set("战士_智能半月数值",WideHitLevel);
m_Game.m_SettingMgr.Get("战士_自动烈火",AutoFireHit);
m_Game.m_SettingMgr.Set("战士_自动烈火间隔",FireHitDelay);
m_Game.m_SettingMgr.Set("脚本_上线脚本",LoginScript);
m_Game.m_SettingMgr.Set("保护_HP保持",HpKeeper);
m_Game.m_SettingMgr.Set("保护_HP数值",HpKeepLevel);
m_Game.m_SettingMgr.Set("保护_MP保持",MpKeeper);
m_Game.m_SettingMgr.Set("保护_MP数值",MpKeepLevel);
std::string str;
str.clear();
for ( std::map<std::string,std::pair<int,int> >::iterator pos=m_ProtectItems.begin(); pos!=m_ProtectItems.end(); ++pos )
{
std::string item;
item=pos->first;
item+=("/"+boost::lexical_cast<std::string>(pos->second.first));
item+=("/"+boost::lexical_cast<std::string>(pos->second.second));
str+=(item+";");
}
m_Game.m_SettingMgr.Set("保护_保护物品",str);
m_Game.m_SettingMgr.Save();
}
posted on 2006-10-03 21:14
shaker(太子) 阅读(1810)
评论(1) 编辑 收藏 引用 所属分类:
C++