improved handling of colors

improved debug colors
refactoring
This commit is contained in:
2024-12-21 23:04:01 +01:00
parent 4e6b1d642c
commit 71db6513f2
7 changed files with 97 additions and 38 deletions

View File

@@ -5,7 +5,7 @@ namespace FOU.Scripts.Elements;
public class Dirt : Solid {
public Dirt(int x, int y, ref Chunk chunk) : base(x, y, ref chunk) {
Color = AddColorVariance(Colors.Brown);
color = AddColorVariance(Colors.Brown);
Density = 10;
DiffuseSpeed = 50;
}

View File

@@ -3,35 +3,35 @@
namespace FOU.Scripts.Elements;
public class Element {
public Color Color = Colors.Black;
public Vector2I Position;
public Chunk Chunk;
public int Density;
public int LastUpdate = -1;
public int LastMove = 0;
public Vector2I Position;
public int DiffuseSpeed = 10;
public const int MAX_DIFFUSE_SPEED = 100;
public const int STEPS_UNTIL_INACTIVE = 500;
protected int Density;
protected int DiffuseSpeed = 10;
protected Color color = Colors.Black;
protected const int MAX_DIFFUSE_SPEED = 100;
protected const int STEPS_UNTIL_INACTIVE = 500;
protected const float MAX_COLOR_VARIANCE = 0.1f;
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
protected int lastMove = 0;
private bool active = false;
private int lastUpdate = -1;
private Color originalColor;
public Element(Element e) {
Position = e.Position;
Chunk = e.Chunk;
LastMove = Engine.GetFramesDrawn();
lastMove = Engine.GetFramesDrawn();
}
public Element(int x, int y, Chunk chunk) {
Position.X = x;
Position.Y = y;
Chunk = chunk;
LastMove = Engine.GetFramesDrawn();
lastMove = Engine.GetFramesDrawn();
Active = false;
}
@@ -42,10 +42,12 @@ public class Element {
active = value;
Chunk.SetElementActive(this, value);
SetDebugColors(value);
// SetDebugColor(value, new Color(0.2f, 0.2f, 0.2f));
}
}
public Color Color => color;
/// <summary>
/// base update method, checks if anything is to do at all
/// </summary>
@@ -54,8 +56,8 @@ public class Element {
public virtual bool Update() {
if (!Active) return false;
if (LastUpdate == Engine.GetFramesDrawn()) return false; // already updated this frame
LastUpdate = Engine.GetFramesDrawn();
if (lastUpdate == Engine.GetFramesDrawn()) return false; // already updated this frame
lastUpdate = Engine.GetFramesDrawn();
return true;
}
@@ -99,10 +101,13 @@ public class Element {
return c;
}
private void SetDebugColors(bool isActive) {
if (isActive)
Color = originalColor;
else if (Main.Instance.DebugVisualization)
Color = new Color(0.2f, 0.2f, 0.2f);
public void ResetColor() {
color = originalColor;
}
public void SetDebugColor(Color color) {
if (!Main.Instance.DebugVisualization) return;
this.color = color;
}
}

View File

@@ -9,7 +9,7 @@ public abstract class Liquid : Element {
public override bool Update() {
if (!base.Update()) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
if (lastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
Tick();

View File

@@ -7,7 +7,7 @@ public abstract class Solid : Element {
public override bool Update() {
if (!base.Update()) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
if (lastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
Tick();

View File

@@ -5,7 +5,7 @@ namespace FOU.Scripts.Elements;
public class Water : Liquid {
public Water(int x, int y, ref Chunk chunk) : base(x, y, ref chunk) {
Color = AddColorVariance(Colors.Blue);
color = AddColorVariance(Colors.Blue);
Density = 1;
}