Fixes issue with iterating over two script sets.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2021-04-17 16:23:29 +02:00
parent 9f091308b0
commit 8f9f2b2b8d
2 changed files with 74 additions and 48 deletions

View File

@@ -7,7 +7,7 @@
namespace CreatureLib::Battling {
class ScriptAggregator {
const ScriptWrapper *_scripts;
const ScriptWrapper* _scripts;
i32 _size;
i32 _index = 0;
i32 _setIndex = 0;
@@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
inline void IncrementToNextNotNull(bool initialIncrement = true) {
if (_scripts[_index].IsSet()) {
_setIndex++;
if (_setIndex >= (i32) _scripts[_index].GetScriptSet()->Count()) {
if (_setIndex >= (i32)_scripts[_index].GetScriptSet()->Count()) {
_setIndex = -1;
} else {
return;
@@ -32,10 +32,10 @@ namespace CreatureLib::Battling {
}
public:
ScriptAggregator() {};
ScriptAggregator(){};
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper> &scripts)
: _scripts(scripts.RawData()), _size(scripts.Count()) {
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper>& scripts)
: _scripts(scripts.RawData()), _size(scripts.Count()) {
Reset();
};
@@ -60,13 +60,16 @@ namespace CreatureLib::Battling {
}
ArbUt::BorrowedPtr<BattleScript> GetNext() {
auto &current = _scripts[_index];
auto& current = _scripts[_index];
if (!current.IsSet()) {
auto s = current.GetScript();
IncrementToNextNotNull();
return (*s);
} else {
auto &set = current.GetScriptSet()->GetIterator();
auto& set = current.GetScriptSet()->GetIterator();
if (_setIndex == -1) {
_setIndex = 0;
}
auto v = set[_setIndex];
IncrementToNextNotNull();
return v;