mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-21 09:11:33 +00:00
proper sorting for newly created records and some case smashing fixes
This commit is contained in:
parent
a06aa881cb
commit
3d8da2b9e0
2 changed files with 30 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "infocollection.hpp"
|
#include "infocollection.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <components/esm/esmreader.hpp>
|
#include <components/esm/esmreader.hpp>
|
||||||
#include <components/esm/loaddial.hpp>
|
#include <components/esm/loaddial.hpp>
|
||||||
|
|
||||||
|
@ -17,7 +19,7 @@ void CSMWorld::InfoCollection::load (const Info& record, bool base)
|
||||||
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
||||||
(base ? record2.mBase : record2.mModified) = record;
|
(base ? record2.mBase : record2.mModified) = record;
|
||||||
|
|
||||||
appendRecord (record2);
|
insertRecord (record2, getIdMap().size());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -33,6 +35,27 @@ void CSMWorld::InfoCollection::load (const Info& record, bool base)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSMWorld::InfoCollection::getAppendIndex (const std::string& id, UniversalId::Type type) const
|
||||||
|
{
|
||||||
|
std::string::size_type separator = id.find_last_of ('#');
|
||||||
|
|
||||||
|
if (separator==std::string::npos)
|
||||||
|
throw std::runtime_error ("invalid info ID: " + id);
|
||||||
|
|
||||||
|
std::pair<MapConstIterator, MapConstIterator> range = getTopicRange (id.substr (0, separator));
|
||||||
|
|
||||||
|
if (range.first==range.second)
|
||||||
|
return Collection<Info, IdAccessor<Info> >::getAppendIndex (id, type);
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (; range.first!=range.second; ++range.first)
|
||||||
|
if (range.first->second>index)
|
||||||
|
index = range.first->second;
|
||||||
|
|
||||||
|
return index+1;
|
||||||
|
}
|
||||||
|
|
||||||
void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue)
|
void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue)
|
||||||
{
|
{
|
||||||
/// \todo put records into proper order
|
/// \todo put records into proper order
|
||||||
|
@ -85,14 +108,14 @@ std::pair<CSMWorld::InfoCollection::MapConstIterator, CSMWorld::InfoCollection::
|
||||||
// Skip invalid records: The beginning of a topic string could be identical to another topic
|
// Skip invalid records: The beginning of a topic string could be identical to another topic
|
||||||
// string.
|
// string.
|
||||||
for (; begin!=getIdMap().end(); ++begin)
|
for (; begin!=getIdMap().end(); ++begin)
|
||||||
if (getRecord (begin->second).get().mTopicId==topic)
|
if (Misc::StringUtils::lowerCase (getRecord (begin->second).get().mTopicId)==topic2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Find end
|
// Find end
|
||||||
MapConstIterator end = begin;
|
MapConstIterator end = begin;
|
||||||
|
|
||||||
for (; end!=getIdMap().end(); ++end)
|
for (; end!=getIdMap().end(); ++end)
|
||||||
if (getRecord (end->second).get().mTopicId!=topic)
|
if (Misc::StringUtils::lowerCase (getRecord (end->second).get().mTopicId)!=topic2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
return std::make_pair (begin, end);
|
return std::make_pair (begin, end);
|
||||||
|
|
|
@ -23,6 +23,10 @@ namespace CSMWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual int getAppendIndex (const std::string& id,
|
||||||
|
UniversalId::Type type = UniversalId::Type_None) const;
|
||||||
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||||
|
|
||||||
void load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue);
|
void load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue);
|
||||||
|
|
||||||
std::pair<MapConstIterator, MapConstIterator> getTopicRange (const std::string& topic)
|
std::pair<MapConstIterator, MapConstIterator> getTopicRange (const std::string& topic)
|
||||||
|
|
Loading…
Reference in a new issue