Merge branch 'cs_ref_id' into 'master'

Use ESM::RefId as index key in collections

See merge request OpenMW/openmw!2740
pull/3229/head
psi29a 2 years ago
commit 2fee5bdb73

@ -643,7 +643,7 @@ bool CSMFilter::Parser::parse(const std::string& filter, bool allowPredefined)
return false;
}
int index = mData.getFilters().searchId(token.mString);
const int index = mData.getFilters().searchId(ESM::RefId::stringRefId(token.mString));
if (index == -1)
{

@ -87,7 +87,7 @@ void CSMTools::ReferenceCheckStage::perform(int stage, CSMDoc::Messages& message
messages.add(id, "Invalid faction rank", "", CSMDoc::Message::Severity_Error);
}
if (!cellRef.mDestCell.empty() && mCells.searchId(cellRef.mDestCell) == -1)
if (!cellRef.mDestCell.empty() && mCells.searchId(ESM::RefId::stringRefId(cellRef.mDestCell)) == -1)
messages.add(
id, "Destination cell '" + cellRef.mDestCell + "' does not exist", "", CSMDoc::Message::Severity_Error);

@ -78,7 +78,7 @@ int CSMTools::TopicInfoCheckStage::setup()
mCellNames.insert(regionRecord.get().mName);
}
// Default cell name
int index = mGameSettings.searchId("sDefaultCellname");
const int index = mGameSettings.searchId(ESM::RefId::stringRefId("sDefaultCellname"));
if (index != -1)
{
const CSMWorld::Record<ESM::GameSetting>& gmstRecord = mGameSettings.getRecord(index);

@ -86,7 +86,7 @@ namespace CSMWorld
private:
std::vector<std::unique_ptr<Record<ESXRecordT>>> mRecords;
std::map<std::string, int> mIndex;
std::map<ESM::RefId, int> mIndex;
std::vector<Column<ESXRecordT>*> mColumns;
// not implemented
@ -148,10 +148,6 @@ namespace CSMWorld
///< Change the state of a record from base to modified, if it is not already.
/// \return True if the record was changed.
int searchId(std::string_view id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
int searchId(const ESM::RefId& id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
@ -232,9 +228,9 @@ namespace CSMWorld
std::move(buffer.begin(), buffer.end(), mRecords.begin() + baseIndex);
// adjust index
for (std::map<std::string, int>::iterator iter(mIndex.begin()); iter != mIndex.end(); ++iter)
if (iter->second >= baseIndex && iter->second < baseIndex + size)
iter->second = newOrder.at(iter->second - baseIndex) + baseIndex;
for (auto& [id, index] : mIndex)
if (index >= baseIndex && index < baseIndex + size)
index = newOrder.at(index - baseIndex) + baseIndex;
}
return true;
@ -329,9 +325,9 @@ namespace CSMWorld
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::add(const ESXRecordT& record)
{
auto id = IdAccessorT().getId(record);
const ESM::RefId id = IdAccessorT().getId(record);
auto iter = mIndex.find(Misc::StringUtils::lowerCase(id.getRefIdString()));
auto iter = mIndex.find(id);
if (iter == mIndex.end())
{
@ -438,7 +434,7 @@ namespace CSMWorld
{
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
typename std::map<std::string, int>::iterator iter = mIndex.begin();
auto iter = mIndex.begin();
while (iter != mIndex.end())
{
@ -451,7 +447,7 @@ namespace CSMWorld
}
else
{
mIndex.erase(iter++);
iter = mIndex.erase(iter);
}
}
else
@ -474,11 +470,9 @@ namespace CSMWorld
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::searchId(std::string_view id) const
int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
{
std::string id2 = Misc::StringUtils::lowerCase(id);
std::map<std::string, int>::const_iterator iter = mIndex.find(id2);
const auto iter = mIndex.find(id);
if (iter == mIndex.end())
return -1;
@ -486,13 +480,6 @@ namespace CSMWorld
return iter->second;
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
{
return searchId(id.getRefIdString());
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::replace(int index, std::unique_ptr<RecordBase> record)
{
@ -549,7 +536,7 @@ namespace CSMWorld
throw std::runtime_error("index out of range");
std::unique_ptr<Record<ESXRecordT>> record2(static_cast<Record<ESXRecordT>*>(record.release()));
std::string id = Misc::StringUtils::lowerCase(IdAccessorT().getId(record2->get()).getRefIdString());
ESM::RefId id = IdAccessorT().getId(record2->get());
if (index == size)
mRecords.push_back(std::move(record2));
@ -558,10 +545,10 @@ namespace CSMWorld
if (index < size - 1)
{
for (std::map<std::string, int>::iterator iter(mIndex.begin()); iter != mIndex.end(); ++iter)
for (auto& [key, value] : mIndex)
{
if (iter->second >= index)
++(iter->second);
if (value >= index)
++value;
}
}

@ -11,9 +11,9 @@ CSMWorld::CollectionBase::CollectionBase() {}
CSMWorld::CollectionBase::~CollectionBase() {}
int CSMWorld::CollectionBase::getInsertIndex(const std::string& id, UniversalId::Type type, RecordBase* record) const
int CSMWorld::CollectionBase::getInsertIndex(const ESM::RefId& id, UniversalId::Type type, RecordBase* record) const
{
return getAppendIndex(ESM::RefId::stringRefId(id), type);
return getAppendIndex(id, type);
}
int CSMWorld::CollectionBase::searchColumnIndex(Columns::ColumnId id) const

@ -65,10 +65,6 @@ namespace CSMWorld
virtual void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
virtual int searchId(std::string_view id) const = 0;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
virtual int searchId(const ESM::RefId& id) const = 0;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
@ -107,7 +103,7 @@ namespace CSMWorld
/// \return Success?
virtual int getInsertIndex(
const std::string& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const;
const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const;
///< Works like getAppendIndex unless an overloaded method uses the record pointer
/// to get additional info about the record that results in an alternative index.

@ -1072,13 +1072,14 @@ void CSMWorld::Data::loadFallbackEntries()
std::pair<std::string, std::string> doorMarkers[] = { std::make_pair("PrisonMarker", "marker_prison.nif") };
for (const auto& marker : staticMarkers)
for (const auto& [id, model] : staticMarkers)
{
if (mReferenceables.searchId(marker.first) == -1)
const ESM::RefId refId = ESM::RefId::stringRefId(id);
if (mReferenceables.searchId(refId) == -1)
{
ESM::Static newMarker;
newMarker.mId = ESM::RefId::stringRefId(marker.first);
newMarker.mModel = marker.second;
newMarker.mId = refId;
newMarker.mModel = model;
newMarker.mRecordFlags = 0;
auto record = std::make_unique<CSMWorld::Record<ESM::Static>>();
record->mBase = newMarker;
@ -1087,13 +1088,14 @@ void CSMWorld::Data::loadFallbackEntries()
}
}
for (const auto& marker : doorMarkers)
for (const auto& [id, model] : doorMarkers)
{
if (mReferenceables.searchId(marker.first) == -1)
const ESM::RefId refId = ESM::RefId::stringRefId(id);
if (mReferenceables.searchId(refId) == -1)
{
ESM::Door newMarker;
newMarker.mId = ESM::RefId::stringRefId(marker.first);
newMarker.mModel = marker.second;
newMarker.mId = refId;
newMarker.mModel = model;
newMarker.mRecordFlags = 0;
auto record = std::make_unique<CSMWorld::Record<ESM::Door>>();
record->mBase = newMarker;
@ -1280,25 +1282,24 @@ bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages)
bool isDeleted = false;
record.load(*mReader, isDeleted);
const std::string& recordIdString = record.mId.getRefIdString();
if (isDeleted)
{
// record vector can be shuffled around which would make pointer to record invalid
mDialogue = nullptr;
if (mJournals.tryDelete(recordIdString))
if (mJournals.tryDelete(record.mId))
{
removeDialogueInfos(record.mId, mJournalInfosByTopic, mJournalInfos);
}
else if (mTopics.tryDelete(recordIdString))
else if (mTopics.tryDelete(record.mId))
{
removeDialogueInfos(record.mId, mTopicInfosByTopic, mTopicInfos);
}
else
{
messages.add(UniversalId::Type_None,
"Trying to delete dialogue record " + recordIdString + " which does not exist", "",
"Trying to delete dialogue record " + record.mId.getRefIdString() + " which does not exist", "",
CSMDoc::Message::Severity_Warning);
}
}
@ -1378,13 +1379,15 @@ bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages)
bool CSMWorld::Data::hasId(const std::string& id) const
{
return getGlobals().searchId(id) != -1 || getGmsts().searchId(id) != -1 || getSkills().searchId(id) != -1
|| getClasses().searchId(id) != -1 || getFactions().searchId(id) != -1 || getRaces().searchId(id) != -1
|| getSounds().searchId(id) != -1 || getScripts().searchId(id) != -1 || getRegions().searchId(id) != -1
|| getBirthsigns().searchId(id) != -1 || getSpells().searchId(id) != -1 || getTopics().searchId(id) != -1
|| getJournals().searchId(id) != -1 || getCells().searchId(id) != -1 || getEnchantments().searchId(id) != -1
|| getBodyParts().searchId(id) != -1 || getSoundGens().searchId(id) != -1
|| getMagicEffects().searchId(id) != -1 || getReferenceables().searchId(id) != -1;
const ESM::RefId refId = ESM::RefId::stringRefId(id);
return getGlobals().searchId(refId) != -1 || getGmsts().searchId(refId) != -1 || getSkills().searchId(refId) != -1
|| getClasses().searchId(refId) != -1 || getFactions().searchId(refId) != -1 || getRaces().searchId(refId) != -1
|| getSounds().searchId(refId) != -1 || getScripts().searchId(refId) != -1 || getRegions().searchId(refId) != -1
|| getBirthsigns().searchId(refId) != -1 || getSpells().searchId(refId) != -1
|| getTopics().searchId(refId) != -1 || getJournals().searchId(refId) != -1 || getCells().searchId(refId) != -1
|| getEnchantments().searchId(refId) != -1 || getBodyParts().searchId(refId) != -1
|| getSoundGens().searchId(refId) != -1 || getMagicEffects().searchId(refId) != -1
|| getReferenceables().searchId(refId) != -1;
}
int CSMWorld::Data::count(RecordBase::State state) const

@ -40,7 +40,7 @@ namespace CSMWorld
/// \return index
int load(const ESXRecordT& record, bool base, int index = -2);
bool tryDelete(const std::string& id);
bool tryDelete(const ESM::RefId& id);
///< Try deleting \a id. If the id does not exist or can't be deleted the call is ignored.
///
/// \return Has the ID been deleted?
@ -135,7 +135,7 @@ namespace CSMWorld
}
template <typename ESXRecordT, typename IdAccessorT>
bool IdCollection<ESXRecordT, IdAccessorT>::tryDelete(const std::string& id)
bool IdCollection<ESXRecordT, IdAccessorT>::tryDelete(const ESM::RefId& id)
{
int index = this->searchId(id);

@ -243,7 +243,8 @@ std::string CSMWorld::IdTable::getId(int row) const
/// This method can return only indexes to the top level table cells
QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column) const
{
int row = mIdCollection->searchId(id);
const int row = mIdCollection->searchId(ESM::RefId::stringRefId(id));
if (row != -1)
return index(row, column);
@ -253,7 +254,8 @@ QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column)
void CSMWorld::IdTable::setRecord(
const std::string& id, std::unique_ptr<RecordBase> record, CSMWorld::UniversalId::Type type)
{
int index = mIdCollection->searchId(id);
const ESM::RefId refId = ESM::RefId::stringRefId(id);
const int index = mIdCollection->searchId(refId);
if (index == -1)
{
@ -263,7 +265,7 @@ void CSMWorld::IdTable::setRecord(
//
// Use an alternative method to get the correct index. For non-Info records the
// record pointer is ignored and internally calls getAppendIndex.
int index2 = mIdCollection->getInsertIndex(id, type, record.get());
const int index2 = mIdCollection->getInsertIndex(refId, type, record.get());
beginInsertRows(QModelIndex(), index2, index2);
@ -377,9 +379,10 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import
for (const std::string& id : ids)
{
int plugin, index;
LandTexture::parseUniqueRecordId(id, plugin, index);
int oldRow = idCollection()->searchId(id);
const ESM::RefId refId = ESM::RefId::stringRefId(id);
const int oldRow = idCollection()->searchId(refId);
// If it does not exist or it is in the current plugin, it can be skipped.
if (oldRow < 0 || plugin == 0)
@ -403,12 +406,13 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import
do
{
std::string newId = LandTexture::createUniqueRecordId(0, index);
int newRow = idCollection()->searchId(newId);
const ESM::RefId newRefId = ESM::RefId::stringRefId(newId);
int newRow = idCollection()->searchId(newRefId);
if (newRow < 0)
{
// Id not taken, clone it
cloneRecord(ESM::RefId::stringRefId(id), ESM::RefId::stringRefId(newId), UniversalId::Type_LandTexture);
cloneRecord(refId, newRefId, UniversalId::Type_LandTexture);
results.createdRecords.push_back(newId);
results.recordMapping.emplace_back(id, newId);
reverseLookupMap.emplace(texture, newId);

@ -12,7 +12,7 @@
bool CSMWorld::InfoCollection::load(const Info& record, bool base)
{
int index = searchId(record.mId.getRefIdString());
const int index = searchId(record.mId);
if (index == -1)
{
@ -48,7 +48,7 @@ void CSMWorld::InfoCollection::load(
bool isDeleted = false;
info.load(reader, isDeleted);
std::string id = dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString();
const ESM::RefId id = ESM::RefId::stringRefId(dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString());
if (isDeleted)
{
@ -75,7 +75,7 @@ void CSMWorld::InfoCollection::load(
{
info.mTopicId = dialogue.mId;
info.mOriginalId = info.mId;
info.mId = ESM::RefId::stringRefId(id);
info.mId = id;
if (load(info, base))
infosByTopic[dialogue.mId].push_back(info.mId);

@ -725,9 +725,9 @@ void CSMWorld::RefIdCollection::appendBlankRecord(const ESM::RefId& id, Universa
mData.appendRecord(type, id, false);
}
int CSMWorld::RefIdCollection::searchId(std::string_view id) const
int CSMWorld::RefIdCollection::searchId(const ESM::RefId& id) const
{
RefIdData::LocalIndex localIndex = mData.searchId(ESM::RefId::stringRefId(id));
const RefIdData::LocalIndex localIndex = mData.searchId(id);
if (localIndex.first == -1)
return -1;
@ -735,11 +735,6 @@ int CSMWorld::RefIdCollection::searchId(std::string_view id) const
return mData.localToGlobalIndex(localIndex);
}
int CSMWorld::RefIdCollection::searchId(const ESM::RefId& id) const
{
return searchId(id.getRefIdString());
}
void CSMWorld::RefIdCollection::replace(int index, std::unique_ptr<RecordBase> record)
{
mData.getRecord(mData.globalToLocalIndex(index)).assign(*record.release());

@ -89,10 +89,6 @@ namespace CSMWorld
void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type) override;
///< \param type Will be ignored, unless the collection supports multiple record types
int searchId(std::string_view id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
int searchId(const ESM::RefId& id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)

@ -32,7 +32,7 @@ bool CSMWorld::ScriptContext::canDeclareLocals() const
char CSMWorld::ScriptContext::getGlobalType(const std::string& name) const
{
int index = mData.getGlobals().searchId(name);
const int index = mData.getGlobals().searchId(ESM::RefId::stringRefId(name));
if (index != -1)
{

@ -128,7 +128,7 @@ namespace CSVRender
{
const auto& bodyParts = mData.getBodyParts();
int index = bodyParts.searchId(bodyPartId);
const int index = bodyParts.searchId(ESM::RefId::stringRefId(bodyPartId));
if (index != -1 && !bodyParts.getRecord(index).isDeleted())
return MeshPrefix + bodyParts.getRecord(index).get().mModel;
else

@ -57,7 +57,7 @@ namespace CSVRender
mWaterGroup = new osg::Group();
mWaterTransform->addChild(mWaterGroup);
int cellIndex = mData.getCells().searchId(mId);
const int cellIndex = mData.getCells().searchId(ESM::RefId::stringRefId(mId));
if (cellIndex > -1)
{
updateCellData(mData.getCells().getRecord(cellIndex));

@ -965,7 +965,7 @@ void CSVRender::InstanceMode::dropEvent(QDropEvent* event)
CSMWorld::IdTree& cellTable
= dynamic_cast<CSMWorld::IdTree&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells));
bool noCell = document.getData().getCells().searchId(cellId) == -1;
const bool noCell = document.getData().getCells().searchId(ESM::RefId::stringRefId(cellId)) == -1;
if (noCell)
{

@ -77,7 +77,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
else
{
// update
int index = cells.searchId(iter->first.getId(mWorldspace));
const int index = cells.searchId(ESM::RefId::stringRefId(iter->first.getId(mWorldspace)));
bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted;
@ -460,7 +460,7 @@ void CSVRender::PagedWorldspaceWidget::addCellToScene(const CSMWorld::CellCoordi
{
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells();
int index = cells.searchId(coordinates.getId(mWorldspace));
const int index = cells.searchId(ESM::RefId::stringRefId(coordinates.getId(mWorldspace)));
bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted;

@ -296,14 +296,14 @@ bool CSVRender::TerrainSelection::noCell(const std::string& cellId)
{
CSMDoc::Document& document = mWorldspaceWidget->getDocument();
const CSMWorld::IdCollection<CSMWorld::Cell>& cellCollection = document.getData().getCells();
return cellCollection.searchId(cellId) == -1;
return cellCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
}
bool CSVRender::TerrainSelection::noLand(const std::string& cellId)
{
CSMDoc::Document& document = mWorldspaceWidget->getDocument();
const CSMWorld::IdCollection<CSMWorld::Land>& landCollection = document.getData().getLand();
return landCollection.searchId(cellId) == -1;
return landCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
}
bool CSVRender::TerrainSelection::noLandLoaded(const std::string& cellId)

@ -1326,14 +1326,14 @@ bool CSVRender::TerrainShapeMode::noCell(const std::string& cellId)
{
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
const CSMWorld::IdCollection<CSMWorld::Cell>& cellCollection = document.getData().getCells();
return cellCollection.searchId(cellId) == -1;
return cellCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
}
bool CSVRender::TerrainShapeMode::noLand(const std::string& cellId)
{
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
const CSMWorld::IdCollection<CSMWorld::Land>& landCollection = document.getData().getLand();
return landCollection.searchId(cellId) == -1;
return landCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
}
bool CSVRender::TerrainShapeMode::noLandLoaded(const std::string& cellId)

@ -32,7 +32,8 @@ namespace CSVRender
{
// The cell isn't guaranteed to have Land. This is because the terrain implementation
// has to wrap the vertices of the last row and column to the next cell, which may be a nonexisting cell
int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY));
const int index
= mData.getLand().searchId(ESM::RefId::stringRefId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)));
if (index == -1)
return nullptr;
@ -43,7 +44,8 @@ namespace CSVRender
const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
{
int row = mData.getLandTextures().searchId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index));
const int row = mData.getLandTextures().searchId(
ESM::RefId::stringRefId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index)));
if (row == -1)
return nullptr;
@ -65,7 +67,8 @@ namespace CSVRender
{
float height = 0.f;
int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY));
const int index
= mData.getLand().searchId(ESM::RefId::stringRefId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)));
if (index == -1) // no land!
return height;

@ -137,7 +137,7 @@ void CSVRender::TerrainTextureMode::primaryEditPressed(const WorldspaceHitResult
QUndoStack& undoStack = document.getUndoStack();
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture);
int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr)
{
@ -186,7 +186,7 @@ bool CSVRender::TerrainTextureMode::primaryEditStartDrag(const QPoint& pos)
mDragMode = InteractionType_PrimaryEdit;
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture);
const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr)
{
@ -242,7 +242,7 @@ void CSVRender::TerrainTextureMode::drag(const QPoint& pos, int diffX, int diffY
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture);
const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr)
{
@ -273,7 +273,7 @@ void CSVRender::TerrainTextureMode::dragCompleted(const QPoint& pos)
QUndoStack& undoStack = document.getUndoStack();
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture);
const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{
@ -718,8 +718,9 @@ bool CSVRender::TerrainTextureMode::allowLandTextureEditing(std::string cellId)
CSMWorld::IdTree& cellTable
= dynamic_cast<CSMWorld::IdTree&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells));
bool noCell = document.getData().getCells().searchId(cellId) == -1;
bool noLand = document.getData().getLand().searchId(cellId) == -1;
const ESM::RefId cellRefId = ESM::RefId::stringRefId(cellId);
const bool noCell = document.getData().getCells().searchId(cellRefId) == -1;
const bool noLand = document.getData().getLand().searchId(cellRefId) == -1;
if (noCell)
{

@ -77,7 +77,7 @@ CSVWidget::TextureBrushWindow::TextureBrushWindow(CSMDoc::Document& document, QW
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
int index = landtexturesCollection.searchId(mBrushTexture);
const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{
@ -164,9 +164,11 @@ void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture)
int index = 0;
int pluginInDragged = 0;
CSMWorld::LandTexture::parseUniqueRecordId(brushTexture, pluginInDragged, index);
const ESM::RefId brushTextureRefId = ESM::RefId::stringRefId(brushTexture);
std::string newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, index);
int rowInBase = landtexturesCollection.searchId(brushTexture);
int rowInNew = landtexturesCollection.searchId(newBrushTextureId);
ESM::RefId newBrushTextureRefId = ESM::RefId::stringRefId(newBrushTextureId);
int rowInBase = landtexturesCollection.searchId(brushTextureRefId);
int rowInNew = landtexturesCollection.searchId(newBrushTextureRefId);
// Check if texture exists in current plugin, and clone if id found in base, otherwise reindex the texture
// TO-DO: Handle case when texture is not found in neither base or plugin properly (finding new index is not enough)
@ -181,10 +183,11 @@ void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture)
do
{
newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, counter);
if (landtexturesCollection.searchId(brushTexture) != -1
&& landtexturesCollection.getRecord(ESM::RefId::stringRefId(brushTexture)).isDeleted() == 0
&& landtexturesCollection.searchId(newBrushTextureId) != -1
&& landtexturesCollection.getRecord(ESM::RefId::stringRefId(newBrushTextureId)).isDeleted() == 0)
newBrushTextureRefId = ESM::RefId::stringRefId(newBrushTextureId);
if (landtexturesCollection.searchId(brushTextureRefId) != -1
&& landtexturesCollection.getRecord(brushTextureRefId).isDeleted() == 0
&& landtexturesCollection.searchId(newBrushTextureRefId) != -1
&& landtexturesCollection.getRecord(newBrushTextureRefId).isDeleted() == 0)
counter = (counter + 1) % maxCounter;
else
freeIndexFound = true;
@ -307,7 +310,7 @@ void CSVWidget::SceneToolTextureBrush::setButtonIcon(CSVWidget::BrushShape brush
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
int index = landtexturesCollection.searchId(mTextureBrushWindow->mBrushTexture);
const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mTextureBrushWindow->mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{
@ -339,7 +342,7 @@ void CSVWidget::SceneToolTextureBrush::updatePanel()
{
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
int index = landtexturesCollection.searchId(mBrushHistory[i]);
const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushHistory[i]));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{

@ -126,7 +126,7 @@ std::string CSVWorld::InfoCreator::getErrors() const
// We ignore errors from GenericCreator here, because they can never happen in an InfoCreator.
std::string errors;
std::string topic = mTopic->text().toUtf8().constData();
const ESM::RefId topic = ESM::RefId::stringRefId(mTopic->text().toStdString());
if ((getCollectionId().getType() == CSMWorld::UniversalId::Type_TopicInfos ? getData().getTopics()
: getData().getJournals())

@ -89,7 +89,7 @@ namespace CSVWorld
std::string LandCreator::getErrors() const
{
if (getData().getLand().searchId(getId()) >= 0)
if (getData().getLand().searchId(ESM::RefId::stringRefId(getId())) >= 0)
return "A land with that name already exists.";
return "";

@ -72,7 +72,7 @@ namespace CSVWorld
std::string LandTextureCreator::getErrors() const
{
if (getData().getLandTextures().searchId(getId()) >= 0)
if (getData().getLandTextures().searchId(ESM::RefId::stringRefId(getId())) >= 0)
{
return "Index is already in use";
}

@ -62,7 +62,7 @@ void CSVWorld::PathgridCreator::cloneMode(const std::string& originId, const CSM
std::string CSVWorld::PathgridCreator::getErrors() const
{
std::string cellId = getId();
const ESM::RefId cellId = ESM::RefId::stringRefId(getId());
// Check user input for any errors.
std::string errors;

@ -22,7 +22,7 @@ CSVWorld::PreviewSubView::PreviewSubView(const CSMWorld::UniversalId& id, CSMDoc
{
QHBoxLayout* layout = new QHBoxLayout;
if (document.getData().getReferenceables().searchId(id.getId()) == -1)
if (document.getData().getReferenceables().searchId(ESM::RefId::stringRefId(id.getId())) == -1)
{
std::string referenceableId = document.getData()
.getReferences()

@ -65,7 +65,7 @@ std::string CSVWorld::ReferenceCreator::getErrors() const
// record is internal and requires neither user input nor verification.
std::string errors;
std::string cell = mCell->text().toUtf8().constData();
const ESM::RefId cell = ESM::RefId::stringRefId(mCell->text().toStdString());
if (cell.empty())
errors += "Missing Cell ID";

@ -62,7 +62,7 @@ void CSVWorld::StartScriptCreator::cloneMode(const std::string& originId, const
std::string CSVWorld::StartScriptCreator::getErrors() const
{
std::string scriptId = getId();
const ESM::RefId scriptId = ESM::RefId::stringRefId(getId());
// Check user input for any errors.
std::string errors;

@ -152,7 +152,7 @@ void CSVWorld::Table::contextMenuEvent(QContextMenuEvent* event)
{
CSMWorld::UniversalId id = mModel->view(row).first;
int index = mDocument.getData().getCells().searchId(id.getId());
const int index = mDocument.getData().getCells().searchId(ESM::RefId::stringRefId(id.getId()));
// index==-1: the ID references a worldspace instead of a cell (ignore for now and go
// ahead)

Loading…
Cancel
Save