1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 20:29:57 +00:00

fixed handling of case-insensitive IDs in esm store (cell list still on TODO list)

This commit is contained in:
Marc Zinnschlag 2010-07-04 13:07:01 +02:00
parent d57e67e722
commit c3c16facbf

View file

@ -4,6 +4,8 @@
#include "components/esm/records.hpp" #include "components/esm/records.hpp"
#include <map> #include <map>
#include <string> #include <string>
#include <algorithm>
#include <cctype>
#include <assert.h> #include <assert.h>
namespace ESMS namespace ESMS
@ -14,6 +16,16 @@ namespace ESMS
{ {
virtual void load(ESMReader &esm, const std::string &id) = 0; virtual void load(ESMReader &esm, const std::string &id) = 0;
virtual int getSize() = 0; virtual int getSize() = 0;
static std::string toLower (const std::string& name)
{
std::string lowerCase;
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
(int(*)(int)) std::tolower);
return lowerCase;
}
}; };
typedef std::map<int,RecList*> RecListList; typedef std::map<int,RecList*> RecListList;
@ -28,15 +40,17 @@ namespace ESMS
// Load one object of this type // Load one object of this type
void load(ESMReader &esm, const std::string &id) void load(ESMReader &esm, const std::string &id)
{ {
list[id].load(esm); std::string id2 = toLower (id);
list[id2].load(esm);
} }
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* find(const std::string &id) const const X* find(const std::string &id) const
{ {
if(list.find(id) == list.end()) std::string id2 = toLower (id);
if(list.find(id2) == list.end())
return NULL; return NULL;
return &list.find(id)->second; return &list.find(id2)->second;
} }
int getSize() { return list.size(); } int getSize() { return list.size(); }
@ -54,7 +68,8 @@ namespace ESMS
void load(ESMReader &esm, const std::string &id) void load(ESMReader &esm, const std::string &id)
{ {
X& ref = list[id]; std::string id2 = toLower (id);
X& ref = list[id2];
ref.id = id; ref.id = id;
ref.load(esm); ref.load(esm);
@ -65,6 +80,8 @@ namespace ESMS
// Cells aren't simply indexed by name. Exterior cells are treated // Cells aren't simply indexed by name. Exterior cells are treated
// separately. // separately.
// TODO: case handling (cell names are case-insensitive, but they are also showen to the
// player, so we can't simply smash case.
struct CellList : RecList struct CellList : RecList
{ {
// Total cell count. Used for statistics. // Total cell count. Used for statistics.
@ -145,7 +162,7 @@ namespace ESMS
X ref; X ref;
ref.load (esm); ref.load (esm);
std::string realId = ref.data.name.toString(); std::string realId = toLower (ref.data.name.toString());
std::swap (list[realId], ref); std::swap (list[realId], ref);
} }
@ -153,9 +170,10 @@ namespace ESMS
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* find(const std::string &id) const const X* find(const std::string &id) const
{ {
if(list.find(id) == list.end()) std::string id2 = toLower (id);
if(list.find(id2) == list.end())
return NULL; return NULL;
return &list.find(id)->second; return &list.find(id2)->second;
} }
int getSize() { return list.size(); } int getSize() { return list.size(); }