Skip to content

Commit

Permalink
feat(tests): player entity
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrynik committed Oct 31, 2023
1 parent 6d6168b commit 735d83f
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 60 deletions.
7 changes: 7 additions & 0 deletions MonoGame.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features.Debugging", "src\L
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scellecs.Morpeh.Extended", "src\Libs\External\Scellecs.Morpeh.Extended\Scellecs.Morpeh.Extended.csproj", "{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.Entities", "src\UnitTests\UnitTests.Entities\UnitTests.Entities.csproj", "{57F0A75A-5AD6-4187-9DC6-3CBA44333061}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -82,6 +84,10 @@ Global
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Release|Any CPU.Build.0 = Release|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5E3B6238-A92E-4703-8527-1C2410D7906A} = {F5258F7E-B0BA-466D-8CF8-4DAB84722BE3}
Expand All @@ -98,5 +104,6 @@ Global
{7AD01EBF-370B-4F35-9AEC-172A889D643F} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E}
{57F0A75A-5AD6-4187-9DC6-3CBA44333061} = {FC0D63F3-9B01-46BD-9435-A7E26C905825}
EndGlobalSection
EndGlobal
23 changes: 6 additions & 17 deletions src/Libs/Components/Data/RectangleCollisionComponent.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
// namespace Entitas.Components.Data
// {
// using Microsoft.Xna.Framework;
//
// public class RectangleCollisionComponent : IComponent
// {
// public Rectangle Size;
// }
// }
using Microsoft.Xna.Framework;
using Scellecs.Morpeh;

namespace Components.Data
{
using Scellecs.Morpeh;
using System.Drawing;
namespace Components.Data;

public struct RectangleCollisionComponent : IComponent
{
public Rectangle Rectangle;
}
public struct RectangleCollisionComponent : IComponent
{
public Rectangle Size;
}
32 changes: 13 additions & 19 deletions src/Libs/Components/Data/TransformComponent.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
// namespace Entitas.Components.Data
// {
// using Microsoft.Xna.Framework;
//
// public class TransformComponent : IComponent
// {
// public Vector2 Position;
// public Vector2 Velocity;
// }
// }
using Microsoft.Xna.Framework;
using Scellecs.Morpeh;

namespace Components.Data
{
using Scellecs.Morpeh;
using System.Numerics;
namespace Components.Data;

public struct TransformComponent : IComponent
{
public Vector2 Position;
public Vector2 Velocity;
}
public struct TransformComponent : IComponent
{
public Vector2 Position;
public Vector2 Velocity;
}

// Input Scan System -> Write Velocity

// Movement System -> Write Velocity
// Collision System -> Reset Velocity if there's collider in the velocity direction
// Position System -> Apply Velocity by changing Position
16 changes: 4 additions & 12 deletions src/Libs/Components/Tags/MovableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// namespace Entitas.Components.Tags
// {
// public class MovableComponent : IComponent
// {
// }
// }
using Scellecs.Morpeh;

namespace Components.Tags
{
using Scellecs.Morpeh;
namespace Components.Tags;

public struct MovableComponent : IComponent
{
}
public struct MovableComponent : IComponent
{
}
16 changes: 4 additions & 12 deletions src/Libs/Components/Tags/PlayerComponent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// namespace Entitas.Components.Tags
// {
// public class PlayerComponent : IComponent
// {
// }
// }
using Scellecs.Morpeh;

namespace Components.Tags
{
using Scellecs.Morpeh;
namespace Components.Tags;

public struct PlayerComponent : IComponent
{
}
public struct PlayerComponent : IComponent
{
}
1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.Entities/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
64 changes: 64 additions & 0 deletions src/UnitTests/UnitTests.Entities/PlayerEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Components.Data;
using Components.Render.Animation;
using Components.Tags;
using Entities;
using Scellecs.Morpeh;

namespace UnitTests.Entities;

public class Tests
{
// TODO: Systems test
private World _world;

[SetUp]
public void Setup()
{
_world = World.Create();
}

[TearDown]
public void TearDown()
{
_world.Dispose();
}

[Test]
public void PlayerEntity_IsCreatedInTheWorld()
{
// TODO: Use mocks for deps
Entity playerEntity = new PlayerEntity(new PlayerComponent(),
new MovableComponent(),
new TransformComponent(),
new RectangleCollisionComponent(),
new MovementAnimationsComponent(),
new CharacterAnimatorComponent())
.Create(@in: _world);

{
_world.TryGetEntity(playerEntity.ID, out Entity result);

Assert.That(playerEntity.ID, Is.EqualTo(result.ID));
}
}

[Test]
public void PlayerEntity_HasComponents()
{
Entity playerEntity = new PlayerEntity(new PlayerComponent(),
new MovableComponent(),
new TransformComponent(),
new RectangleCollisionComponent(),
new MovementAnimationsComponent(),
new CharacterAnimatorComponent())
.Create(@in: _world);

{
_world.TryGetEntity(playerEntity.ID, out Entity result);

Assert.That(result.Has<PlayerComponent>(), Is.True);
Assert.That(result.Has<MovableComponent>(), Is.True);
// ...
}
}
}
24 changes: 24 additions & 0 deletions src/UnitTests/UnitTests.Entities/UnitTests.Entities.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2"/>
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
<PackageReference Include="coverlet.collector" Version="3.2.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Libs\Entities\Entities.csproj" />
</ItemGroup>

</Project>

0 comments on commit 735d83f

Please sign in to comment.