Make Attack name a ConstString.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-02 15:29:42 +01:00
parent 3bca3c0673
commit 81ae0e8454
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 15 additions and 14 deletions

View File

@ -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){};

View File

@ -1,7 +1,7 @@
#include "AttackData.hpp"
#include <utility>
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();
}

View File

@ -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<Arbutils::CaseInsensitiveConstString> _flags;
std::unordered_set<ConstString> _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<Arbutils::CaseInsensitiveConstString> 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<ConstString> 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;
};
}

View File

@ -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;
}