Add ConstString to several other places where context isn't changed much during runtime.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -38,6 +38,6 @@ const DamageLibrary* BattleLibrary::GetDamageLibrary() const { return _damageLib
|
||||
|
||||
const MiscLibrary* BattleLibrary::GetMiscLibrary() const { return _miscLibrary; }
|
||||
|
||||
Script* BattleLibrary::LoadScript(ScriptCategory category, const std::string& scriptName) const {
|
||||
Script* BattleLibrary::LoadScript(ScriptCategory category, const ConstString& scriptName) const {
|
||||
return _scriptResolver->LoadScript(category, scriptName);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace CreatureLib::Battling {
|
||||
[[nodiscard]] const MiscLibrary* GetMiscLibrary() const;
|
||||
[[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const { return _experienceLibrary; }
|
||||
|
||||
[[nodiscard]] Script* LoadScript(ScriptCategory category, const std::string& scriptName) const;
|
||||
[[nodiscard]] Script* LoadScript(ScriptCategory category, const ConstString& scriptName) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ void Battle::ValidateBattleState() {
|
||||
this->_battleResult = BattleResult::Conclusive(winningSide);
|
||||
this->_hasEnded = true;
|
||||
}
|
||||
void Battle::AddVolatileScript(const std::string& key) {
|
||||
void Battle::AddVolatileScript(const ConstString& key) {
|
||||
auto script = _volatile.Get(key);
|
||||
if (script != nullptr) {
|
||||
script->Stack();
|
||||
@@ -129,6 +129,6 @@ void Battle::AddVolatileScript(const std::string& key) {
|
||||
return _volatile.Add(script);
|
||||
}
|
||||
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
|
||||
void Battle::RemoveVolatileScript(const std::string& name) { _volatile.Remove(name); }
|
||||
void Battle::RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }
|
||||
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
|
||||
void Battle::HasVolatileScript(const std::string& name) const { _volatile.Has(name); }
|
||||
void Battle::HasVolatileScript(const ConstString& name) const { _volatile.Has(name); }
|
||||
|
||||
@@ -75,12 +75,12 @@ namespace CreatureLib::Battling {
|
||||
inline const BattleResult& GetResult() const { return _battleResult; }
|
||||
|
||||
const std::vector<BattleSide*>& GetSides() const { return _sides; }
|
||||
Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); }
|
||||
void AddVolatileScript(const std::string& key);
|
||||
Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); }
|
||||
void AddVolatileScript(const ConstString& key);
|
||||
void AddVolatileScript(Script* script);
|
||||
void RemoveVolatileScript(const std::string& name);
|
||||
void RemoveVolatileScript(const ConstString& name);
|
||||
void RemoveVolatileScript(Script* script);
|
||||
void HasVolatileScript(const std::string& name) const;
|
||||
void HasVolatileScript(const ConstString& name) const;
|
||||
|
||||
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
|
||||
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
|
||||
|
||||
@@ -25,7 +25,7 @@ void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||
RecalculateFlatStats();
|
||||
}
|
||||
|
||||
const std::string& Battling::Creature::GetActiveTalent() const {
|
||||
const ConstString& Battling::Creature::GetActiveTalent() const {
|
||||
if (_hasOverridenTalent) {
|
||||
return _overridenTalentName;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ void Battling::Creature::Heal(uint32_t amount) {
|
||||
_currentHealth = newHealth;
|
||||
}
|
||||
|
||||
void Battling::Creature::OverrideActiveTalent(const std::string& talent) {
|
||||
void Battling::Creature::OverrideActiveTalent(const ConstString& talent) {
|
||||
_hasOverridenTalent = true;
|
||||
_activeTalent->OnRemove();
|
||||
delete _activeTalent;
|
||||
@@ -183,7 +183,7 @@ void Battling::Creature::SetHeldItem(const Arbutils::CaseInsensitiveConstString&
|
||||
}
|
||||
_heldItem = item;
|
||||
}
|
||||
void Battling::Creature::AddVolatileScript(const std::string& name) {
|
||||
void Battling::Creature::AddVolatileScript(const ConstString& name) {
|
||||
auto script = _volatile.Get(name);
|
||||
if (script != nullptr) {
|
||||
script->Stack();
|
||||
@@ -194,6 +194,6 @@ void Battling::Creature::AddVolatileScript(const std::string& name) {
|
||||
}
|
||||
|
||||
void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
|
||||
void Battling::Creature::RemoveVolatileScript(const std::string& name) { _volatile.Remove(name); }
|
||||
void Battling::Creature::RemoveVolatileScript(const ConstString& name) { _volatile.Remove(name); }
|
||||
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
||||
void Battling::Creature::HasVolatileScript(const std::string& name) const { _volatile.Has(name); }
|
||||
void Battling::Creature::HasVolatileScript(const ConstString& name) const { _volatile.Has(name); }
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace CreatureLib::Battling {
|
||||
Script* _activeTalent = nullptr;
|
||||
|
||||
bool _hasOverridenTalent;
|
||||
std::string _overridenTalentName = "";
|
||||
ConstString _overridenTalentName = ""_cnc;
|
||||
std::unordered_set<Creature*> _seenOpponents = {};
|
||||
|
||||
std::vector<LearnedAttack*> _attacks;
|
||||
@@ -98,7 +98,7 @@ namespace CreatureLib::Battling {
|
||||
bool IsOnBattleField() const { return _onBattleField; }
|
||||
|
||||
const std::string& GetNickname() const { return _nickname; }
|
||||
const std::string& GetActiveTalent() const;
|
||||
const ConstString& GetActiveTalent() const;
|
||||
|
||||
[[nodiscard]] bool IsFainted() const;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
@@ -108,7 +108,7 @@ namespace CreatureLib::Battling {
|
||||
void ChangeLevel(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
void Heal(uint32_t amount);
|
||||
void OverrideActiveTalent(const std::string& talent);
|
||||
void OverrideActiveTalent(const ConstString& talent);
|
||||
void AddExperience(uint32_t amount);
|
||||
|
||||
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
||||
@@ -116,11 +116,11 @@ namespace CreatureLib::Battling {
|
||||
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
|
||||
void ClearVolatileScripts();
|
||||
void AddVolatileScript(const std::string& name);
|
||||
void AddVolatileScript(const ConstString& name);
|
||||
void AddVolatileScript(Script* script);
|
||||
void RemoveVolatileScript(const std::string& name);
|
||||
void RemoveVolatileScript(const ConstString& name);
|
||||
void RemoveVolatileScript(Script* script);
|
||||
void HasVolatileScript(const std::string& name) const;
|
||||
void HasVolatileScript(const ConstString& name) const;
|
||||
|
||||
std::vector<LearnedAttack*>& GetAttacks() { return _attacks; }
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
|
||||
virtual void Stack(){};
|
||||
virtual void OnRemove(){};
|
||||
|
||||
virtual const std::string& GetName() const = 0;
|
||||
virtual const ConstString& GetName() const = 0;
|
||||
|
||||
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace CreatureLib::Battling {
|
||||
virtual ~ScriptResolver() = default;
|
||||
|
||||
virtual void Initialize(BattleLibrary* library){};
|
||||
virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName) { return nullptr; };
|
||||
virtual Script* LoadScript(ScriptCategory category, const ConstString& scriptName) { return nullptr; };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSet {
|
||||
std::vector<Script*> _scripts;
|
||||
std::unordered_map<std::string, size_t> _lookup;
|
||||
std::unordered_map<ConstString, size_t> _lookup;
|
||||
|
||||
public:
|
||||
~ScriptSet() {
|
||||
@@ -28,7 +28,7 @@ namespace CreatureLib::Battling {
|
||||
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
||||
}
|
||||
|
||||
Script* Get(const std::string& key) const {
|
||||
Script* Get(const ConstString& key) const {
|
||||
auto f = _lookup.find(key);
|
||||
if (f != _lookup.end()) {
|
||||
return _scripts[f->second];
|
||||
@@ -36,7 +36,7 @@ namespace CreatureLib::Battling {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Remove(const std::string& key) {
|
||||
void Remove(const ConstString& key) {
|
||||
auto find = _lookup.find(key);
|
||||
if (find != _lookup.end()) {
|
||||
auto script = _scripts[find->second];
|
||||
@@ -55,7 +55,7 @@ namespace CreatureLib::Battling {
|
||||
_lookup.clear();
|
||||
}
|
||||
|
||||
bool Has(const std::string& key) const {
|
||||
bool Has(const ConstString& key) const {
|
||||
auto find = _lookup.find(key);
|
||||
return find != _lookup.end();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user