Skip to content

Commit

Permalink
feat: "scale" keyvalue for prop and transform components now accepts …
Browse files Browse the repository at this point in the history
…vector values
  • Loading branch information
Silverlan committed Mar 13, 2023
1 parent 048f8a4 commit 755e0cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/shared/include/pragma/entities/prop/prop_base.h
Expand Up @@ -27,7 +27,7 @@ namespace pragma {
virtual void OnEntitySpawn() override;
protected:
void InitializePhysics();
float m_kvScale;
Vector3 m_kvScale {1.f, 1.f, 1.f};
float m_kvMass = std::numeric_limits<float>::quiet_NaN();
BasePropComponent(BaseEntity &ent);
bool SetKeyValue(std::string key, std::string val);
Expand Down
Expand Up @@ -96,6 +96,15 @@ void BaseTransformComponent::Initialize()
ustring::string_to_array<float, double>(kvData.value, &ang.p, atof, 3);
SetAngles(ang);
}
else if(ustring::compare<std::string>(kvData.key, "scale", false)) {
Vector3 scale {1.f, 1.f, 1.f};
auto n = ustring::string_to_array<float, double>(kvData.value, &scale.x, atof, 3);
if(n == 1) {
scale.y = scale.x;
scale.z = scale.x;
}
SetScale(scale);
}
else
return util::EventReply::Unhandled;
return util::EventReply::Handled;
Expand Down
15 changes: 11 additions & 4 deletions core/shared/src/entities/prop/prop_base.cpp
Expand Up @@ -19,7 +19,7 @@

using namespace pragma;

BasePropComponent::BasePropComponent(BaseEntity &ent) : BaseEntityComponent(ent), m_kvScale(1.f) {}
BasePropComponent::BasePropComponent(BaseEntity &ent) : BaseEntityComponent(ent) {}

PHYSICSTYPE BasePropComponent::UpdatePhysicsType(BaseEntity *ent)
{
Expand All @@ -40,8 +40,15 @@ PHYSICSTYPE BasePropComponent::UpdatePhysicsType(BaseEntity *ent)

bool BasePropComponent::SetKeyValue(std::string key, std::string val)
{
if(key == "scale")
m_kvScale = ustring::to_float(val);
if(key == "scale") {
Vector3 scale {1.f, 1.f, 1.f};
auto n = ustring::string_to_array<float, double>(val, &scale.x, atof, 3);
if(n == 1) {
scale.y = scale.x;
scale.z = scale.x;
}
m_kvScale = scale;
}
else if(key == "mass") {
ustring::remove_whitespace(val);
if(val.empty() == false)
Expand Down Expand Up @@ -125,7 +132,7 @@ void BasePropComponent::OnEntitySpawn()
BaseEntityComponent::OnEntitySpawn();
auto &ent = GetEntity();
auto mdlComponent = ent.GetModelComponent();
if(m_kvScale != 1.f) {
if(m_kvScale != Vector3 {1.f, 1.f, 1.f}) {
auto pTrComponent = ent.GetTransformComponent();
if(pTrComponent != nullptr)
pTrComponent->SetScale(m_kvScale);
Expand Down

0 comments on commit 755e0cd

Please sign in to comment.