mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
68 lines
1.5 KiB
Beef
68 lines
1.5 KiB
Beef
using System.Collections;
|
|
|
|
namespace GlitchyEngine
|
|
{
|
|
public class LayerStack
|
|
{
|
|
private List<Layer> _layers = new List<Layer>() ~ DeleteContainerAndItems!(_);
|
|
|
|
/*
|
|
* Marks the index of the last layer.
|
|
* Used to insert new layers before overlays.
|
|
*/
|
|
private int _insertIndex = 0;
|
|
|
|
/**
|
|
* Pushes the provided layer onto the layer stack.
|
|
* @param ownLayer The layer that will be pushed onto the layerstack.
|
|
* @remarks The layerstack takes ownership of ownLayer.
|
|
*/
|
|
public void PushLayer(Layer ownLayer)
|
|
{
|
|
_layers.Insert(_insertIndex++, ownLayer);
|
|
ownLayer.OnAttach();
|
|
}
|
|
|
|
/**
|
|
* Pushes the provided overlay onto the layer stack.
|
|
* @param ownLayer The overlay that will be pushed onto the layerstack.
|
|
* @remarks The layerstack takes ownership of ownOverlay.
|
|
*/
|
|
public void PushOverlay(Layer ownOverlay)
|
|
{
|
|
_layers.Add(ownOverlay);
|
|
ownOverlay.OnAttach();
|
|
}
|
|
|
|
/**
|
|
* Removes the given overlay from the layer stack.
|
|
* @param layer The layer to pop from the LayerStack.
|
|
*/
|
|
public void PopLayer(Layer layer)
|
|
{
|
|
if(_layers.Remove(layer))
|
|
{
|
|
_insertIndex--;
|
|
layer.OnDetach();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Removes the given overlay from the layer stack.
|
|
* @param overlay The overlay to pop from the LayerStack.
|
|
*/
|
|
public void PopOverlay(Layer overlay)
|
|
{
|
|
if(_layers.Remove(overlay))
|
|
{
|
|
overlay.OnDetach();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns an enumerator for enumerating the layers.
|
|
*/
|
|
public List<Layer>.Enumerator GetEnumerator() => _layers.GetEnumerator();
|
|
}
|
|
}
|