Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Entity Component to Entities via EntityInspectorView #295

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 48 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 @@ -8,42 +8,78 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Numerics;
using FinalEngine.ECS;
using FinalEngine.ECS.Components.Core;
using FinalEngine.Editor.Common.Exceptions.Entities;
using Microsoft.Extensions.Logging;

public class SomeComponent : IEntityComponent

Check warning on line 17 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent'

Check warning on line 17 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent'

Check warning on line 17 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent'
softwareantics marked this conversation as resolved.
Show resolved Hide resolved
{
public string Float { get; set; }

Check warning on line 19 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Non-nullable property 'Float' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 19 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Float'

Check warning on line 19 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Non-nullable property 'Float' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 19 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Float'

Check warning on line 19 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Non-nullable property 'Float' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 19 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Float'

public string Float2 { get; set; }

Check warning on line 21 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Non-nullable property 'Float2' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 21 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Float2'

Check warning on line 21 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Non-nullable property 'Float2' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 21 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Float2'

Check warning on line 21 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Non-nullable property 'Float2' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 21 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Float2'

public Vector2 Vector10 { get; set; }

Check warning on line 23 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Vector10'

Check warning on line 23 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Vector10'

Check warning on line 23 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Vector10'

public Vector2 Vector11 { get; set; }

Check warning on line 25 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Vector11'

Check warning on line 25 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Vector11'

Check warning on line 25 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Vector11'

public Vector2 Vector12 { get; set; }

Check warning on line 27 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Vector12'

Check warning on line 27 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Vector12'

Check warning on line 27 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Vector12'

public Vector2 Vector13 { get; set; }

Check warning on line 29 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Vector13'

Check warning on line 29 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Vector13'

Check warning on line 29 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Vector13'

public Vector2 Vector14 { get; set; }

Check warning on line 31 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_common

Missing XML comment for publicly visible type or member 'SomeComponent.Vector14'

Check warning on line 31 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_desktop

Missing XML comment for publicly visible type or member 'SomeComponent.Vector14'

Check warning on line 31 in FinalEngine.Editor.Common/Models/Scenes/Scene.cs

View workflow job for this annotation

GitHub Actions / build_editor_view_models

Missing XML comment for publicly visible type or member 'SomeComponent.Vector14'

public Vector2 Vector15 { get; set; }

public Vector2 Vector2 { get; set; }

public Vector2 Vector3 { get; set; }

public Vector2 Vector4 { get; set; }

public Vector2 Vector5 { get; set; }

public Vector2 Vector6 { get; set; }

public Vector2 Vector7 { get; set; }

public Vector2 Vector8 { get; set; }

public Vector2 Vector9 { get; set; }
}

/// <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 +96,7 @@

/// <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 All @@ -79,6 +115,7 @@
});

entity.AddComponent(new TransformComponent());
entity.AddComponent(new SomeComponent());

this.world.AddEntity(entity);
this.entities.Add(entity);
Expand All @@ -88,7 +125,7 @@

/// <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
Loading