WiP: deactivated array elements

This commit is contained in:
2024-11-03 14:56:07 +01:00
parent d1dac0b855
commit 383e1343ef
6 changed files with 52 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FOU.Scripts.Elements;
using Godot;
@@ -16,7 +17,7 @@ public class Chunk {
private readonly Image image;
private readonly int sizeX;
private readonly int sizeY;
private readonly List<Element> activeElements = new List<Element>();
private readonly HashSet<Element> activeElements;
public Chunk(int x, int y, int index) {
Index = index;
@@ -30,6 +31,8 @@ public class Chunk {
}
}
activeElements = new HashSet<Element>(sizeX * sizeY);
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
image.Fill(Colors.Black);
}
@@ -59,7 +62,7 @@ public class Chunk {
if (Elements[X,Y].GetType() != type) {
Elements[X, Y] = o as Element;
activeElements.Add(Elements[X, Y]);
Elements[X, Y].Active = true;
}
}
}
@@ -78,12 +81,17 @@ public class Chunk {
public void SetElementActive(Element e, bool active) {
if (e.Active == active) return;
if (active)
GD.Print($"setting {e} to {active}");
if (active && e.GetType() != typeof(Element))
activeElements.Add(e);
else
activeElements.Remove(e);
}
public int ActiveElemetnsCount() {
return activeElements.Count;
}
public void Swap(Element what, Vector2I pos) {
Swap(what, Get(pos));
}