Remove event hook threads, as it caused issues when being called from dotnet.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-07 20:11:03 +02:00
parent 5b1c73a2af
commit 3d21b7c42d
5 changed files with 37 additions and 31 deletions

View File

@@ -13,7 +13,6 @@ TEST_CASE("Build and use event hook", "[Battling]") {
for (size_t i = 0; i < 10; i++) {
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
}
eventHook.FinishListening();
REQUIRE(events.size() == 10);
REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
}
@@ -25,7 +24,6 @@ TEST_CASE("Build and use event hook a lot", "[Battling]") {
for (size_t i = 0; i < 10000; i++) {
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
}
eventHook.FinishListening();
REQUIRE(events.size() == 10000);
}
@@ -41,6 +39,5 @@ TEST_CASE("Build and use event hook with different types", "[Battling]") {
eventHook.Trigger<FaintEvent>(nullptr);
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
eventHook.Trigger<FaintEvent>(nullptr);
eventHook.FinishListening();
}
#endif

View File

@@ -186,6 +186,37 @@ TEST_CASE("Switch Creature in", "[Integrations]") {
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c2);
}
TEST_CASE("Switch Creature in with event listener", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
.Create();
auto c2 =
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
CreatureParty party1{c1, c2};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
CreatureParty party2{c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
std::vector<const EventData*> events;
battle.RegisterEventListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c3);
REQUIRE(events.size() == 2);
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c1);
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
battle.TrySetChoice(new PassTurnChoice(c3));
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c2);
}
TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =