diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 4aff838..2ffc7d9 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -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(); } diff --git a/src/Battling/Models/CreateCreature.hpp b/src/Battling/Models/CreateCreature.hpp index 919362f..fbf5803 100644 --- a/src/Battling/Models/CreateCreature.hpp +++ b/src/Battling/Models/CreateCreature.hpp @@ -11,7 +11,7 @@ namespace CreatureLib::Battling { ArbUt::StringView _species; ArbUt::StringView _variant = "default"_cnc; uint8_t _level; - std::string _nickname = ""; + std::optional _nickname = ""; ArbUt::StringView _talent = ""_cnc; Library::Gender _gender = static_cast(-1); diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 733b76f..96cb839 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -11,7 +11,7 @@ namespace CreatureLib::Battling { const ArbUt::BorrowedPtr& species, const ArbUt::BorrowedPtr& variant, level_int_t level, uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring, - ArbUt::OptionalBorrowedPtr heldItem, std::string nickname, + ArbUt::OptionalBorrowedPtr heldItem, std::optional nickname, const Library::TalentIndex& talent, const std::vector& attacks, bool allowedExperienceGain) : _library(library), _species(species), _variant(variant), _level(level), _experience(experience), diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 1479fb7..9bf5d6f 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -48,7 +48,7 @@ namespace CreatureLib::Battling { std::unordered_set> SeenOpponents; } _battleData = {}; - std::string _nickname = {}; + std::optional _nickname = {}; CreatureLib::Library::TalentIndex _talentIndex = {}; std::unique_ptr _activeTalent = {}; @@ -71,7 +71,7 @@ namespace CreatureLib::Battling { const ArbUt::BorrowedPtr& species, const ArbUt::BorrowedPtr& variant, level_int_t level, uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring, - ArbUt::OptionalBorrowedPtr heldItem, std::string nickname, + ArbUt::OptionalBorrowedPtr heldItem, std::optional nickname, const Library::TalentIndex& talent, const std::vector& 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 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;