Fixes issue with iterating over two script sets.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
9f091308b0
commit
8f9f2b2b8d
|
@ -67,6 +67,9 @@ namespace CreatureLib::Battling {
|
||||||
return (*s);
|
return (*s);
|
||||||
} else {
|
} else {
|
||||||
auto& set = current.GetScriptSet()->GetIterator();
|
auto& set = current.GetScriptSet()->GetIterator();
|
||||||
|
if (_setIndex == -1) {
|
||||||
|
_setIndex = 0;
|
||||||
|
}
|
||||||
auto v = set[_setIndex];
|
auto v = set[_setIndex];
|
||||||
IncrementToNextNotNull();
|
IncrementToNextNotNull();
|
||||||
return v;
|
return v;
|
||||||
|
|
|
@ -97,8 +97,7 @@ TEST_CASE ("Script Aggregator properly iterates data of Script and Script Set.")
|
||||||
set.Add(script2);
|
set.Add(script2);
|
||||||
set.Add(script3);
|
set.Add(script3);
|
||||||
auto vec =
|
auto vec =
|
||||||
ArbUt::List<ScriptWrapper>{
|
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script)),
|
||||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript> *>(&script)),
|
|
||||||
ScriptWrapper::FromSet(&set)};
|
ScriptWrapper::FromSet(&set)};
|
||||||
auto aggr = ScriptAggregator(vec);
|
auto aggr = ScriptAggregator(vec);
|
||||||
while (aggr.HasNext()) {
|
while (aggr.HasNext()) {
|
||||||
|
@ -129,6 +128,30 @@ TEST_CASE ("Script Aggregator properly iterates data of Script, Script Set and S
|
||||||
CHECK(ran == 4);
|
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.") {
|
TEST_CASE("Script Aggregator properly iterates when empty.") {
|
||||||
auto ran = 0;
|
auto ran = 0;
|
||||||
auto vec = ArbUt::List<ScriptWrapper>{};
|
auto vec = ArbUt::List<ScriptWrapper>{};
|
||||||
|
|
Loading…
Reference in New Issue