Update Particle Emitter to use a single string as color and add properties for the object panel

This commit is contained in:
Florian Rival
2024-09-08 12:37:07 +02:00
parent 3c8ee887b0
commit 3374823695
9 changed files with 516 additions and 271 deletions

View File

@@ -33,12 +33,8 @@ ParticleEmitterBase::ParticleEmitterBase()
particleGravityY(0.0f),
particleLifeTimeMin(0.5f),
particleLifeTimeMax(2.5f),
particleRed1(255.0f),
particleRed2(255.0f),
particleGreen1(51),
particleGreen2(255),
particleBlue1(51),
particleBlue2(0.0f),
particleColor1("255;51;51"),
particleColor2("255;255;0"),
particleAlpha1(204),
particleAlpha2(0.0f),
particleSize1(100.0f),
@@ -57,6 +53,339 @@ ParticleEmitterBase::ParticleEmitterBase()
ParticleEmitterObject::ParticleEmitterObject() {}
bool ParticleEmitterObject::UpdateProperty(const gd::String& propertyName,
const gd::String& newValue) {
if (propertyName == "textureParticleName") {
SetParticleTexture(newValue);
return true;
}
if (propertyName == "rendererType") {
auto newRendererType = newValue == "Circle" ? Point
: newValue == "Line" ? Line
: Quad;
SetRendererType(newRendererType);
if (newRendererType != Quad) {
SetParticleTexture("");
}
return true;
}
if (propertyName == "particlesWidth") {
SetRendererParam1(newValue.To<double>());
return true;
}
if (propertyName == "particlesHeight") {
SetRendererParam2(newValue.To<double>());
return true;
}
if (propertyName == "lineLength") {
SetRendererParam1(newValue.To<double>());
return true;
}
if (propertyName == "lineThickness") {
SetRendererParam2(newValue.To<double>());
return true;
}
if (propertyName == "particlesSize") {
SetRendererParam1(newValue.To<double>());
return true;
}
if (propertyName == "particlesStartSize") {
SetParticleSize1(newValue.To<double>());
return true;
}
if (propertyName == "particlesEndSize") {
SetParticleSize2(newValue.To<double>());
return true;
}
if (propertyName == "particlesStartColor") {
SetParticleColor1(newValue);
return true;
}
if (propertyName == "particlesEndColor") {
SetParticleColor2(newValue);
return true;
}
if (propertyName == "particlesStartOpacity") {
SetParticleAlpha1(newValue.To<double>());
return true;
}
if (propertyName == "particlesEndOpacity") {
SetParticleAlpha2(newValue.To<double>());
return true;
}
if (propertyName == "additiveRendering") {
if (newValue == "1")
SetRenderingAdditive();
else
SetRenderingAlpha();
return true;
}
if (propertyName == "deleteWhenOutOfParticles") {
SetDestroyWhenNoParticles(newValue == "1");
return true;
}
if (propertyName == "maxParticlesCount") {
SetMaxParticleNb(newValue.To<double>());
return true;
}
if (propertyName == "tank") {
SetTank(newValue.To<double>());
return true;
}
if (propertyName == "flow") {
SetFlow(newValue.To<double>());
return true;
}
if (propertyName == "emitterForceMin") {
SetEmitterForceMin(newValue.To<double>());
return true;
}
if (propertyName == "emitterForceMax") {
SetEmitterForceMax(newValue.To<double>());
return true;
}
if (propertyName == "particleRotationSpeedMin") {
SetParticleAngle1(newValue.To<double>());
return true;
}
if (propertyName == "particleRotationSpeedMax") {
SetParticleAngle2(newValue.To<double>());
return true;
}
if (propertyName == "coneSprayAngle") {
SetConeSprayAngle(newValue.To<double>());
return true;
}
if (propertyName == "zoneRadius") {
SetZoneRadius(newValue.To<double>());
return true;
}
if (propertyName == "particleGravityX") {
SetParticleGravityX(newValue.To<double>());
return true;
}
if (propertyName == "particleGravityY") {
SetParticleGravityY(newValue.To<double>());
return true;
}
if (propertyName == "particleLifeTimeMin") {
SetParticleLifeTimeMin(newValue.To<double>());
return true;
}
if (propertyName == "particleLifeTimeMax") {
SetParticleLifeTimeMax(newValue.To<double>());
return true;
}
if (propertyName == "jumpForwardInTimeOnCreation") {
SetJumpForwardInTimeOnCreation(newValue.To<double>());
return true;
}
return false;
}
std::map<gd::String, gd::PropertyDescriptor>
ParticleEmitterObject::GetProperties() const {
std::map<gd::String, gd::PropertyDescriptor> objectProperties;
objectProperties["rendererType"]
.SetValue(GetRendererType() == Point ? "Circle"
: GetRendererType() == Line ? "Line"
: "Image")
.SetType("choice")
.AddExtraInfo("Circle")
.AddExtraInfo("Line")
.AddExtraInfo("Image")
.SetLabel(_("Particle type"));
if (GetRendererType() == Quad) {
objectProperties["textureParticleName"]
.SetValue(GetParticleTexture())
.SetType("resource")
.AddExtraInfo("image")
.SetLabel(_("Texture"));
objectProperties["particlesWidth"]
.SetValue(gd::String::From(GetRendererParam1()))
.SetType("number")
.SetLabel(_("Width"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles size"));
objectProperties["particlesHeight"]
.SetValue(gd::String::From(GetRendererParam2()))
.SetType("number")
.SetLabel(_("Height"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles size"));
} else if (GetRendererType() == Line) {
objectProperties["lineLength"]
.SetValue(gd::String::From(GetRendererParam1()))
.SetType("number")
.SetLabel(_("Lines length"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles size"));
objectProperties["lineThickness"]
.SetValue(gd::String::From(GetRendererParam2()))
.SetType("number")
.SetLabel(_("Lines thickness"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles size"));
} else {
objectProperties["particlesSize"]
.SetValue(gd::String::From(GetRendererParam1()))
.SetType("number")
.SetLabel(_("Size"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles size"));
}
objectProperties["particlesStartSize"]
.SetValue(gd::String::From(GetParticleSize1()))
.SetType("number")
.SetLabel(_("Start size (in percents)"))
.SetGroup(_("Particles size"));
objectProperties["particlesEndSize"]
.SetValue(gd::String::From(GetParticleSize2()))
.SetType("number")
.SetLabel(_("End size (in percents)"))
.SetGroup(_("Particles size"));
objectProperties["particlesStartColor"]
.SetValue(GetParticleColor1())
.SetType("color")
.SetLabel(_("Particles start color"))
.SetGroup(_("Particles color"));
objectProperties["particlesEndColor"]
.SetValue(GetParticleColor2())
.SetType("color")
.SetLabel(_("Particles end color"))
.SetGroup(_("Particles color"));
objectProperties["particlesStartOpacity"]
.SetValue(gd::String::From(GetParticleAlpha1()))
.SetType("number")
.SetLabel(_("Start opacity (0-255)"))
.SetGroup(_("Particles color"));
objectProperties["particlesEndOpacity"]
.SetValue(gd::String::From(GetParticleAlpha2()))
.SetType("number")
.SetLabel(_("End opacity (0-255)"))
.SetGroup(_("Particles color"));
objectProperties["additiveRendering"]
.SetValue(IsRenderingAdditive() ? "true" : "false")
.SetType("boolean")
.SetLabel(_("Additive rendering"))
.SetGroup(_("Particles color"));
objectProperties["deleteWhenOutOfParticles"]
.SetValue(GetDestroyWhenNoParticles() ? "true" : "false")
.SetType("boolean")
.SetLabel(_("Delete when out of particles"))
.SetGroup(_("Particles flow"));
objectProperties["maxParticlesCount"]
.SetValue(gd::String::From(GetMaxParticleNb()))
.SetType("number")
.SetLabel(_("Max particles count"))
.SetGroup(_("Particles flow"));
objectProperties["tank"]
.SetValue(gd::String::From(GetTank()))
.SetType("number")
.SetLabel(_("Tank"))
.SetGroup(_("Particles flow"));
objectProperties["flow"]
.SetValue(gd::String::From(GetFlow()))
.SetType("number")
.SetLabel(_("Flow"))
.SetGroup(_("Particles flow (particles/seconds)"));
objectProperties["emitterForceMin"]
.SetValue(gd::String::From(GetEmitterForceMin()))
.SetType("number")
.SetLabel(_("Emitter force min"))
.SetGroup(_("Particles movement"));
objectProperties["emitterForceMax"]
.SetValue(gd::String::From(GetEmitterForceMax()))
.SetType("number")
.SetLabel(_("Emitter force max"))
.SetGroup(_("Particles movement"));
objectProperties["particleRotationSpeedMin"]
.SetValue(gd::String::From(GetParticleAngle1()))
.SetType("number")
.SetLabel(_("Minimum rotation speed"))
.SetMeasurementUnit(gd::MeasurementUnit::GetDegreeAngle())
.SetGroup(_("Particles movement"));
objectProperties["particleRotationSpeedMax"]
.SetValue(gd::String::From(GetParticleAngle2()))
.SetType("number")
.SetLabel(_("Maximum rotation speed"))
.SetMeasurementUnit(gd::MeasurementUnit::GetDegreeAngle())
.SetGroup(_("Particles movement"));
objectProperties["coneSprayAngle"]
.SetValue(gd::String::From(GetConeSprayAngle()))
.SetType("number")
.SetLabel(_("Cone spray angle"))
.SetMeasurementUnit(gd::MeasurementUnit::GetDegreeAngle())
.SetGroup(_("Particles movement"));
objectProperties["zoneRadius"]
.SetValue(gd::String::From(GetZoneRadius()))
.SetType("number")
.SetLabel(_("Emitter radius"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles movement"));
objectProperties["particleGravityX"]
.SetValue(gd::String::From(GetParticleGravityX()))
.SetType("number")
.SetLabel(_("Gravity X"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles gravity"));
objectProperties["particleGravityY"]
.SetValue(gd::String::From(GetParticleGravityY()))
.SetType("number")
.SetLabel(_("Gravity Y"))
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
.SetGroup(_("Particles gravity"));
objectProperties["particleLifeTimeMin"]
.SetValue(gd::String::From(GetParticleLifeTimeMin()))
.SetType("number")
.SetLabel(_("Minimum lifetime"))
.SetMeasurementUnit(gd::MeasurementUnit::GetSecond())
.SetGroup(_("Particles life time"));
objectProperties["particleLifeTimeMax"]
.SetValue(gd::String::From(GetParticleLifeTimeMax()))
.SetType("number")
.SetLabel(_("Maximum lifetime"))
.SetMeasurementUnit(gd::MeasurementUnit::GetSecond())
.SetGroup(_("Particles life time"));
objectProperties["jumpForwardInTimeOnCreation"]
.SetValue(gd::String::From(GetJumpForwardInTimeOnCreation()))
.SetType("number")
.SetLabel(_("Jump forward in time on creation"))
.SetMeasurementUnit(gd::MeasurementUnit::GetSecond())
.SetGroup(_("Particles life time"));
return objectProperties;
}
void ParticleEmitterObject::DoUnserializeFrom(
gd::Project& project, const gd::SerializerElement& element) {
ParticleEmitterBase::UnserializeParticleEmitterBaseFrom(element);
@@ -75,12 +404,27 @@ void ParticleEmitterBase::UnserializeParticleEmitterBaseFrom(
particleGravityY = element.GetDoubleAttribute("particleGravityY");
particleLifeTimeMin = element.GetDoubleAttribute("particleLifeTimeMin");
particleLifeTimeMax = element.GetDoubleAttribute("particleLifeTimeMax");
particleRed1 = element.GetDoubleAttribute("particleRed1");
particleRed2 = element.GetDoubleAttribute("particleRed2");
particleGreen1 = element.GetDoubleAttribute("particleGreen1");
particleGreen2 = element.GetDoubleAttribute("particleGreen2");
particleBlue1 = element.GetDoubleAttribute("particleBlue1");
particleBlue2 = element.GetDoubleAttribute("particleBlue2");
particleColor1 = element.GetStringAttribute("particleColor1");
// Compatibility with GD <= 5.4.210
if (element.HasChild("particleRed1") && !element.HasChild("particleColor1")) {
particleColor1 =
element.GetChild("particleRed1").GetValue().GetString() + ";" +
element.GetChild("particleGreen1").GetValue().GetString() + ";" +
element.GetChild("particleBlue1").GetValue().GetString();
}
// end of compatibility code
particleColor2 = element.GetStringAttribute("particleColor2");
// Compatibility with GD <= 5.4.210
if (element.HasChild("particleRed2") && !element.HasChild("particleColor2")) {
particleColor2 =
element.GetChild("particleRed2").GetValue().GetString() + ";" +
element.GetChild("particleGreen2").GetValue().GetString() + ";" +
element.GetChild("particleBlue2").GetValue().GetString();
}
// end of compatibility code
particleAlpha1 = element.GetDoubleAttribute("particleAlpha1");
particleAlpha2 = element.GetDoubleAttribute("particleAlpha2");
rendererParam1 = element.GetDoubleAttribute("rendererParam1");
@@ -106,7 +450,8 @@ void ParticleEmitterBase::UnserializeParticleEmitterBaseFrom(
element.GetBoolAttribute("destroyWhenNoParticles", false);
textureParticleName = element.GetStringAttribute("textureParticleName");
maxParticleNb = element.GetIntAttribute("maxParticleNb", 5000);
jumpForwardInTimeOnCreation = element.GetDoubleAttribute("jumpForwardInTimeOnCreation");
jumpForwardInTimeOnCreation =
element.GetDoubleAttribute("jumpForwardInTimeOnCreation");
{
gd::String result = element.GetStringAttribute("rendererType");
@@ -137,12 +482,8 @@ void ParticleEmitterBase::SerializeParticleEmitterBaseTo(
element.SetAttribute("particleGravityY", particleGravityY);
element.SetAttribute("particleLifeTimeMin", particleLifeTimeMin);
element.SetAttribute("particleLifeTimeMax", particleLifeTimeMax);
element.SetAttribute("particleRed1", particleRed1);
element.SetAttribute("particleRed2", particleRed2);
element.SetAttribute("particleGreen1", particleGreen1);
element.SetAttribute("particleGreen2", particleGreen2);
element.SetAttribute("particleBlue1", particleBlue1);
element.SetAttribute("particleBlue2", particleBlue2);
element.SetAttribute("particleColor1", particleColor1);
element.SetAttribute("particleColor2", particleColor2);
element.SetAttribute("particleAlpha1", particleAlpha1);
element.SetAttribute("particleAlpha2", particleAlpha2);
element.SetAttribute("particleSize1", particleSize1);
@@ -161,7 +502,8 @@ void ParticleEmitterBase::SerializeParticleEmitterBaseTo(
element.SetAttribute("destroyWhenNoParticles", destroyWhenNoParticles);
element.SetAttribute("textureParticleName", textureParticleName);
element.SetAttribute("maxParticleNb", (int)maxParticleNb);
element.SetAttribute("jumpForwardInTimeOnCreation", jumpForwardInTimeOnCreation);
element.SetAttribute("jumpForwardInTimeOnCreation",
jumpForwardInTimeOnCreation);
gd::String rendererTypeStr = "Point";
if (rendererType == Line)
@@ -169,6 +511,26 @@ void ParticleEmitterBase::SerializeParticleEmitterBaseTo(
else if (rendererType == Quad)
rendererTypeStr = "Quad";
element.SetAttribute("rendererType", rendererTypeStr);
// Still serialize the old particle color components for compatibility with GDevelop <= 5.4.210.
// Remove this in a few releases (or when hex strings are accepted for the color).
{
auto rgb = particleColor1.Split(';');
if (rgb.size() == 3) {
element.SetAttribute("particleRed1", rgb[0].To<double>());
element.SetAttribute("particleGreen1", rgb[1].To<double>());
element.SetAttribute("particleBlue1", rgb[2].To<double>());
}
}
{
auto rgb = particleColor2.Split(';');
if (rgb.size() == 3) {
element.SetAttribute("particleRed2", rgb[0].To<double>());
element.SetAttribute("particleGreen2", rgb[1].To<double>());
element.SetAttribute("particleBlue2", rgb[2].To<double>());
}
}
// end of compatibility code
}
ParticleEmitterBase::~ParticleEmitterBase() {}
@@ -227,26 +589,6 @@ double ParticleEmitterBase::GetParticleGravityLength() const {
GetParticleGravityX() * GetParticleGravityX());
}
void ParticleEmitterBase::SetParticleColor1(const gd::String& color) {
std::vector<gd::String> colors = color.Split(U';');
if (colors.size() < 3) return; // Color is incorrect
SetParticleRed1(colors[0].To<int>());
SetParticleGreen1(colors[1].To<int>());
SetParticleBlue1(colors[2].To<int>());
}
void ParticleEmitterBase::SetParticleColor2(const gd::String& color) {
std::vector<gd::String> colors = color.Split(U';');
if (colors.size() < 3) return; // Color is incorrect
SetParticleRed2(colors[0].To<int>());
SetParticleGreen2(colors[1].To<int>());
SetParticleBlue2(colors[2].To<int>());
}
/**
* Used by copy constructor and assignment operator.
* \warning Do not forget to update me if members were changed!
@@ -269,12 +611,8 @@ void ParticleEmitterBase::Init(const ParticleEmitterBase& other) {
particleGravityY = other.particleGravityY;
particleLifeTimeMin = other.particleLifeTimeMin;
particleLifeTimeMax = other.particleLifeTimeMax;
particleRed1 = other.particleRed1;
particleRed2 = other.particleRed2;
particleGreen1 = other.particleGreen1;
particleGreen2 = other.particleGreen2;
particleBlue1 = other.particleBlue1;
particleBlue2 = other.particleBlue2;
particleColor1 = other.particleColor1;
particleColor2 = other.particleColor2;
particleAlpha1 = other.particleAlpha1;
particleAlpha2 = other.particleAlpha2;
particleSize1 = other.particleSize1;

View File

@@ -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 SetParticleColor1(const gd::String& color) { particleColor1 = color; };
void SetParticleColor2(const gd::String& color) { particleColor2 = 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 SetParticleAlpha1(double newValue) { particleAlpha1 = newValue; };
void SetParticleAlpha2(double newValue) { particleAlpha2 = newValue; };
void SetParticleSize1(double newValue) { particleSize1 = newValue; };
@@ -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;
};
@@ -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; };
@@ -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; };
@@ -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,
@@ -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

View File

@@ -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)
),
},
],
@@ -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 {

View File

@@ -21,12 +21,8 @@ namespace gdjs {
particleLifeTimeMin: number;
particleGravityY: number;
particleGravityX: number;
particleRed2: number;
particleRed1: number;
particleGreen2: number;
particleGreen1: number;
particleBlue2: number;
particleBlue1: number;
particleColor2: string;
particleColor1: string;
particleSize2: number;
particleSize1: number;
/**
@@ -83,12 +79,8 @@ namespace gdjs {
gravx: number;
gravy: number;
// Color
colr1: number;
colr2: number;
colg1: number;
colg2: number;
colb1: number;
colb2: number;
color1: number;
color2: number;
// Size
size1: number;
size2: number;
@@ -124,12 +116,8 @@ namespace gdjs {
lifeTimeMax: float;
gravityX: number;
gravityY: number;
colorR1: number;
colorR2: number;
colorG1: number;
colorG2: number;
colorB1: number;
colorB2: number;
color1: number;
color2: number;
size1: number;
size2: number;
alpha1: number;
@@ -195,12 +183,12 @@ namespace gdjs {
this.lifeTimeMax = particleObjectData.particleLifeTimeMax;
this.gravityX = particleObjectData.particleGravityX;
this.gravityY = particleObjectData.particleGravityY;
this.colorR1 = particleObjectData.particleRed1;
this.colorR2 = particleObjectData.particleRed2;
this.colorG1 = particleObjectData.particleGreen1;
this.colorG2 = particleObjectData.particleGreen2;
this.colorB1 = particleObjectData.particleBlue1;
this.colorB2 = particleObjectData.particleBlue2;
this.color1 = gdjs.rgbOrHexStringToNumber(
particleObjectData.particleColor1
);
this.color2 = gdjs.rgbOrHexStringToNumber(
particleObjectData.particleColor2
);
this.size1 = particleObjectData.particleSize1;
this.size2 = particleObjectData.particleSize2;
this.alpha1 = particleObjectData.particleAlpha1;
@@ -296,23 +284,11 @@ namespace gdjs {
if (oldObjectData.particleGravityY !== newObjectData.particleGravityY) {
this.setParticleGravityY(newObjectData.particleGravityY);
}
if (oldObjectData.particleRed1 !== newObjectData.particleRed1) {
this.setParticleRed1(newObjectData.particleRed1);
if (oldObjectData.particleColor1 !== newObjectData.particleColor1) {
this.setParticleColor1(newObjectData.particleColor1);
}
if (oldObjectData.particleRed2 !== newObjectData.particleRed2) {
this.setParticleRed2(newObjectData.particleRed2);
}
if (oldObjectData.particleGreen1 !== newObjectData.particleGreen1) {
this.setParticleGreen1(newObjectData.particleGreen1);
}
if (oldObjectData.particleGreen2 !== newObjectData.particleGreen2) {
this.setParticleGreen2(newObjectData.particleGreen2);
}
if (oldObjectData.particleBlue1 !== newObjectData.particleBlue1) {
this.setParticleBlue1(newObjectData.particleBlue1);
}
if (oldObjectData.particleBlue2 !== newObjectData.particleBlue2) {
this.setParticleBlue2(newObjectData.particleBlue2);
if (oldObjectData.particleColor2 !== newObjectData.particleColor2) {
this.setParticleColor2(newObjectData.particleColor2);
}
if (oldObjectData.particleSize1 !== newObjectData.particleSize1) {
this.setParticleSize1(newObjectData.particleSize1);
@@ -397,12 +373,8 @@ namespace gdjs {
ltmax: this.lifeTimeMax,
gravx: this.gravityX,
gravy: this.gravityY,
colr1: this.colorR1,
colr2: this.colorR2,
colg1: this.colorG1,
colg2: this.colorG2,
colb1: this.colorB1,
colb2: this.colorB2,
color1: this.color1,
color2: this.color2,
size1: this.size1,
size2: this.size2,
alp1: this.alpha1,
@@ -463,23 +435,11 @@ namespace gdjs {
if (syncData.gravy !== undefined) {
this.setParticleGravityY(syncData.gravy);
}
if (syncData.colr1 !== undefined) {
this.setParticleRed1(syncData.colr1);
if (syncData.color1 !== undefined) {
this.setParticleColor1AsNumber(syncData.color1);
}
if (syncData.colr2 !== undefined) {
this.setParticleRed2(syncData.colr2);
}
if (syncData.colg1 !== undefined) {
this.setParticleGreen1(syncData.colg1);
}
if (syncData.colg2 !== undefined) {
this.setParticleGreen2(syncData.colg2);
}
if (syncData.colb1 !== undefined) {
this.setParticleBlue1(syncData.colb1);
}
if (syncData.colb2 !== undefined) {
this.setParticleBlue2(syncData.colb2);
if (syncData.color2 !== undefined) {
this.setParticleColor2AsNumber(syncData.color2);
}
if (syncData.size1 !== undefined) {
this.setParticleSize1(syncData.size1);
@@ -547,14 +507,7 @@ namespace gdjs {
this._renderer.setGravity(this.gravityX, this.gravityY);
}
if (this._colorDirty) {
this._renderer.setColor(
this.colorR1,
this.colorG1,
this.colorB1,
this.colorR2,
this.colorG2,
this.colorB2
);
this._renderer.setColor(this.color1, this.color2);
}
if (this._sizeDirty) {
this._renderer.setSize(this.size1, this.size2);
@@ -820,7 +773,7 @@ namespace gdjs {
}
getParticleRed1(): number {
return this.colorR1;
return gdjs.hexNumberToRGBArray(this.color1)[0];
}
setParticleRed1(red: number): void {
@@ -830,14 +783,14 @@ namespace gdjs {
if (red > 255) {
red = 255;
}
if (this.colorR1 !== red) {
this._colorDirty = true;
this.colorR1 = red;
}
const existingColor = gdjs.hexNumberToRGBArray(this.color1);
this.setParticleColor1AsNumber(
gdjs.rgbToHexNumber(red, existingColor[1], existingColor[2])
);
}
getParticleRed2(): number {
return this.colorR2;
return gdjs.hexNumberToRGBArray(this.color2)[0];
}
setParticleRed2(red: number): void {
@@ -847,14 +800,14 @@ namespace gdjs {
if (red > 255) {
red = 255;
}
if (this.colorR2 !== red) {
this._colorDirty = true;
this.colorR2 = red;
}
const existingColor = gdjs.hexNumberToRGBArray(this.color2);
this.setParticleColor2AsNumber(
gdjs.rgbToHexNumber(red, existingColor[1], existingColor[2])
);
}
getParticleGreen1(): number {
return this.colorG1;
return gdjs.hexNumberToRGBArray(this.color1)[1];
}
setParticleGreen1(green: number): void {
@@ -864,14 +817,14 @@ namespace gdjs {
if (green > 255) {
green = 255;
}
if (this.colorG1 !== green) {
this._colorDirty = true;
this.colorG1 = green;
}
const existingColor = gdjs.hexNumberToRGBArray(this.color1);
this.setParticleColor1AsNumber(
gdjs.rgbToHexNumber(existingColor[0], green, existingColor[2])
);
}
getParticleGreen2(): number {
return this.colorG2;
return gdjs.hexNumberToRGBArray(this.color2)[1];
}
setParticleGreen2(green: number): void {
@@ -881,14 +834,14 @@ namespace gdjs {
if (green > 255) {
green = 255;
}
if (this.colorG2 !== green) {
this._colorDirty = true;
this.colorG2 = green;
}
const existingColor = gdjs.hexNumberToRGBArray(this.color2);
this.setParticleColor2AsNumber(
gdjs.rgbToHexNumber(existingColor[0], green, existingColor[2])
);
}
getParticleBlue1(): number {
return this.colorB1;
return gdjs.hexNumberToRGBArray(this.color1)[2];
}
setParticleBlue1(blue: number): void {
@@ -898,14 +851,14 @@ namespace gdjs {
if (blue > 255) {
blue = 255;
}
if (this.colorB1 !== blue) {
this._colorDirty = true;
this.colorB1 = blue;
}
const existingColor = gdjs.hexNumberToRGBArray(this.color1);
this.setParticleColor1AsNumber(
gdjs.rgbToHexNumber(existingColor[0], existingColor[1], blue)
);
}
getParticleBlue2(): number {
return this.colorB2;
return gdjs.hexNumberToRGBArray(this.color2)[2];
}
setParticleBlue2(blue: number): void {
@@ -915,30 +868,34 @@ namespace gdjs {
if (blue > 255) {
blue = 255;
}
if (this.colorB2 !== blue) {
this._colorDirty = true;
this.colorB2 = blue;
}
const existingColor = gdjs.hexNumberToRGBArray(this.color2);
this.setParticleColor2AsNumber(
gdjs.rgbToHexNumber(existingColor[0], existingColor[1], blue)
);
}
setParticleColor1(rgbColor: string): void {
const colors = rgbColor.split(';');
if (colors.length < 3) {
return;
}
this.setParticleRed1(parseInt(colors[0], 10));
this.setParticleGreen1(parseInt(colors[1], 10));
this.setParticleBlue1(parseInt(colors[2], 10));
setParticleColor1AsNumber(color: number): void {
this.color1 = color;
this._colorDirty = true;
debugger;
}
setParticleColor2(rgbColor: string): void {
const colors = rgbColor.split(';');
if (colors.length < 3) {
return;
}
this.setParticleRed2(parseInt(colors[0], 10));
this.setParticleGreen2(parseInt(colors[1], 10));
this.setParticleBlue2(parseInt(colors[2], 10));
setParticleColor1(rgbOrHexColor: string): void {
this.setParticleColor1AsNumber(
gdjs.rgbOrHexStringToNumber(rgbOrHexColor)
);
}
setParticleColor2AsNumber(color: number): void {
this.color2 = color;
this._colorDirty = true;
debugger;
}
setParticleColor2(rgbOrHexColor: string): void {
this.setParticleColor2AsNumber(
gdjs.rgbOrHexStringToNumber(rgbOrHexColor)
);
}
getParticleSize1(): float {

View File

@@ -3627,18 +3627,10 @@ interface ParticleEmitterObject {
void SetParticleLifeTimeMax(double newValue);
double GetParticleLifeTimeMax();
void SetParticleRed1(double newValue);
double GetParticleRed1();
void SetParticleRed2(double newValue);
double GetParticleRed2();
void SetParticleGreen1(double newValue);
double GetParticleGreen1();
void SetParticleGreen2(double newValue);
double GetParticleGreen2();
void SetParticleBlue1(double newValue);
double GetParticleBlue1();
void SetParticleBlue2(double newValue);
double GetParticleBlue2();
void SetParticleColor1([Const] DOMString newValue);
[Const, Ref] DOMString GetParticleColor1();
void SetParticleColor2([Const] DOMString newValue);
[Const, Ref] DOMString GetParticleColor2();
void SetParticleAlpha1(double newValue);
double GetParticleAlpha1();
void SetParticleAlpha2(double newValue);

View File

@@ -2696,18 +2696,10 @@ export class ParticleEmitterObject extends ObjectConfiguration {
getParticleLifeTimeMin(): number;
setParticleLifeTimeMax(newValue: number): void;
getParticleLifeTimeMax(): number;
setParticleRed1(newValue: number): void;
getParticleRed1(): number;
setParticleRed2(newValue: number): void;
getParticleRed2(): number;
setParticleGreen1(newValue: number): void;
getParticleGreen1(): number;
setParticleGreen2(newValue: number): void;
getParticleGreen2(): number;
setParticleBlue1(newValue: number): void;
getParticleBlue1(): number;
setParticleBlue2(newValue: number): void;
getParticleBlue2(): number;
setParticleColor1(newValue: string): void;
getParticleColor1(): string;
setParticleColor2(newValue: string): void;
getParticleColor2(): string;
setParticleAlpha1(newValue: number): void;
getParticleAlpha1(): number;
setParticleAlpha2(newValue: number): void;

View File

@@ -40,18 +40,10 @@ declare class gdParticleEmitterObject extends gdObjectConfiguration {
getParticleLifeTimeMin(): number;
setParticleLifeTimeMax(newValue: number): void;
getParticleLifeTimeMax(): number;
setParticleRed1(newValue: number): void;
getParticleRed1(): number;
setParticleRed2(newValue: number): void;
getParticleRed2(): number;
setParticleGreen1(newValue: number): void;
getParticleGreen1(): number;
setParticleGreen2(newValue: number): void;
getParticleGreen2(): number;
setParticleBlue1(newValue: number): void;
getParticleBlue1(): number;
setParticleBlue2(newValue: number): void;
getParticleBlue2(): number;
setParticleColor1(newValue: string): void;
getParticleColor1(): string;
setParticleColor2(newValue: string): void;
getParticleColor2(): string;
setParticleAlpha1(newValue: number): void;
getParticleAlpha1(): number;
setParticleAlpha2(newValue: number): void;

View File

@@ -164,18 +164,13 @@ export default class ParticleEmitterEditor extends React.Component<
floatingLabelText={<Trans>Particles start color</Trans>}
disableAlpha
fullWidth
color={rgbColorToRGBString({
r: particleEmitterConfiguration.getParticleRed1(),
g: particleEmitterConfiguration.getParticleGreen1(),
b: particleEmitterConfiguration.getParticleBlue1(),
})}
color={particleEmitterConfiguration.getParticleColor1()}
onChange={color => {
const rgbColor = rgbStringAndAlphaToRGBColor(color);
if (rgbColor) {
particleEmitterConfiguration.setParticleRed1(rgbColor.r);
particleEmitterConfiguration.setParticleGreen1(rgbColor.g);
particleEmitterConfiguration.setParticleBlue1(rgbColor.b);
particleEmitterConfiguration.setParticleColor1(
rgbColorToRGBString(rgbColor)
);
this.forceUpdate();
}
}}
@@ -199,18 +194,13 @@ export default class ParticleEmitterEditor extends React.Component<
floatingLabelText={<Trans>Particles end color</Trans>}
disableAlpha
fullWidth
color={rgbColorToRGBString({
r: particleEmitterConfiguration.getParticleRed2(),
g: particleEmitterConfiguration.getParticleGreen2(),
b: particleEmitterConfiguration.getParticleBlue2(),
})}
color={particleEmitterConfiguration.getParticleColor2()}
onChange={color => {
const rgbColor = rgbStringAndAlphaToRGBColor(color);
if (rgbColor) {
particleEmitterConfiguration.setParticleRed2(rgbColor.r);
particleEmitterConfiguration.setParticleGreen2(rgbColor.g);
particleEmitterConfiguration.setParticleBlue2(rgbColor.b);
particleEmitterConfiguration.setParticleColor2(
rgbColorToRGBString(rgbColor)
);
this.forceUpdate();
}
}}

View File

@@ -3,7 +3,7 @@ import RenderedInstance from './RenderedInstance';
import PixiResourcesLoader from '../../ObjectsRendering/PixiResourcesLoader';
import ResourcesLoader from '../../ResourcesLoader';
import * as PIXI from 'pixi.js-legacy';
import { rgbToHexNumber } from '../../Utils/ColorTransformer';
import { rgbOrHexToHexNumber } from '../../Utils/ColorTransformer';
const gd: libGDevelop = global.gd;
/**
@@ -66,11 +66,7 @@ export default class RenderedParticleEmitterInstance extends RenderedInstance {
this._pixiObject.beginFill(0, 0);
this._pixiObject.lineStyle(
3,
rgbToHexNumber(
particleEmitterConfiguration.getParticleRed2(),
particleEmitterConfiguration.getParticleGreen2(),
particleEmitterConfiguration.getParticleBlue2()
),
rgbOrHexToHexNumber(particleEmitterConfiguration.getParticleColor2()),
1
);
this._pixiObject.moveTo(0, 0);
@@ -87,11 +83,7 @@ export default class RenderedParticleEmitterInstance extends RenderedInstance {
this._pixiObject.lineStyle(0, 0x000000, 1);
this._pixiObject.beginFill(
rgbToHexNumber(
particleEmitterConfiguration.getParticleRed1(),
particleEmitterConfiguration.getParticleGreen1(),
particleEmitterConfiguration.getParticleBlue1()
)
rgbOrHexToHexNumber(particleEmitterConfiguration.getParticleColor1())
);
this._pixiObject.drawCircle(0, 0, 8);
this._pixiObject.endFill();