1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

Rewrite handleTextKey using substring views

This commit is contained in:
Alexei Kotov 2022-06-13 12:28:12 +03:00
parent 9e6b7fed1a
commit ab46337c41

View File

@ -886,7 +886,7 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T
{ {
std::string_view evt = key->second; std::string_view evt = key->second;
if(evt.compare(0, 7, "sound: ") == 0) if (evt.substr(0, 7) == "sound: ")
{ {
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f); sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f);
@ -894,7 +894,7 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T
} }
auto& charClass = mPtr.getClass(); auto& charClass = mPtr.getClass();
if(evt.compare(0, 10, "soundgen: ") == 0) if (evt.substr(0, 10) == "soundgen: ")
{ {
std::string soundgen = std::string(evt.substr(10)); std::string soundgen = std::string(evt.substr(10));
@ -936,30 +936,34 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T
return; return;
} }
if(evt.compare(0, groupname.size(), groupname) != 0 || if (evt.substr(0, groupname.size()) != groupname || evt.substr(groupname.size(), 2) != ": ")
evt.compare(groupname.size(), 2, ": ") != 0)
{ {
// Not ours, skip it // Not ours, skip it
return; return;
} }
const size_t off = groupname.size()+2;
const size_t len = evt.size() - off;
if(groupname == "shield" && evt.compare(off, len, "equip attach") == 0) std::string_view action = evt.substr(groupname.size() + 2);
mAnimation->showCarriedLeft(true); if (action == "equip attach")
else if(groupname == "shield" && evt.compare(off, len, "unequip detach") == 0) {
mAnimation->showCarriedLeft(false); if (groupname == "shield")
else if(evt.compare(off, len, "equip attach") == 0) mAnimation->showCarriedLeft(true);
mAnimation->showWeapons(true); else
else if(evt.compare(off, len, "unequip detach") == 0) mAnimation->showWeapons(true);
mAnimation->showWeapons(false); }
else if(evt.compare(off, len, "chop hit") == 0) else if (action == "unequip detach")
{
if (groupname == "shield")
mAnimation->showCarriedLeft(false);
else
mAnimation->showWeapons(false);
}
else if (action == "chop hit")
charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Chop); charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Chop);
else if(evt.compare(off, len, "slash hit") == 0) else if (action == "slash hit")
charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Slash); charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Slash);
else if(evt.compare(off, len, "thrust hit") == 0) else if (action == "thrust hit")
charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Thrust); charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Thrust);
else if(evt.compare(off, len, "hit") == 0) else if (action == "hit")
{ {
if (groupname == "attack1" || groupname == "swimattack1") if (groupname == "attack1" || groupname == "swimattack1")
charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Chop); charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Chop);
@ -970,9 +974,7 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T
else else
charClass.hit(mPtr, mAttackStrength); charClass.hit(mPtr, mAttackStrength);
} }
else if (!groupname.empty() else if (isRandomAttackAnimation(groupname) && action == "start")
&& (groupname.compare(0, groupname.size()-1, "attack") == 0 || groupname.compare(0, groupname.size()-1, "swimattack") == 0)
&& evt.compare(off, len, "start") == 0)
{ {
std::multimap<float, std::string>::const_iterator hitKey = key; std::multimap<float, std::string>::const_iterator hitKey = key;
@ -1001,25 +1003,22 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T
charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Thrust); charClass.hit(mPtr, mAttackStrength, ESM::Weapon::AT_Thrust);
} }
} }
else if (evt.compare(off, len, "shoot attach") == 0) else if (action == "shoot attach")
mAnimation->attachArrow(); mAnimation->attachArrow();
else if (evt.compare(off, len, "shoot release") == 0) else if (action == "shoot release")
mAnimation->releaseArrow(mAttackStrength); mAnimation->releaseArrow(mAttackStrength);
else if (evt.compare(off, len, "shoot follow attach") == 0) else if (action == "shoot follow attach")
mAnimation->attachArrow(); mAnimation->attachArrow();
// Make sure this key is actually for the RangeType we are casting. The flame atronach has
else if (groupname == "spellcast" && evt.substr(evt.size()-7, 7) == "release" // the same animation for all range types, so there are 3 "release" keys on the same time, one for each range type.
// Make sure this key is actually for the RangeType we are casting. The flame atronach has else if (groupname == "spellcast" && action == mAttackType + " release")
// the same animation for all range types, so there are 3 "release" keys on the same time, one for each range type.
&& evt.compare(off, len, mAttackType + " release") == 0)
{ {
MWBase::Environment::get().getWorld()->castSpell(mPtr, mCastingManualSpell); MWBase::Environment::get().getWorld()->castSpell(mPtr, mCastingManualSpell);
mCastingManualSpell = false; mCastingManualSpell = false;
} }
else if (groupname == "shield" && action == "block hit")
else if (groupname == "shield" && evt.compare(off, len, "block hit") == 0)
charClass.block(mPtr); charClass.block(mPtr);
else if (groupname == "containeropen" && evt.compare(off, len, "loot") == 0) else if (groupname == "containeropen" && action == "loot")
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container, mPtr); MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container, mPtr);
} }