From 81ae0e8454d86a2226a95c885829cbdb5e1641f5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 2 Mar 2020 15:29:42 +0100 Subject: [PATCH] Make Attack name a ConstString. --- src/Battling/ScriptHandling/Script.hpp | 2 +- src/Library/Attacks/AttackData.cpp | 4 ++-- src/Library/Attacks/AttackData.hpp | 15 ++++++++------- tests/TestLibrary/TestLibrary.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Battling/ScriptHandling/Script.hpp b/src/Battling/ScriptHandling/Script.hpp index aad1dec..bac712a 100644 --- a/src/Battling/ScriptHandling/Script.hpp +++ b/src/Battling/ScriptHandling/Script.hpp @@ -26,7 +26,7 @@ namespace CreatureLib::Battling { virtual void OnBeforeTurn(const BaseTurnChoice* choice){}; - virtual void ChangeAttack(AttackTurnChoice* choice, std::string* outAttack){}; + virtual void ChangeAttack(AttackTurnChoice* choice, ConstString* outAttack){}; virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){}; virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){}; virtual void StopBeforeAttack(ExecutingAttack* attack, bool* outResult){}; diff --git a/src/Library/Attacks/AttackData.cpp b/src/Library/Attacks/AttackData.cpp index 0483814..f20bc22 100644 --- a/src/Library/Attacks/AttackData.cpp +++ b/src/Library/Attacks/AttackData.cpp @@ -1,7 +1,7 @@ #include "AttackData.hpp" #include -CreatureLib::Library::AttackData::AttackData(std::string name, uint8_t type, +CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t type, CreatureLib::Library::AttackCategory category, uint8_t power, uint8_t accuracy, uint8_t baseUsage, CreatureLib::Library::AttackTarget target, int8_t priority, @@ -9,6 +9,6 @@ CreatureLib::Library::AttackData::AttackData(std::string name, uint8_t type, : _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {} -bool CreatureLib::Library::AttackData::HasFlag(const Arbutils::CaseInsensitiveConstString& key) const { +bool CreatureLib::Library::AttackData::HasFlag(const ConstString& key) const { return this->_flags.find(key) != this->_flags.end(); } diff --git a/src/Library/Attacks/AttackData.hpp b/src/Library/Attacks/AttackData.hpp index b6fd44f..9e1c66c 100644 --- a/src/Library/Attacks/AttackData.hpp +++ b/src/Library/Attacks/AttackData.hpp @@ -7,10 +7,12 @@ #include "AttackCategory.hpp" #include "AttackTarget.hpp" +using ConstString = Arbutils::CaseInsensitiveConstString; + namespace CreatureLib::Library { class AttackData { protected: - const std::string _name; + const ConstString _name; uint8_t _type; AttackCategory _category; uint8_t _basePower; @@ -18,15 +20,14 @@ namespace CreatureLib::Library { uint8_t _baseUsages; AttackTarget _target; int8_t _priority; - std::unordered_set _flags; + std::unordered_set _flags; public: - AttackData(std::string name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy, - uint8_t baseUsage, AttackTarget target, int8_t priority, - std::unordered_set flags); + AttackData(const ConstString& name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy, + uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set flags); virtual ~AttackData() = default; - inline const std::string& GetName() const { return _name; } + inline const ConstString& GetName() const { return _name; } inline const uint8_t GetType() const { return _type; } inline AttackCategory GetCategory() const { return _category; } inline uint8_t GetBasePower() const { return _basePower; } @@ -35,7 +36,7 @@ namespace CreatureLib::Library { inline AttackTarget GetTarget() const { return _target; } inline int8_t GetPriority() const { return _priority; } - bool HasFlag(const Arbutils::CaseInsensitiveConstString& key) const; + bool HasFlag(const ConstString& key) const; }; } diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 8f939d1..67b04d4 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -33,13 +33,13 @@ SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { AttackLibrary* TestLibrary::BuildAttackLibrary() { auto l = new AttackLibrary(); - l->Insert("standard"_cnc, new AttackData("standard", 0, AttackCategory::Physical, 20, 100, 30, + l->Insert("standard"_cnc, new AttackData("standard"_cnc, 0, AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, 0, {})); - l->Insert("highPriority"_cnc, new AttackData("highPriority", 0, AttackCategory::Physical, 20, 100, 30, + l->Insert("highPriority"_cnc, new AttackData("highPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, 1, {})); - l->Insert("higherPriority"_cnc, new AttackData("higherPriority", 0, AttackCategory::Physical, 20, 100, 30, + l->Insert("higherPriority"_cnc, new AttackData("higherPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, 2, {})); - l->Insert("lowPriority"_cnc, new AttackData("lowPriority", 0, AttackCategory::Physical, 20, 100, 30, + l->Insert("lowPriority"_cnc, new AttackData("lowPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30, AttackTarget::AdjacentOpponent, -1, {})); return l; }