From 88971dce371f96f3578d9b2b0deaa1f5c3d2294d Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 10 Aug 2020 18:03:01 +0200 Subject: [PATCH] Support flags for species and formes. --- .clang-format | 1 + CInterface/Library/PokemonSpecies.cpp | 20 +++++++++++--------- src/Library/Species/PokemonForme.cpp | 7 +++++-- src/Library/Species/PokemonForme.hpp | 2 +- src/Library/Species/PokemonSpecies.hpp | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.clang-format b/.clang-format index bb1b6f3..623f0d8 100644 --- a/.clang-format +++ b/.clang-format @@ -129,6 +129,7 @@ Standard: c++20 StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION + - Try TabWidth: 8 UseCRLF: false UseTab: Never diff --git a/CInterface/Library/PokemonSpecies.cpp b/CInterface/Library/PokemonSpecies.cpp index 047f4da..dd991e1 100644 --- a/CInterface/Library/PokemonSpecies.cpp +++ b/CInterface/Library/PokemonSpecies.cpp @@ -5,15 +5,19 @@ using namespace PkmnLib::Library; export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name, const PokemonForme* defaultForme, float genderRatio, const char* growthRate, uint8_t captureRate, uint8_t baseHappiness, - const char* const* eggGroupsRaw, size_t eggGroupsLength) { + const char* const* eggGroupsRaw, size_t eggGroupsLength, + const char* flags[], size_t flagsCount) { Try( - ArbUt::List eggGroups(eggGroupsLength); - for (size_t i = 0; i < eggGroupsLength; i++) { eggGroups.Append(ArbUt::StringView(eggGroupsRaw[i])); } - auto cName = ArbUt::StringView(name); + std::unordered_set conversedFlags(flagsCount); for (size_t i = 0; i < flagsCount; i++) { + conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); + } ArbUt::List + eggGroups(eggGroupsLength); + for (size_t i = 0; i < eggGroupsLength; + i++) { eggGroups.Append(ArbUt::StringView(eggGroupsRaw[i])); } auto cName = ArbUt::StringView(name); auto cGrowthRate = ArbUt::StringView(growthRate); out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness, - eggGroups);) + eggGroups, conversedFlags);) } export void PkmnLib_PokemonSpecies_Destruct(const PokemonSpecies* p) { delete p; } @@ -31,9 +35,7 @@ export uint8_t PkmnLib_PokemonSpecies_GetEvolutions(const PokemonSpecies* p, con Try(out = p->GetEvolutions().RawData()); } -export size_t PkmnLib_PokemonSpecies_GetEggGroupCount(const PokemonSpecies* p) { - return p->GetEggGroups().Count(); -} -export const char* PkmnLib_PokemonSpecies_GetEggGroup(const PokemonSpecies* p, size_t index){ +export size_t PkmnLib_PokemonSpecies_GetEggGroupCount(const PokemonSpecies* p) { return p->GetEggGroups().Count(); } +export const char* PkmnLib_PokemonSpecies_GetEggGroup(const PokemonSpecies* p, size_t index) { return p->GetEggGroups()[index].c_str(); } \ No newline at end of file diff --git a/src/Library/Species/PokemonForme.cpp b/src/Library/Species/PokemonForme.cpp index 513d666..5847e14 100644 --- a/src/Library/Species/PokemonForme.cpp +++ b/src/Library/Species/PokemonForme.cpp @@ -1,8 +1,11 @@ #include "PokemonForme.hpp" + +#include PkmnLib::Library::PokemonForme::PokemonForme(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, const ArbUt::List& types, CreatureLib::Library::StatisticSet baseStats, const ArbUt::List& talents, const ArbUt::List& secretTalents, - const CreatureLib::Library::LearnableAttacks* attacks) - : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {} + const CreatureLib::Library::LearnableAttacks* attacks, + std::unordered_set flags) + : SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks, std::move(flags)) {} diff --git a/src/Library/Species/PokemonForme.hpp b/src/Library/Species/PokemonForme.hpp index 8ebdf3c..5e5138e 100644 --- a/src/Library/Species/PokemonForme.hpp +++ b/src/Library/Species/PokemonForme.hpp @@ -10,7 +10,7 @@ namespace PkmnLib::Library { PokemonForme(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, const ArbUt::List& types, CreatureLib::Library::StatisticSet baseStats, const ArbUt::List& talents, const ArbUt::List& secretTalents, - const CreatureLib::Library::LearnableAttacks* attacks); + const CreatureLib::Library::LearnableAttacks* attacks, std::unordered_set flags = {}); private: public: diff --git a/src/Library/Species/PokemonSpecies.hpp b/src/Library/Species/PokemonSpecies.hpp index 479901f..48fb151 100644 --- a/src/Library/Species/PokemonSpecies.hpp +++ b/src/Library/Species/PokemonSpecies.hpp @@ -15,8 +15,8 @@ namespace PkmnLib::Library { public: PokemonSpecies(uint16_t id, const ArbUt::StringView& name, const PokemonForme* defaultForme, float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate, uint8_t baseHappiness, - const ArbUt::List& eggGroups) noexcept - : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate), + const ArbUt::List& eggGroups, std::unordered_set flags = {}) noexcept + : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate, flags), _baseHappiness(baseHappiness), _eggGroups(eggGroups) {} ~PokemonSpecies() override = default;