Support not only StringRefId for checking first person body part

depth-refraction
elsid 2 years ago
parent e6cf516e12
commit 04d7781424
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -425,11 +425,6 @@ namespace CSMWorld
return index;
}
bool ActorAdapter::is1stPersonPart(const std::string& name) const
{
return name.size() >= 4 && name.find(".1st", name.size() - 4) != std::string::npos;
}
ActorAdapter::RaceDataPtr ActorAdapter::getRaceData(const ESM::RefId& id)
{
// Return cached race data if it exists
@ -519,8 +514,7 @@ namespace CSMWorld
}
auto& part = partRecord.get();
if (part.mRace == id && part.mData.mType == ESM::BodyPart::MT_Skin
&& !is1stPersonPart(part.mId.getRefIdString()))
if (part.mRace == id && part.mData.mType == ESM::BodyPart::MT_Skin && !ESM::isFirstPersonBodyPart(part))
{
auto type = (ESM::BodyPart::MeshPart)part.mData.mPart;
bool female = part.mData.mFlags & ESM::BodyPart::BPF_Female;

@ -149,7 +149,6 @@ namespace CSMWorld
ActorAdapter& operator=(const ActorAdapter&) = delete;
QModelIndex getHighestIndex(QModelIndex) const;
bool is1stPersonPart(const std::string& id) const;
RaceDataPtr getRaceData(const ESM::RefId& raceId);

@ -321,7 +321,6 @@ namespace MWGui
for (const ESM::BodyPart& bodypart : store)
{
const std::string& idString = bodypart.mId.getRefIdString();
if (bodypart.mData.mFlags & ESM::BodyPart::BPF_NotPlayable)
continue;
if (bodypart.mData.mType != ESM::BodyPart::MT_Skin)
@ -330,8 +329,7 @@ namespace MWGui
continue;
if (mGenderIndex != (bodypart.mData.mFlags & ESM::BodyPart::BPF_Female))
continue;
bool firstPerson = Misc::StringUtils::ciEndsWith(idString, "1st");
if (firstPerson)
if (ESM::isFirstPersonBodyPart(bodypart))
continue;
if (bodypart.mRace == mCurrentRaceId)
out.push_back(bodypart.mId);

@ -85,7 +85,6 @@ namespace
namespace MWRender
{
class HeadAnimationTime : public SceneUtil::ControllerSource
{
private:
@ -761,12 +760,6 @@ namespace MWRender
}
}
bool NpcAnimation::isFirstPersonPart(const ESM::BodyPart* bodypart)
{
std::string_view partName = bodypart->mId.getRefIdString();
return partName.size() >= 3 && partName.substr(partName.size() - 3, 3) == "1st";
}
bool NpcAnimation::isFemalePart(const ESM::BodyPart* bodypart)
{
return bodypart->mData.mFlags & ESM::BodyPart::BPF_Female;
@ -1220,7 +1213,7 @@ namespace MWRender
if (!(bodypart.mRace == race))
continue;
bool partFirstPerson = isFirstPersonPart(&bodypart);
const bool partFirstPerson = ESM::isFirstPersonBodyPart(bodypart);
bool isHand = bodypart.mData.mPart == ESM::BodyPart::MP_Hand
|| bodypart.mData.mPart == ESM::BodyPart::MP_Wrist
@ -1277,7 +1270,7 @@ namespace MWRender
parts[bIt->second] = &bodypart;
// If we have 3d person fallback bodypart for hand and 1st person fallback found (2)
else if (isHand && !isFirstPersonPart(parts[bIt->second]) && partFirstPerson)
else if (isHand && !ESM::isFirstPersonBodyPart(*parts[bIt->second]) && partFirstPerson)
parts[bIt->second] = &bodypart;
++bIt;

@ -99,7 +99,6 @@ namespace MWRender
osg::ref_ptr<RotateController> mFirstPersonNeckController;
static bool isFirstPersonPart(const ESM::BodyPart* bodypart);
static bool isFemalePart(const ESM::BodyPart* bodypart);
static NpcType getNpcType(const MWWorld::Ptr& ptr);

@ -77,6 +77,19 @@ namespace ESM
}
};
struct EndsWith
{
const std::string_view mSuffix;
bool operator()(StringRefId v) const { return v.endsWith(mSuffix); }
template <class T>
bool operator()(const T& /*v*/) const
{
return false;
}
};
struct Contains
{
const std::string_view mSubString;
@ -155,6 +168,11 @@ namespace ESM
return std::visit(StartsWith{ prefix }, mValue);
}
bool RefId::endsWith(std::string_view suffix) const
{
return std::visit(EndsWith{ suffix }, mValue);
}
bool RefId::contains(std::string_view subString) const
{
return std::visit(Contains{ subString }, mValue);

@ -104,6 +104,10 @@ namespace ESM
// Otherwise returns false.
bool startsWith(std::string_view prefix) const;
// Returns true if underlying value is StringRefId and its underlying std::string ends with given suffix.
// Otherwise returns false.
bool endsWith(std::string_view suffix) const;
// Returns true if underlying value is StringRefId and its underlying std::string contains given subString.
// Otherwise returns false.
bool contains(std::string_view subString) const;

@ -81,6 +81,11 @@ namespace ESM
return Misc::StringUtils::ciStartsWith(*mValue, prefix);
}
bool StringRefId::endsWith(std::string_view suffix) const
{
return Misc::StringUtils::ciEndsWith(*mValue, suffix);
}
bool StringRefId::contains(std::string_view subString) const
{
return Misc::StringUtils::ciFind(*mValue, subString) != std::string_view::npos;

@ -27,6 +27,8 @@ namespace ESM
bool startsWith(std::string_view prefix) const;
bool endsWith(std::string_view suffix) const;
bool contains(std::string_view subString) const;
bool operator==(StringRefId rhs) const noexcept { return mValue == rhs.mValue; }

@ -73,4 +73,9 @@ namespace ESM
mModel.clear();
mRace = ESM::RefId();
}
bool isFirstPersonBodyPart(const BodyPart& value)
{
return value.mId.endsWith("1st");
}
}

@ -72,5 +72,7 @@ namespace ESM
void blank();
///< Set record to default state (does not touch the ID).
};
bool isFirstPersonBodyPart(const BodyPart& value);
}
#endif

Loading…
Cancel
Save