77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using NUnit.Framework;
|
|
using FluentAssertions;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
using Encompass;
|
|
|
|
namespace Tests
|
|
{
|
|
public class WorldTest
|
|
{
|
|
struct TestComponent : IComponent { }
|
|
struct TestDrawComponent : IComponent { }
|
|
|
|
static List<object> drawOrder = new List<object>();
|
|
|
|
[Renders(typeof(TestDrawComponent), typeof(TestComponent))]
|
|
class TestEntityRenderer : EntityRenderer
|
|
{
|
|
public override void Render(Entity entity)
|
|
{
|
|
drawOrder.Add(entity);
|
|
}
|
|
}
|
|
|
|
class TestGeneralRenderer : GeneralRenderer
|
|
{
|
|
public override void Render()
|
|
{
|
|
drawOrder.Add(this);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void DrawOrder()
|
|
{
|
|
var worldBuilder = new WorldBuilder();
|
|
worldBuilder.AddEntityRenderer(new TestEntityRenderer());
|
|
var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
|
|
|
|
TestComponent testComponent;
|
|
TestDrawComponent testDrawComponent = default(TestDrawComponent);
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
entity.AddComponent(testComponent);
|
|
entity.AddDrawComponent(testDrawComponent, 3);
|
|
|
|
TestDrawComponent testDrawComponentTwo = default(TestDrawComponent);
|
|
|
|
var entityTwo = worldBuilder.CreateEntity();
|
|
entityTwo.AddComponent(testComponent);
|
|
entityTwo.AddDrawComponent(testDrawComponentTwo, 1);
|
|
|
|
TestDrawComponent testDrawComponentThree = default(TestDrawComponent);
|
|
|
|
var entityThree = worldBuilder.CreateEntity();
|
|
entityThree.AddComponent(testComponent);
|
|
entityThree.AddDrawComponent(testDrawComponentThree, 5);
|
|
|
|
TestDrawComponent testDrawComponentFour = default(TestDrawComponent);
|
|
|
|
var entityFour = worldBuilder.CreateEntity();
|
|
entityFour.AddComponent(testComponent);
|
|
entityFour.AddDrawComponent(testDrawComponentFour, -5);
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
world.Update(0.01f);
|
|
world.Draw();
|
|
|
|
drawOrder.Should().BeEquivalentTo(entityFour, entityTwo, entity, entityThree, testGeneralRenderer);
|
|
}
|
|
}
|
|
}
|