1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 15:39:02 +00:00
OpenMW/apps/openmw/mwdialogue/topic.cpp
florent.teppe 65cdd489fb create a specific esm reader function for RefID to avoid allocation for string and then again for RefId
Fixed some types

removed useless header

applied clang format

fixed compile tests

fixed clang tidy, and closer to logic before this MR

Removed hardcoded refids

unless there is a returned value we don't use static RefIds
can use == between RefId and hardcoded string

Fix clang format

Fixed a few instances where std::string was used, when only const std::string& was needed

removed unused variable
2022-12-27 19:15:57 +01:00

74 lines
1.7 KiB
C++

#include "topic.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/esmstore.hpp"
namespace MWDialogue
{
Topic::Topic() {}
Topic::Topic(const ESM::RefId& topic)
: mTopic(topic)
, mName(
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find(topic)->mId.getRefIdString())
{
}
Topic::~Topic() {}
bool Topic::addEntry(const JournalEntry& entry)
{
if (entry.mTopic != mTopic)
throw std::runtime_error("topic does not match: " + mTopic.getRefIdString());
// bail out if we already have heard this
for (Topic::TEntryIter it = mEntries.begin(); it != mEntries.end(); ++it)
{
if (it->mInfoId == entry.mInfoId)
return false;
}
mEntries.push_back(entry); // we want slicing here
return false;
}
void Topic::insertEntry(const ESM::JournalEntry& entry)
{
mEntries.push_back(entry);
}
const ESM::RefId& Topic::getTopic() const
{
return mTopic;
}
std::string_view Topic::getName() const
{
return mName;
}
Topic::TEntryIter Topic::begin() const
{
return mEntries.begin();
}
Topic::TEntryIter Topic::end() const
{
return mEntries.end();
}
void Topic::removeLastAddedResponse(std::string_view actorName)
{
for (std::vector<MWDialogue::Entry>::reverse_iterator it = mEntries.rbegin(); it != mEntries.rend(); ++it)
{
if (it->mActorName == actorName)
{
mEntries.erase((++it).base()); // erase doesn't take a reverse_iterator
return;
}
}
}
}