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

ESM::Dialogue Lua bindings 6

This commit is contained in:
trav5 2024-04-20 20:23:37 +02:00
parent c1639e54b1
commit 277d830530

View file

@ -36,6 +36,7 @@ namespace
{ {
using DecoratedIterator = MWWorld::Store<ESM::Dialogue>::iterator; using DecoratedIterator = MWWorld::Store<ESM::Dialogue>::iterator;
DecoratedIterator mIter; DecoratedIterator mIter;
DecoratedIterator mEndIter;
public: public:
using iterator_category = DecoratedIterator::iterator_category; using iterator_category = DecoratedIterator::iterator_category;
@ -44,8 +45,9 @@ namespace
using pointer = DecoratedIterator::pointer; using pointer = DecoratedIterator::pointer;
using reference = DecoratedIterator::reference; using reference = DecoratedIterator::reference;
FilteredDialogueIterator(const DecoratedIterator& decoratedIterator) FilteredDialogueIterator(const DecoratedIterator& pointingIterator, const DecoratedIterator& end)
: mIter{ decoratedIterator } : mIter{ pointingIterator }
, mEndIter{ end }
{ {
} }
@ -53,8 +55,8 @@ namespace
{ {
do do
{ {
std::advance(mIter, 1); ++mIter;
} while (mIter->mType != filter); } while (mIter->mType != filter and mIter != mEndIter);
return *this; return *this;
} }
@ -63,17 +65,17 @@ namespace
FilteredDialogueIterator iter = *this; FilteredDialogueIterator iter = *this;
do do
{ {
std::advance(mIter, 1); ++mIter;
} while (mIter->mType != filter); } while (mIter->mType != filter and mIter != mEndIter);
return iter; return iter;
} }
FilteredDialogueIterator& operator+=(difference_type advance) FilteredDialogueIterator& operator+=(difference_type advance)
{ {
while (advance > 0) while (advance > 0 and mIter != mEndIter)
{ {
std::advance(mIter, 1); ++mIter;
if (mIter->mType != filter) if (mIter->mType == filter)
{ {
--advance; --advance;
} }
@ -105,7 +107,7 @@ namespace
} }
auto result = begin(); auto result = begin();
std::advance(result, index); result += index;
return &(*result); return &(*result);
} }
@ -118,15 +120,15 @@ namespace
iterator begin() const iterator begin() const
{ {
iterator result{ mDialogueStore.begin() }; iterator result{ mDialogueStore.begin(), mDialogueStore.end() };
while (result != end() and result->mType != filter) while (result != end() and result->mType != filter)
{ {
std::advance(result, 1); ++result;
} }
return result; return result;
} }
iterator end() const { return iterator{ mDialogueStore.end() }; } iterator end() const { return iterator{ mDialogueStore.end(), mDialogueStore.end() }; }
}; };
template <ESM::Dialogue::Type filter> template <ESM::Dialogue::Type filter>