1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-29 02:11:34 +00:00

Remove NAME handling from MWWorld::Globals

(cherry picked from commit 897a52cdda)
This commit is contained in:
Stanislav Bas 2015-07-08 21:40:01 +03:00 committed by cc9cii
parent 2564eb9841
commit f8b0cfc637
2 changed files with 14 additions and 16 deletions

View file

@ -13,7 +13,7 @@ namespace MWWorld
{
Globals::Collection::const_iterator Globals::find (const std::string& name) const
{
Collection::const_iterator iter = mVariables.find (name);
Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name));
if (iter==mVariables.end())
throw std::runtime_error ("unknown global variable: " + name);
@ -23,7 +23,7 @@ namespace MWWorld
Globals::Collection::iterator Globals::find (const std::string& name)
{
Collection::iterator iter = mVariables.find (name);
Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name));
if (iter==mVariables.end())
throw std::runtime_error ("unknown global variable: " + name);
@ -40,28 +40,28 @@ namespace MWWorld
for (MWWorld::Store<ESM::Global>::iterator iter = globals.begin(); iter!=globals.end();
++iter)
{
mVariables.insert (std::make_pair (iter->mId, iter->mValue));
mVariables.insert (std::make_pair (Misc::StringUtils::lowerCase (iter->mId), *iter));
}
}
const ESM::Variant& Globals::operator[] (const std::string& name) const
{
return find (name)->second;
return find (Misc::StringUtils::lowerCase (name))->second.mValue;
}
ESM::Variant& Globals::operator[] (const std::string& name)
{
return find (name)->second;
return find (Misc::StringUtils::lowerCase (name))->second.mValue;
}
char Globals::getType (const std::string& name) const
{
Collection::const_iterator iter = mVariables.find (name);
Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name));
if (iter==mVariables.end())
return ' ';
switch (iter->second.getType())
switch (iter->second.mValue.getType())
{
case ESM::VT_Short: return 's';
case ESM::VT_Long: return 'l';
@ -81,8 +81,7 @@ namespace MWWorld
for (Collection::const_iterator iter (mVariables.begin()); iter!=mVariables.end(); ++iter)
{
writer.startRecord (ESM::REC_GLOB);
writer.writeHNString ("NAME", iter->first);
iter->second.write (writer, ESM::Variant::Format_Global);
iter->second.save (writer);
writer.endRecord (ESM::REC_GLOB);
}
}
@ -91,14 +90,13 @@ namespace MWWorld
{
if (type==ESM::REC_GLOB)
{
std::string id = reader.getHNString ("NAME");
ESM::Global global;
global.load(reader);
Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (id));
Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (global.mId));
if (iter!=mVariables.end())
iter->second.read (reader, ESM::Variant::Format_Global);
else
reader.skipRecord();
iter->second = global;
return true;
}

View file

@ -8,7 +8,7 @@
#include <stdint.h>
#include <components/interpreter/types.hpp>
#include <components/esm/variant.hpp>
#include <components/esm/loadglob.hpp>
namespace ESM
{
@ -29,7 +29,7 @@ namespace MWWorld
{
private:
typedef std::map<std::string, ESM::Variant> Collection;
typedef std::map<std::string, ESM::Global> Collection;
Collection mVariables; // type, value