Skip to content

Commit

Permalink
[WIP] Add Entity Component to Entities via EntityInspectorView (#295)
Browse files Browse the repository at this point in the history
* [WIP] Add Entity Component to Entities via `EntityInspectorView`

* Getting there

* Fixed styling issue

* Fix
  • Loading branch information
softwareantics authored Dec 5, 2023
1 parent 265213c commit c2bb7ba
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 90 deletions.
15 changes: 8 additions & 7 deletions FinalEngine.ECS.Components/Core/TagComponent.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
// <copyright file="TagComponent.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS.Components.Core;

using System.ComponentModel;

/// <summary>
/// Provides a component that represents a name or tag for an <see cref="Entity"/>.
/// Provides a component that represents a name or tag for an <see cref="Entity"/>.
/// </summary>
/// <seealso cref="IEntityComponent" />
/// <seealso cref="IEntityComponent"/>
[Category("Core")]
public sealed class TagComponent : IEntityComponent, INotifyPropertyChanged
{
/// <summary>
/// The tag.
/// The tag.
/// </summary>
private string? tag;

/// <summary>
/// Occurs when a property value changes.
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler? PropertyChanged;

/// <summary>
/// Gets or sets the tag.
/// Gets or sets the tag.
/// </summary>
/// <value>
/// The tag.
/// The tag.
/// </value>
public string? Tag
{
Expand Down
66 changes: 34 additions & 32 deletions FinalEngine.ECS.Components/Core/TransformComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

namespace FinalEngine.ECS.Components.Core;

using System.ComponentModel;
using System.Numerics;

/// <summary>
/// Provides a component that represents the translation, rotation and scale of an entity.
/// Provides a component that represents the translation, rotation and scale of an entity.
/// </summary>
/// <seealso cref="IEntityComponent" />
/// <seealso cref="IEntityComponent"/>
[Category("Core")]
public sealed class TransformComponent : IEntityComponent
{
/// <summary>
/// Initializes a new instance of the <see cref="TransformComponent"/> class.
/// Initializes a new instance of the <see cref="TransformComponent"/> class.
/// </summary>
public TransformComponent()
{
Expand All @@ -23,100 +25,100 @@ public TransformComponent()
}

/// <summary>
/// Gets a normalized vector representing the negative Z-axis of the transform in world space.
/// Gets a normalized vector representing the negative Z-axis of the transform in world space.
/// </summary>
/// <value>
/// The normalized vector representing the Z-axis of the transform in world space..
/// The normalized vector representing the Z-axis of the transform in world space..
/// </value>
public Vector3 Backward
{
get { return Vector3.Normalize(Vector3.Transform(-Vector3.UnitZ, this.Rotation)); }
}

/// <summary>
/// Gets a normalized vector representing the negative Y-axis of the transform in world space.
/// Gets a normalized vector representing the negative Y-axis of the transform in world space.
/// </summary>
/// <value>
/// The normalized vector representing the negative Y-axis of the transform in world space.
/// The normalized vector representing the negative Y-axis of the transform in world space.
/// </value>
public Vector3 Down
{
get { return Vector3.Normalize(Vector3.Transform(-Vector3.UnitY, this.Rotation)); }
}

/// <summary>
/// Gets a normalized vector representing the Z-axis of the transform in world space.
/// Gets a normalized vector representing the Z-axis of the transform in world space.
/// </summary>
/// <value>
/// The normalized vector representing the Z-axis of the transform in world space..
/// The normalized vector representing the Z-axis of the transform in world space..
/// </value>
public Vector3 Forward
{
get { return Vector3.Normalize(Vector3.Transform(Vector3.UnitZ, this.Rotation)); }
}

/// <summary>
/// Gets a normalized vector representing the negative X-axis of the transform in world space.
/// Gets a normalized vector representing the negative X-axis of the transform in world space.
/// </summary>
/// <value>
/// The normalized vector representing the negative X-axis of the transform in world space.
/// The normalized vector representing the negative X-axis of the transform in world space.
/// </value>
public Vector3 Left
{
get { return Vector3.Normalize(Vector3.Transform(-Vector3.UnitX, this.Rotation)); }
}

/// <summary>
/// Gets or sets the position of the transform.
/// Gets or sets the position of the transform.
/// </summary>
/// <value>
/// The position of the transform.
/// The position of the transform.
/// </value>
public Vector3 Position { get; set; }

/// <summary>
/// Gets a normalized vector representing the X-axis of the transform in world space.
/// Gets a normalized vector representing the X-axis of the transform in world space.
/// </summary>
/// <value>
/// The normalized vector representing the negative X-axis of the transform in world space.
/// The normalized vector representing the negative X-axis of the transform in world space.
/// </value>
public Vector3 Right
{
get { return Vector3.Normalize(Vector3.Transform(Vector3.UnitX, this.Rotation)); }
}

/// <summary>
/// Gets or sets the rotation of this transform.
/// Gets or sets the rotation of this transform.
/// </summary>
/// <value>
/// The rotation of this transform.
/// The rotation of this transform.
/// </value>
public Quaternion Rotation { get; set; }

/// <summary>
/// Gets or sets the scale.
/// Gets or sets the scale.
/// </summary>
/// <value>
/// The scale.
/// The scale.
/// </value>
public Vector3 Scale { get; set; }

/// <summary>
/// Gets a normalized vector representing the Y-axis of the transform in world space.
/// Gets a normalized vector representing the Y-axis of the transform in world space.
/// </summary>
/// <value>
/// The normalized vector representing the negative Y-axis of the transform in world space.
/// The normalized vector representing the negative Y-axis of the transform in world space.
/// </value>
public Vector3 Up
{
get { return Vector3.Normalize(Vector3.Transform(Vector3.UnitY, this.Rotation)); }
}

/// <summary>
/// Creates the transformation matrix for this transform.
/// Creates the transformation matrix for this transform.
/// </summary>
/// <returns>
/// The newly create <see cref="Matrix4x4"/> that represents the transformation matrix for this transform.
/// The newly create <see cref="Matrix4x4"/> that represents the transformation matrix for this transform.
/// </returns>
public Matrix4x4 CreateTransformationMatrix()
{
Expand All @@ -126,27 +128,27 @@ public Matrix4x4 CreateTransformationMatrix()
}

/// <summary>
/// Creates the view matrix for this transform.
/// Creates the view matrix for this transform.
/// </summary>
/// <param name="cameraUp">
/// The camera up vector.
/// The camera up vector.
/// </param>
/// <returns>
/// The newly created <see cref="Matrix4x4"/> that represents the view matrix for this transform.
/// The newly created <see cref="Matrix4x4"/> that represents the view matrix for this transform.
/// </returns>
public Matrix4x4 CreateViewMatrix(Vector3 cameraUp)
{
return Matrix4x4.CreateLookAt(this.Position, this.Position + this.Forward, cameraUp);
}

/// <summary>
/// Rotates this transform on the specified <paramref name="axis"/> by the specified <paramref name="radians"/>.
/// Rotates this transform on the specified <paramref name="axis"/> by the specified <paramref name="radians"/>.
/// </summary>
/// <param name="axis">
/// The axis to rotate.
/// The axis to rotate.
/// </param>
/// <param name="radians">
/// The radians that represents the amount to rotate by.
/// The radians that represents the amount to rotate by.
/// </param>
public void Rotate(Vector3 axis, float radians)
{
Expand All @@ -155,13 +157,13 @@ public void Rotate(Vector3 axis, float radians)
}

/// <summary>
/// Translates this transform in the specified <paramref name="direction"/> by the specified <paramref name="amount"/>.
/// Translates this transform in the specified <paramref name="direction"/> by the specified <paramref name="amount"/>.
/// </summary>
/// <param name="direction">
/// The direction to translate.
/// The direction to translate.
/// </param>
/// <param name="amount">
/// The amount to translate.
/// The amount to translate.
/// </param>
public void Translate(Vector3 direction, float amount)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Platforms>x64</Platforms>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion FinalEngine.Editor.Common/FinalEngine.Editor.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Platforms>x64</Platforms>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 11 additions & 11 deletions FinalEngine.Editor.Common/Models/Scenes/Scene.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="Scene.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Models.Scenes;
Expand All @@ -14,36 +14,36 @@ namespace FinalEngine.Editor.Common.Models.Scenes;
using Microsoft.Extensions.Logging;

/// <summary>
/// Represents a scene that contains a collection of entities and systems.
/// Represents a scene that contains a collection of entities and systems.
/// </summary>
public sealed class Scene : IScene
{
/// <summary>
/// The entities contained within the scene.
/// The entities contained within the scene.
/// </summary>
private readonly ObservableCollection<Entity> entities;

/// <summary>
/// The logger.
/// The logger.
/// </summary>
private readonly ILogger<Scene> logger;

/// <summary>
/// The underlying entity world that contains all the scenes entities and systems.
/// The underlying entity world that contains all the scenes entities and systems.
/// </summary>
private readonly IEntityWorld world;

/// <summary>
/// Initializes a new instance of the <see cref="Scene"/> class.
/// Initializes a new instance of the <see cref="Scene"/> class.
/// </summary>
/// <param name="logger">
/// The logger.
/// The logger.
/// </param>
/// <param name="world">
/// The entity world to be associated with this scene.
/// The entity world to be associated with this scene.
/// </param>
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="logger"/> or <paramref name="world"/> parameter cannot be null.
/// The specified <paramref name="logger"/> or <paramref name="world"/> parameter cannot be null.
/// </exception>
public Scene(ILogger<Scene> logger, IEntityWorld world)
{
Expand All @@ -60,7 +60,7 @@ public IReadOnlyCollection<Entity> Entities

/// <inheritdoc/>
/// <exception cref="ArgumentException">
/// The specified <paramref name="tag"/> parameter cannot be null or whitespace.
/// The specified <paramref name="tag"/> parameter cannot be null or whitespace.
/// </exception>
public void AddEntity(string tag, Guid uniqueID)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public void AddEntity(string tag, Guid uniqueID)

/// <inheritdoc/>
/// <exception cref="ArgumentException">
/// Failed to locate an <see cref="Entity"/> that matches the specified <paramref name="uniqueIdentifier"/>.
/// Failed to locate an <see cref="Entity"/> that matches the specified <paramref name="uniqueIdentifier"/>.
/// </exception>
public void RemoveEntity(Guid uniqueIdentifier)
{
Expand Down
Loading

0 comments on commit c2bb7ba

Please sign in to comment.