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 : IDrawComponent { public int Layer { get ; set; } } static List drawOrder = new List(); [Renders(typeof(TestDrawComponent), typeof(TestComponent))] class TestEntityRenderer : EntityRenderer { public override void Render(Entity entity) { drawOrder.Add(entity); } } class TestGeneralRenderer : GeneralRenderer { public new int Layer { get { return 9; } } public override void Render() { drawOrder.Add(this); } } [Test] public void DrawOrder() { var worldBuilder = new WorldBuilder(); worldBuilder.AddRenderer(); var testGeneralRenderer = worldBuilder.AddRenderer(); TestComponent testComponent; TestDrawComponent testDrawComponent = default(TestDrawComponent); testDrawComponent.Layer = 3; var entity = worldBuilder.CreateEntity(); entity.AddComponent(testComponent); entity.AddComponent(testDrawComponent); TestDrawComponent testDrawComponentTwo = default(TestDrawComponent); testDrawComponentTwo.Layer = 1; var entityTwo = worldBuilder.CreateEntity(); entityTwo.AddComponent(testComponent); entityTwo.AddComponent(testDrawComponentTwo); TestDrawComponent testDrawComponentThree = default(TestDrawComponent); testDrawComponentThree.Layer = 5; var entityThree = worldBuilder.CreateEntity(); entityThree.AddComponent(testComponent); entityThree.AddComponent(testDrawComponentThree); TestDrawComponent testDrawComponentFour = default(TestDrawComponent); testDrawComponentFour.Layer = -5; var entityFour = worldBuilder.CreateEntity(); entityFour.AddComponent(testComponent); entityFour.AddComponent(testDrawComponentFour); var world = worldBuilder.Build(); world.Update(0.01f); world.Draw(); drawOrder.Should().BeEquivalentTo(entityFour, entityTwo, entity, entityThree, testGeneralRenderer); } } }