Skip to content

Commit

Permalink
Update Particle Emitter to use a single string as color and add prope…
Browse files Browse the repository at this point in the history
…rties for the object panel
  • Loading branch information
4ian committed Sep 8, 2024
1 parent 693f500 commit c68f113
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 272 deletions.
430 changes: 384 additions & 46 deletions Extensions/ParticleSystem/ParticleEmitterObject.cpp

Large diffs are not rendered by default.

43 changes: 20 additions & 23 deletions Extensions/ParticleSystem/ParticleEmitterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ class GD_EXTENSION_API ParticleEmitterBase {
void SetParticleGravityAngle(double newAngleInDegree);
void SetParticleGravityLength(double newLength);

void SetParticleColor1(const gd::String& color);
void SetParticleColor2(const gd::String& color);

void SetParticleRed1(double newValue) { particleRed1 = newValue; };
void SetParticleRed2(double newValue) { particleRed2 = newValue; };
void SetParticleGreen1(double newValue) { particleGreen1 = newValue; };
void SetParticleGreen2(double newValue) { particleGreen2 = newValue; };
void SetParticleBlue1(double newValue) { particleBlue1 = newValue; };
void SetParticleBlue2(double newValue) { particleBlue2 = newValue; };
void SetParticleColor1(const gd::String& color) { particleColor1 = color; };
void SetParticleColor2(const gd::String& color) { particleColor2 = color; };

void SetParticleAlpha1(double newValue) { particleAlpha1 = newValue; };
void SetParticleAlpha2(double newValue) { particleAlpha2 = newValue; };
void SetParticleSize1(double newValue) { particleSize1 = newValue; };
Expand Down Expand Up @@ -91,7 +85,7 @@ class GD_EXTENSION_API ParticleEmitterBase {
void SetDestroyWhenNoParticles(bool enable = true) {
destroyWhenNoParticles = enable;
};
void SetJumpForwardInTimeOnCreation(double newValue) {
void SetJumpForwardInTimeOnCreation(double newValue) {
jumpForwardInTimeOnCreation = newValue;
};

Expand All @@ -114,12 +108,8 @@ class GD_EXTENSION_API ParticleEmitterBase {
std::size_t GetMaxParticleNb() const { return maxParticleNb; };
bool GetDestroyWhenNoParticles() const { return destroyWhenNoParticles; };

double GetParticleRed1() const { return particleRed1; };
double GetParticleRed2() const { return particleRed2; };
double GetParticleGreen1() const { return particleGreen1; };
double GetParticleGreen2() const { return particleGreen2; };
double GetParticleBlue1() const { return particleBlue1; };
double GetParticleBlue2() const { return particleBlue2; };
const gd::String& GetParticleColor1() const { return particleColor1; };
const gd::String& GetParticleColor2() const { return particleColor2; };
double GetParticleAlpha1() const { return particleAlpha1; };
double GetParticleAlpha2() const { return particleAlpha2; };
double GetParticleSize1() const { return particleSize1; };
Expand All @@ -146,7 +136,7 @@ class GD_EXTENSION_API ParticleEmitterBase {
void SetRendererType(RendererType type) { rendererType = type; };
RendererType GetRendererType() const { return rendererType; };

bool IsRenderingAdditive() { return additive; };
bool IsRenderingAdditive() const { return additive; };
void SetRenderingAdditive() { additive = true; };
void SetRenderingAlpha() { additive = false; };

Expand All @@ -173,8 +163,9 @@ class GD_EXTENSION_API ParticleEmitterBase {
double zoneRadius;
double particleGravityX, particleGravityY;
double particleLifeTimeMin, particleLifeTimeMax;
double particleRed1, particleRed2, particleGreen1, particleGreen2,
particleBlue1, particleBlue2, particleAlpha1, particleAlpha2;
gd::String particleColor1;
gd::String particleColor2;
double particleAlpha1, particleAlpha2;
double particleSize1, particleSize2, particleAngle1, particleAngle2;
double particleAlphaRandomness1, particleAlphaRandomness2;
double particleSizeRandomness1, particleSizeRandomness2,
Expand All @@ -194,16 +185,22 @@ class GD_EXTENSION_API ParticleEmitterObject : public gd::ObjectConfiguration,
public:
ParticleEmitterObject();
virtual ~ParticleEmitterObject(){};
virtual std::unique_ptr<gd::ObjectConfiguration> Clone() const {
virtual std::unique_ptr<gd::ObjectConfiguration> Clone() const override {
return gd::make_unique<ParticleEmitterObject>(*this);
}

virtual void ExposeResources(gd::ArbitraryResourceWorker& worker);
virtual void ExposeResources(gd::ArbitraryResourceWorker& worker) override;

virtual std::map<gd::String, gd::PropertyDescriptor>
GetProperties() const override;

virtual bool UpdateProperty(const gd::String &name,
const gd::String &value) override;

private:
virtual void DoUnserializeFrom(gd::Project& project,
const gd::SerializerElement& element);
virtual void DoSerializeTo(gd::SerializerElement& element) const;
const gd::SerializerElement& element) override;
virtual void DoSerializeTo(gd::SerializerElement& element) const override;
};

#endif // PARTICLEEMITTEROBJECT_H
39 changes: 17 additions & 22 deletions Extensions/ParticleSystem/particleemitterobject-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,13 @@ namespace gdjs {
{
time: 0,
value: gdjs.rgbToHex(
objectData.particleRed1,
objectData.particleGreen1,
objectData.particleBlue1
...gdjs.rgbOrHexToRGBColor(objectData.particleColor1)
),
},
{
time: 1,
value: gdjs.rgbToHex(
objectData.particleRed2,
objectData.particleGreen2,
objectData.particleBlue2
...gdjs.rgbOrHexToRGBColor(objectData.particleColor2)
),
},
],
Expand Down Expand Up @@ -292,31 +288,30 @@ namespace gdjs {
moveAcceleration.maxStart < 0);
}

setColor(
r1: number,
g1: number,
b1: number,
r2: number,
g2: number,
b2: number
): void {
setColor(color1: number, color2: number): void {
// console.log({color1,color2})
// debugger;
// Access private members of the behavior to apply changes right away.
const behavior: any = this.emitter.getBehavior('color');
const first = behavior.list.first;

const startColor = first.value;
startColor.r = r1;
startColor.g = g1;
startColor.b = b1;
{
const [r, g, b] = gdjs.hexNumberToRGBArray(color1);
first.value.r = r;
first.value.g = g;
first.value.b = b;
}

first.next = first.next || {
time: 1,
value: {},
};
const endColor = first.next.value;
endColor.r = r2;
endColor.g = g2;
endColor.b = b2;
{
const [r, g, b] = gdjs.hexNumberToRGBArray(color2);
first.next.value.r = r;
first.next.value.g = g;
first.next.value.b = b;
}
}

setSize(size1: float, size2: float): void {
Expand Down
Loading

0 comments on commit c68f113

Please sign in to comment.