From d5d474c673ff15cdefb1ce057b072688dd639acf Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 26 Jun 2023 16:09:40 +1000 Subject: [PATCH] Fix particles finally --- source/game/StarAnimation.cpp | 4 ++-- source/game/StarAnimation.hpp | 4 ++-- source/game/StarParticle.cpp | 16 +++++++++------- source/game/StarParticle.hpp | 2 +- source/game/StarPlant.cpp | 4 +++- source/game/StarPlantDrop.cpp | 4 ++-- source/game/StarPlantDrop.hpp | 3 ++- source/game/StarWorldClient.cpp | 6 +++--- source/rendering/StarWorldPainter.cpp | 2 +- 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/source/game/StarAnimation.cpp b/source/game/StarAnimation.cpp index 7f3847c..8a1e9c1 100644 --- a/source/game/StarAnimation.cpp +++ b/source/game/StarAnimation.cpp @@ -43,7 +43,7 @@ void Animation::setAngle(float angle) { m_angle = angle; } -void Animation::setProcessing(Directives processing) { +void Animation::setProcessing(DirectivesGroup processing) { m_processing = move(processing); } @@ -70,7 +70,7 @@ Drawable Animation::drawable(float pixelSize) const { baseFrame += ":" + toString(m_frame); Drawable drawable = Drawable::makeImage(move(baseFrame), pixelSize, m_centered, m_offset); - drawable.imagePart().addDirectives(m_processing); + drawable.imagePart().addDirectivesGroup(m_processing); drawable.rotate(m_angle); drawable.color = m_color; return drawable; diff --git a/source/game/StarAnimation.hpp b/source/game/StarAnimation.hpp index e4a2ece..9fbe812 100644 --- a/source/game/StarAnimation.hpp +++ b/source/game/StarAnimation.hpp @@ -15,7 +15,7 @@ public: void setAngle(float angle); - void setProcessing(Directives processing); + void setProcessing(DirectivesGroup processing); void setColor(Color color); @@ -43,7 +43,7 @@ private: float m_angle; Vec2F m_offset; bool m_centered; - Directives m_processing; + DirectivesGroup m_processing; Color m_color; int m_variantOffset; diff --git a/source/game/StarParticle.cpp b/source/game/StarParticle.cpp index 82c63c6..7b2240b 100644 --- a/source/game/StarParticle.cpp +++ b/source/game/StarParticle.cpp @@ -66,14 +66,16 @@ Particle::Particle(Json const& config, String const& path) { if (type == Type::Textured || type == Type::Animated) string = AssetPath::relativeTo(path, string); - if (type == Type::Animated) - initializeAnimation(); + image = string; - auto pathEnd = string.find('?'); - if (pathEnd == NPos) - directives = ""; - else - directives.parse(string.substr(pathEnd)); + if (type == Type::Animated) { + auto pathEnd = string.find('?'); + if (pathEnd == NPos) + directives.clear(); + else + directives = string.substr(pathEnd); + initializeAnimation(); + } if (config.contains("color")) color = jsonToColor(config.get("color")); diff --git a/source/game/StarParticle.hpp b/source/game/StarParticle.hpp index a0945ac..c0477e7 100644 --- a/source/game/StarParticle.hpp +++ b/source/game/StarParticle.hpp @@ -77,7 +77,7 @@ struct Particle { // Used differently depending on the type of the particle. String string; AssetPath image; - Directives directives; + DirectivesGroup directives; Color color; Color light; diff --git a/source/game/StarPlant.cpp b/source/game/StarPlant.cpp index b71643a..f6a366b 100644 --- a/source/game/StarPlant.cpp +++ b/source/game/StarPlant.cpp @@ -773,8 +773,10 @@ void Plant::render(RenderCallback* renderCallback) { continue; auto particle = Root::singleton().particleDatabase()->particle(config); particle.color.hueShift(hueshift); - if (!particle.string.empty()) + if (!particle.string.empty()) { particle.string = strf("%s?hueshift=%s", particle.string, hueshift); + particle.image = particle.string; + } particle.position = {m_tileDamageX + Random::randf(), m_tileDamageY + Random::randf()}; particle.translate(position()); renderCallback->addParticle(move(particle)); diff --git a/source/game/StarPlantDrop.cpp b/source/game/StarPlantDrop.cpp index ab351ba..1fc085f 100644 --- a/source/game/StarPlantDrop.cpp +++ b/source/game/StarPlantDrop.cpp @@ -279,8 +279,8 @@ void PlantDrop::particleForPlantPart(PlantDropPiece const& piece, String const& particle = Root::singleton().particleDatabase()->particle(config); particle.color.hueShift(mainConfig.getFloat("hueshift", 0) / 360.0f); - if (!particle.string.empty()) - particle.string += AssetPath::getDirectives(piece.image); + for (Directives const& directives : piece.image.directives.list()) + particle.directives.append(directives); density--; diff --git a/source/game/StarPlantDrop.hpp b/source/game/StarPlantDrop.hpp index 0eff7a2..a11b732 100644 --- a/source/game/StarPlantDrop.hpp +++ b/source/game/StarPlantDrop.hpp @@ -4,6 +4,7 @@ #include "StarNetElementSystem.hpp" #include "StarMovementController.hpp" #include "StarPlant.hpp" +#include "StarAssetPath.hpp" namespace Star { @@ -50,7 +51,7 @@ public: private: struct PlantDropPiece { PlantDropPiece(); - String image; + AssetPath image; Vec2F offset; int segmentIdx; Plant::PlantPieceKind kind; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 269bbca..6fa7709 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -401,7 +401,7 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) { if (directives) { int directiveIndex = unsigned(entity->entityId()) % directives->size(); for (auto& p : renderCallback.particles) - p.directives = directives->get(directiveIndex); + p.directives.append(directives->get(directiveIndex)); } m_particles->addParticles(move(renderCallback.particles)); @@ -1273,7 +1273,7 @@ void WorldClient::handleDamageNotifications() { if (directives) { int directiveIndex = unsigned(damageNotification.targetEntityId) % directives->size(); for (auto& p : hitParticles) - p.directives = directives->get(directiveIndex); + p.directives.append(directives->get(directiveIndex)); } m_particles->addParticles(hitParticles); @@ -1343,7 +1343,7 @@ void WorldClient::removeEntity(EntityId entityId, bool andDie) { if (directives) { int directiveIndex = unsigned(entity->entityId()) % directives->size(); for (auto& p : renderCallback.particles) - p.directives = directives->get(directiveIndex); + p.directives.append(directives->get(directiveIndex)); } m_particles->addParticles(move(renderCallback.particles)); diff --git a/source/rendering/StarWorldPainter.cpp b/source/rendering/StarWorldPainter.cpp index ea63abe..fb0641d 100644 --- a/source/rendering/StarWorldPainter.cpp +++ b/source/rendering/StarWorldPainter.cpp @@ -189,7 +189,7 @@ void WorldPainter::renderParticles(WorldRenderData& renderData, Particle::Layer if (particle.flip && particle.flippable) drawable.scale(Vec2F(-1, 1)); if (drawable.isImage()) - drawable.imagePart().addDirectives(particle.directives, true); + drawable.imagePart().addDirectivesGroup(particle.directives, true); drawable.fullbright = particle.fullbright; drawable.color = particle.color; drawable.rotate(particle.rotation);