system for changing drawable component layer

pull/5/head
Evan Hemsley 2019-11-20 19:26:44 -08:00
parent d53bf043db
commit 83b180fadb
2 changed files with 17 additions and 8 deletions

View File

@ -72,18 +72,16 @@ namespace Encompass
return id; return id;
} }
internal Guid MarkDrawComponentForWrite<TComponent>(Entity entity, TComponent component, int priority, int layer = 0) where TComponent : struct, IComponent
{
var id = MarkComponentForWrite(entity, component, priority);
drawLayerManager.RegisterComponentWithLayer(id, layer);
return id;
}
internal void RegisterDrawableComponent<TComponent>(Guid componentID, TComponent component) where TComponent : IDrawableComponent internal void RegisterDrawableComponent<TComponent>(Guid componentID, TComponent component) where TComponent : IDrawableComponent
{ {
drawLayerManager.RegisterComponentWithLayer(componentID, component.Layer); drawLayerManager.RegisterComponentWithLayer(componentID, component.Layer);
} }
internal void ChangeDrawableComponentLayer(Guid componentID, int layer)
{
drawLayerManager.AdjustComponentLayer(componentID, layer);
}
internal void AddComponent(Entity entity, Type type, Guid componentID, IComponent component) internal void AddComponent(Entity entity, Type type, Guid componentID, IComponent component)
{ {
IDToComponent[componentID] = component; IDToComponent[componentID] = component;

View File

@ -505,10 +505,21 @@ namespace Encompass
} }
if (component is IDrawableComponent drawableComponent) if (component is IDrawableComponent drawableComponent)
{
if (HasComponent<TComponent>(entity))
{
var currentComponent = GetComponent<TComponent>(entity);
if (((IDrawableComponent)currentComponent).Layer != drawableComponent.Layer)
{
componentManager.ChangeDrawableComponentLayer(componentID, drawableComponent.Layer);
}
}
else
{ {
componentManager.RegisterDrawableComponent(componentID, drawableComponent); componentManager.RegisterDrawableComponent(componentID, drawableComponent);
} }
} }
}
/// <summary> /// <summary>
/// Sends a Message. /// Sends a Message.