mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 21:29:56 +00:00
Remove NAME handling from MWWorld::Globals
This commit is contained in:
parent
9301bc148e
commit
897a52cdda
2 changed files with 14 additions and 16 deletions
|
@ -14,7 +14,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);
|
||||
|
@ -24,7 +24,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);
|
||||
|
@ -41,28 +41,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';
|
||||
|
@ -82,8 +82,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);
|
||||
}
|
||||
}
|
||||
|
@ -92,14 +91,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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue