Change Creature::Nickname to be an optional.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-09-19 11:40:18 +02:00
parent 152ac7e407
commit ce30077a5d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 17 additions and 6 deletions

View File

@ -55,7 +55,13 @@ SIMPLE_GET_FUNC(Creature, GetCurrentHealth, uint32_t);
OPTIONAL_GET_FUNC(Creature, GetBattle, Battle*);
OPTIONAL_GET_FUNC(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().data(); }
export const char* CreatureLib_Creature_GetNickname(Creature* p) {
auto s = p->GetNickname();
if (s.has_value()) {
return p->GetNickname().value().data();
}
return "";
}
export void CreatureLib_Creature_SetNickname(Creature* p, const char* nickname) { p->SetNickname(nickname); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
export size_t CreatureLib_Creature_GetTypeCount(Creature* p) { return p->GetTypes().size(); }

View File

@ -11,7 +11,7 @@ namespace CreatureLib::Battling {
ArbUt::StringView _species;
ArbUt::StringView _variant = "default"_cnc;
uint8_t _level;
std::string _nickname = "";
std::optional<std::string> _nickname = "";
ArbUt::StringView _talent = ""_cnc;
Library::Gender _gender = static_cast<Library::Gender>(-1);

View File

@ -11,7 +11,7 @@ namespace CreatureLib::Battling {
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level,
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, std::string nickname,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, std::optional<std::string> nickname,
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain)
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),

View File

@ -48,7 +48,7 @@ namespace CreatureLib::Battling {
std::unordered_set<ArbUt::BorrowedPtr<Creature>> SeenOpponents;
} _battleData = {};
std::string _nickname = {};
std::optional<std::string> _nickname = {};
CreatureLib::Library::TalentIndex _talentIndex = {};
std::unique_ptr<BattleScript> _activeTalent = {};
@ -71,7 +71,7 @@ namespace CreatureLib::Battling {
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, level_int_t level,
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, std::string nickname,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, std::optional<std::string> nickname,
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain = true);
@ -117,7 +117,12 @@ namespace CreatureLib::Battling {
inline const CreatureIndex& GetBattleIndex() const noexcept { return _battleData.Index; }
inline bool IsOnBattleField() const { return _battleData.OnBattleField; }
inline std::string_view GetNickname() const noexcept { return _nickname; }
inline std::optional<std::string_view> GetNickname() const noexcept {
if (_nickname.has_value()) {
return _nickname.value();
}
return {};
}
inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; }
const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; }
const ArbUt::StringView& GetActiveTalent() const;