Core/Common: Tokenizer -> Trinity::Tokenize

This commit is contained in:
Treeston authored and Ovahlord committed 2025-07-30 20:51:19 +02:00
1 parent 95329dc15c
commit f95a8bfdca
32 files changed
+414 -354

No files matched your search

+13 -12
View File
@@ -19,6 +19,7 @@
#include "Creature.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
#include "StringConvert.h"
CharmInfo::CharmInfo(Unit* unit)
: _unit(unit), _CommandState(COMMAND_FOLLOW), _petnumber(0), _oldReactState(REACT_PASSIVE),
@@ -236,29 +237,29 @@ void CharmInfo::LoadPetActionBar(const std::string& data)
{
InitPetActionBar();
Tokenizer tokens(data, ' ');
std::vector<std::string_view> tokens = Trinity::Tokenize(data, ' ', false);
if (tokens.size() != (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START) * 2)
return; // non critical, will reset to default
uint8 index = ACTION_BAR_INDEX_START;
Tokenizer::const_iterator iter = tokens.begin();
for (; index < ACTION_BAR_INDEX_END; ++iter, ++index)
auto iter = tokens.begin();
for (uint8 index = ACTION_BAR_INDEX_START; index < ACTION_BAR_INDEX_END; ++index)
{
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
ActiveStates type = ActiveStates(atol(*iter));
++iter;
uint32 action = atoul(*iter);
Optional<uint8> type = Trinity::StringTo<uint8>(*(iter++));
Optional<uint32> action = Trinity::StringTo<uint32>(*(iter++));
PetActionBar[index].SetActionAndType(action, type);
if (!type || !action)
continue;
PetActionBar[index].SetActionAndType(*action, static_cast<ActiveStates>(*type));
// check correctness
if (PetActionBar[index].IsActionBarForSpell())
{
SpellInfo const* spelInfo = sSpellMgr->GetSpellInfo(PetActionBar[index].GetAction());
if (!spelInfo)
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(PetActionBar[index].GetAction());
if (!spellInfo)
SetActionBar(index, 0, ACT_PASSIVE);
else if (!spelInfo->IsAutocastable())
else if (!spellInfo->IsAutocastable())
SetActionBar(index, PetActionBar[index].GetAction(), ACT_PASSIVE);
}
}