Initialize CreateCreature with ConstString instead of std::string.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-10 16:44:25 +02:00
parent e89d2a9e0c
commit 49e0f00237
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 71 additions and 56 deletions

View File

@ -23,8 +23,8 @@ namespace CreatureLib::Battling {
List<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
public:
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
: _library(library), _species(std::move(species)), _level(level) {}
CreateCreature(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
: _library(library), _species(species), _level(level) {}
CreateCreature* WithVariant(const Arbutils::CaseInsensitiveConstString& variant);
CreateCreature* WithNickname(std::string nickname);

View File

@ -11,10 +11,10 @@ using namespace CreatureLib::Battling;
TEST_CASE("Move creature choice up next.", "[Battling]") {
auto lib = TestLibrary::Get();
auto c1 = CreateCreature(lib, "testSpecies1", 1).Create();
auto c2 = CreateCreature(lib, "testSpecies1", 1).Create();
auto c3 = CreateCreature(lib, "testSpecies1", 1).Create();
auto c4 = CreateCreature(lib, "testSpecies1", 1).Create();
auto c1 = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto c2 = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto c3 = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto c4 = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
std::vector<BaseTurnChoice*> choices = {
new PassTurnChoice(c1),

View File

@ -10,7 +10,7 @@ using namespace CreatureLib::Battling;
TEST_CASE("Set Choice one-sized side", "[Battling]") {
auto side = BattleSide(0, nullptr, 1);
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c, 0);
auto choice = new PassTurnChoice(c);
side.SetChoice(choice);
@ -20,7 +20,7 @@ TEST_CASE("Set Choice one-sized side", "[Battling]") {
TEST_CASE("Set Choice one-sized side, validate all choices set", "[Battling]") {
auto side = BattleSide(0, nullptr, 1);
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c, 0);
auto choice = new PassTurnChoice(c);
REQUIRE_FALSE(side.AllChoicesSet());
@ -32,8 +32,8 @@ TEST_CASE("Set Choice one-sized side, validate all choices set", "[Battling]") {
TEST_CASE("Set Choice two-sized side", "[Battling]") {
auto side = BattleSide(0, nullptr, 2);
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c1, 0);
side.SetCreature(c2, 1);
auto choice1 = new PassTurnChoice(c1);
@ -48,8 +48,8 @@ TEST_CASE("Set Choice two-sized side", "[Battling]") {
TEST_CASE("Set Choice two-sized side, validate all choices set", "[Battling]") {
auto side = BattleSide(0, nullptr, 2);
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c1, 0);
side.SetCreature(c2, 1);
auto choice1 = new PassTurnChoice(c1);

View File

@ -13,8 +13,9 @@ using namespace Battling;
TEST_CASE("Create Party", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)});
REQUIRE(battleParty.GetParty()->GetAtIndex(0) == c1);
@ -22,12 +23,14 @@ TEST_CASE("Create Party", "[Integrations]") {
TEST_CASE("Create Battle", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -36,12 +39,14 @@ TEST_CASE("Create Battle", "[Integrations]") {
TEST_CASE("Use damaging move", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -58,12 +63,14 @@ TEST_CASE("Use damaging move", "[Integrations]") {
TEST_CASE("Finish battle when all battle of one side have fainted", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -93,12 +100,13 @@ TEST_CASE("Finish battle when all battle of one side have fainted", "[Integratio
TEST_CASE("When creature is dealt enough damage, faint it and mark battle as ended", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -122,14 +130,15 @@ TEST_CASE("When creature is dealt enough damage, faint it and mark battle as end
TEST_CASE("When another creature is available on faint, make sure the battle hasn't ended", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2, c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -160,14 +169,15 @@ TEST_CASE("When another creature is available on faint, make sure the battle has
TEST_CASE("Switch Creature in", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
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", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -186,14 +196,17 @@ TEST_CASE("Switch Creature in", "[Integrations]") {
TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
auto c2 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c3 = CreateCreature(library, "testSpecies1"_cnc, 50)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party2{c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -211,14 +224,15 @@ TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit ne
TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
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", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
@ -250,12 +264,13 @@ TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integratio
TEST_CASE("Flee Battle", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});

View File

@ -6,41 +6,41 @@
using namespace CreatureLib::Library;
TEST_CASE("Create basic creature", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
delete creature;
}
TEST_CASE("Get creature species", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1"_cnc);
delete creature;
}
TEST_CASE("Get creature level", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
REQUIRE(creature->GetLevel() == 1);
delete creature;
}
TEST_CASE("Get creature variant when unset", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
REQUIRE(creature->GetVariant()->GetName() == "default");
delete creature;
}
TEST_CASE("Get creature nickname when unset", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
REQUIRE(creature->GetNickname() == "testSpecies1");
delete creature;
}
TEST_CASE("Increase creature stat boost", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
creature->ChangeStatBoost(CreatureLib::Library::Statistic::PhysicalAttack, 6);
REQUIRE(creature->GetStatBoost(CreatureLib::Library::Statistic::PhysicalAttack) == 6);
delete creature;