Return optional pointer instead of raw pointers in Pokemon::GetMoves
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-04-23 11:53:00 +02:00
parent 939cf4e328
commit 1c66aa8696
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 4 additions and 4 deletions

View File

@ -42,8 +42,8 @@ namespace PkmnLib::Battling {
inline bool IsShiny() const noexcept { return _coloring == 1; } inline bool IsShiny() const noexcept { return _coloring == 1; }
const ArbUt::List<LearnedMove*>& GetMoves() const { const ArbUt::List<ArbUt::OptionalBorrowedPtr<LearnedMove>>& GetMoves() const {
return reinterpret_cast<const ArbUt::List<LearnedMove*>&>(_attacks); return reinterpret_cast<const ArbUt::List<ArbUt::OptionalBorrowedPtr<LearnedMove>>&>(_attacks);
} }
inline const ArbUt::BorrowedPtr<const PkmnLib::Library::Nature>& GetNature() const noexcept { return _nature; } inline const ArbUt::BorrowedPtr<const PkmnLib::Library::Nature>& GetNature() const noexcept { return _nature; }

View File

@ -28,9 +28,9 @@ TEST_CASE("Get Attack name from Pokemon") {
.LearnMove("testMove"_cnc, CreatureLib::Battling::AttackLearnMethod::Level) .LearnMove("testMove"_cnc, CreatureLib::Battling::AttackLearnMethod::Level)
.LearnMove("testMove2"_cnc, CreatureLib::Battling::AttackLearnMethod::Level) .LearnMove("testMove2"_cnc, CreatureLib::Battling::AttackLearnMethod::Level)
.Build(); .Build();
auto move = mon->GetMoves()[0]; auto move = mon->GetMoves()[0].GetValue();
REQUIRE(move->GetMoveData()->GetName() == "testMove"_cnc); REQUIRE(move->GetMoveData()->GetName() == "testMove"_cnc);
auto move2 = mon->GetMoves()[1]; auto move2 = mon->GetMoves()[1].GetValue();
REQUIRE(move2->GetMoveData()->GetName() == "testMove2"_cnc); REQUIRE(move2->GetMoveData()->GetName() == "testMove2"_cnc);
delete mon; delete mon;
} }