Fixes issue with iterating over two script sets.
continuous-integration/drone/push Build is passing Details

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

View File

@ -67,6 +67,9 @@ namespace CreatureLib::Battling {
return (*s);
} else {
auto& set = current.GetScriptSet()->GetIterator();
if (_setIndex == -1) {
_setIndex = 0;
}
auto v = set[_setIndex];
IncrementToNextNotNull();
return v;

View File

@ -97,8 +97,7 @@ TEST_CASE ("Script Aggregator properly iterates data of Script and Script Set.")
set.Add(script2);
set.Add(script3);
auto vec =
ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript> *>(&script)),
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script)),
ScriptWrapper::FromSet(&set)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
@ -129,6 +128,30 @@ TEST_CASE ("Script Aggregator properly iterates data of Script, Script Set and S
CHECK(ran == 4);
}
TEST_CASE("Script Aggregator properly iterates multiple script sets.") {
BattleScript* script1 = new TestScript("test");
BattleScript* script2 = new TestScript("test2");
BattleScript* script3 = new TestScript("test3");
BattleScript* script4 = new TestScript("test4");
auto ran = 0;
auto set1 = ScriptSet();
set1.Add(script2);
set1.Add(script3);
auto set2 = ScriptSet();
set2.Add(script1);
set2.Add(script4);
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromSet(&set1),
ScriptWrapper::FromSet(&set2),
};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 4);
}
TEST_CASE("Script Aggregator properly iterates when empty.") {
auto ran = 0;
auto vec = ArbUt::List<ScriptWrapper>{};