Files
MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs
T
Christopher Whitley a501f76162 Sprite Rework (#897)
* Add file header

* Refator to file-scoped namespace

* Least complex to most complext method ordering

* Refactor: Group properties at top before constructor

* Use the new UV properties from Texture2DRegion.
This removes the dependency on the texture size in the calculations if the TextureRegion property is changed.

* No longer need to cache normalized origin to preserve it

* Use ArgumentNullException instead

* Use ArgumentNullException.ThrowIfNull

* Refactor:  Use brackets for readability

* Add xml documentation

* Add check for disposed texture

* Moved `Sprite` to `MonoGame.Extended.Graphics`

* Moved extension methods for rendering sprite into `SpriteBatch.Extensions`

* `ISpriteBatchDrawable` is not used by anything
It was originally part of the ScreneGraph implementation in MonoGame.Extended which was replaced by the ECS system.  It appears that this interface was forgotten to be removed and is not used for anything anymore.

* Add `CreateSprite` methods

* Add file header

* Moved `SpriteSheetAnimationFrame` to `MonoGame.Extended.Graphics`

* Move properties before constructor.

* Changed `Duration` to `TimeSpan` type

* Renamed `Index` to `FrameIndex`

* Add `TextureRegion` property

* Make property get only

* Cleanup whitespace

* Remove `SpriteSheetAnimationFrameJsonConverter`

* Cleanup unused namespaces

* Make file-scoped namespace

* Added xml documentation

* Added file header

* marked constructor as internal.
This will be created from a spritesheet itself

* Move `SpriteSheetAnimationCycle` to `MonoGame.Extended.Graphcis`

* File scoped namespace

* Add file header

* Reorganize: Move properties above constructor

* Make `Frames` property a read-only span

* Remove duration, this is being moved to the frame itself

* Add `Name` property

* Set looping, reversed, and ping pong properties in ctor

* Make ctor internal
This will be an object created by a spritesheet instane itself.

* Cleanup: Whitespace

* Add `FrameCount` property

* Add `GetFrame` method and accompanying `this[int]` method.

* Documentation: Added missing documentation.

* WIP: Temporary commit for workstation change

* WIP: Temporary commit for workstation change

* WIP: Temporary commit for workstation change

* WIP: Temporary commit for workstation change

* Refactor: Animation Refactor Completed

* Refactor: Sprite stuff finished

* Remove tests that can't be run on GitHub CI
Need to find alternative

* Make optional name param the last param in Texture2DRegion ctors

* Resolve merge conflicts
2024-06-23 23:10:16 -04:00

88 lines
2.8 KiB
C#

using System.Collections.Specialized;
using MonoGame.Extended.Graphics;
using Xunit;
namespace MonoGame.Extended.Entities.Tests
{
public class DummyComponent
{
}
public class AspectTests
{
private readonly ComponentManager _componentManager;
private readonly BitVector32 _entityA;
private readonly BitVector32 _entityB;
public AspectTests()
{
_componentManager = new ComponentManager();
_entityA = new BitVector32
{
[1 << _componentManager.GetComponentTypeId(typeof(Transform2))] = true,
[1 << _componentManager.GetComponentTypeId(typeof(Sprite))] = true,
[1 << _componentManager.GetComponentTypeId(typeof(DummyComponent))] = true
};
_entityB = new BitVector32
{
[1 << _componentManager.GetComponentTypeId(typeof(Transform2))] = true,
[1 << _componentManager.GetComponentTypeId(typeof(Sprite))] = true,
};
}
[Fact]
public void EmptyAspectMatchesAllComponents()
{
var componentManager = new ComponentManager();
var emptyAspect = Aspect.All()
.Build(componentManager);
Assert.True(emptyAspect.IsInterested(_entityA));
Assert.True(emptyAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInAllComponents()
{
var allAspect = Aspect
.All(typeof(Sprite), typeof(Transform2), typeof(DummyComponent))
.Build(_componentManager);
Assert.True(allAspect.IsInterested(_entityA));
Assert.False(allAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInEitherOneOfTheComponents()
{
var eitherOneAspect = Aspect
.One(typeof(Transform2), typeof(DummyComponent))
.Build(_componentManager);
Assert.True(eitherOneAspect.IsInterested(_entityA));
Assert.True(eitherOneAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInJustOneComponent()
{
var oneAspect = Aspect
.One(typeof(DummyComponent))
.Build(_componentManager);
Assert.True(oneAspect.IsInterested(_entityA));
Assert.False(oneAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInExcludingOneComponent()
{
var oneAspect = Aspect
.Exclude(typeof(DummyComponent))
.Build(_componentManager);
Assert.False(oneAspect.IsInterested(_entityA));
Assert.True(oneAspect.IsInterested(_entityB));
}
}
}