From 27e0f6bd713285c0b2aa0e358a17fe84bbbfbfdf Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 29 Apr 2024 06:18:58 +1000 Subject: [PATCH] fix: scale not applying to NPCs properly and applying post-rotation --- source/game/StarHumanoid.cpp | 15 ++++++++++++--- source/game/StarHumanoid.hpp | 4 +++- source/game/StarNpc.cpp | 1 + source/game/StarPlayer.cpp | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/game/StarHumanoid.cpp b/source/game/StarHumanoid.cpp index a18dd3f..0b33ba4 100644 --- a/source/game/StarHumanoid.cpp +++ b/source/game/StarHumanoid.cpp @@ -299,6 +299,7 @@ Humanoid::Humanoid(Json const& config) { m_altHand.angle = 0; m_facingDirection = Direction::Left; m_rotation = 0; + m_scale = Vec2F::filled(1.f); m_drawVaporTrail = false; m_state = State::Idle; m_emoteState = HumanoidEmote::Idle; @@ -409,6 +410,10 @@ void Humanoid::setRotation(float rotation) { m_rotation = rotation; } +void Humanoid::setScale(Vec2F scale) { + m_scale = scale; +} + void Humanoid::setVaporTrail(bool enabled) { m_drawVaporTrail = enabled; } @@ -499,7 +504,7 @@ void Humanoid::resetAnimation() { m_danceTimer = 0.0f; } -List Humanoid::render(bool withItems, bool withRotation) { +List Humanoid::render(bool withItems, bool withRotationAndScale) { List drawables; int armStateSeq = getArmStateSequence(); @@ -794,8 +799,12 @@ List Humanoid::render(bool withItems, bool withRotation) { for (auto& drawable : drawables) { drawable.translate(m_globalOffset); - if (withRotation && m_rotation != 0) - drawable.rotate(m_rotation); + if (withRotationAndScale) { + if (m_scale.x() != 1.f || m_scale.y() != 1.f) + drawable.scale(m_scale); + if (m_rotation != 0.f) + drawable.rotate(m_rotation); + } drawable.rebase(); } return drawables; diff --git a/source/game/StarHumanoid.hpp b/source/game/StarHumanoid.hpp index 3f8296b..283f7e9 100644 --- a/source/game/StarHumanoid.hpp +++ b/source/game/StarHumanoid.hpp @@ -162,6 +162,7 @@ public: void setFacingDirection(Direction facingDirection); void setMovingBackwards(bool movingBackwards); void setRotation(float rotation); + void setScale(Vec2F scale); void setVaporTrail(bool enabled); @@ -197,7 +198,7 @@ public: // Renders to centered drawables (centered on the normal image center for the // player graphics), (in world space, not pixels) - List render(bool withItems = true, bool withRotation = true); + List render(bool withItems = true, bool withRotationAndScale = true); // Renders to centered drawables (centered on the normal image center for the // player graphics), (in pixels, not world space) @@ -353,6 +354,7 @@ private: Direction m_facingDirection; bool m_movingBackwards; float m_rotation; + Vec2F m_scale; bool m_drawVaporTrail; HandDrawingInfo m_primaryHand; diff --git a/source/game/StarNpc.cpp b/source/game/StarNpc.cpp index d45f416..c68fd08 100644 --- a/source/game/StarNpc.cpp +++ b/source/game/StarNpc.cpp @@ -483,6 +483,7 @@ void Npc::render(RenderCallback* renderCallback) { scale = scale.piecewiseMultiply(result.first); humanoidDirectives.append(result.second); } + m_humanoid.setScale(scale); for (auto& drawable : m_humanoid.render()) { drawable.translate(position()); diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index 07196b6..8b15254 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -386,9 +386,9 @@ List Player::drawables() const { }; extractScale(m_techController->parentDirectives().list()); extractScale(m_statusController->parentDirectives().list()); + m_humanoid->setScale(scale); for (auto& drawable : m_humanoid->render()) { - drawable.scale(scale); drawable.translate(position() + m_techController->parentOffset()); if (drawable.isImage()) { drawable.imagePart().addDirectivesGroup(humanoidDirectives, true);