Skip to content

Commit

Permalink
[EPIC] Editor (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareantics committed Aug 15, 2023
1 parent 0d9fed9 commit 5e8ed3f
Show file tree
Hide file tree
Showing 122 changed files with 6,416 additions and 26 deletions.
2 changes: 1 addition & 1 deletion FinalEngine.ECS/IEntityWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace FinalEngine.ECS;
/// <summary>
/// Defines an interface that creates the connection between <see cref="Entity"/> and <see cref="EntitySystemBase"/>.
/// </summary>
public interface IEntityWorld
public interface IEntityWorld : IEntitySystemsProcessor
{
/// <summary>
/// Adds the specified <paramref name="entity"/> to this <see cref="IEntityWorld"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// <copyright file="ServiceCollectionExtensions.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Extensions;

using System;
using System.Diagnostics.CodeAnalysis;
using FinalEngine.Editor.Common.Services.Factories;
using Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Provides extension methods for an <see cref="IServiceCollection"/>.
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Extensions")]
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds an <see cref="IFactory{T}"/> that can create a <typeparamref name="TService"/> to the specified <paramref name="services"/>.
/// </summary>
/// <typeparam name="TService">
/// The type of the service to register.
/// </typeparam>
/// <typeparam name="TImplementation">
/// The type of service implementation.
/// </typeparam>
/// <param name="services">
/// The <see cref="IServiceCollection"/> used to register the service.
/// </param>
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="services"/> parameter cannot be null.
/// </exception>
public static void AddFactory<TService, TImplementation>(this IServiceCollection services)
where TService : class
where TImplementation : class, TService
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}

services.AddTransient<TService, TImplementation>();
services.AddSingleton<Func<TService>>(x =>
{
return () =>
{
return x.GetRequiredService<TService>();
};
});

services.AddSingleton<IFactory<TService>, Factory<TService>>();
}
}
38 changes: 38 additions & 0 deletions FinalEngine.Editor.Common/FinalEngine.Editor.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<AnalysisMode>All</AnalysisMode>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Platforms>x64</Platforms>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\Styling\StyleCop\Other\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions" Version="19.2.29" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FinalEngine.ECS\FinalEngine.ECS.csproj" />
<ProjectReference Include="..\FinalEngine.Rendering\FinalEngine.Rendering.csproj" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions FinalEngine.Editor.Common/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// <copyright file="GlobalSuppressions.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "KISS")]
[assembly: SuppressMessage("Usage", "CA2254:Template should be a static expression", Justification = "KISS")]
35 changes: 35 additions & 0 deletions FinalEngine.Editor.Common/Models/Scenes/IScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <copyright file="IScene.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Models.Scenes;

using System.Collections.Generic;
using FinalEngine.ECS;

/// <summary>
/// Defines an interface that represents a scene.
/// </summary>
public interface IScene
{
/// <summary>
/// Gets the entities contained within this scene.
/// </summary>
/// <value>
/// The entities contained within this scene.
/// </value>
IReadOnlyCollection<Entity> Entities { get; }

/// <summary>
/// Adds the specified <paramref name="entity"/> to the scene.
/// </summary>
/// <param name="entity">
/// The entity to be added.
/// </param>
void AddEntity(Entity entity);

/// <summary>
/// Renders the scene, processing all rendering systems.
/// </summary>
void Render();
}
68 changes: 68 additions & 0 deletions FinalEngine.Editor.Common/Models/Scenes/Scene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// <copyright file="Scene.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Models.Scenes;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using FinalEngine.ECS;

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

/// <summary>
/// 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.
/// </summary>
/// <param name="world">
/// The entity world to be associated with this scene.
/// </param>
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="world"/> parameter cannot be null.
/// </exception>
public Scene(IEntityWorld world)
{
this.world = world ?? throw new ArgumentNullException(nameof(world));
this.entities = new ObservableCollection<Entity>();
}

/// <inheritdoc/>
public IReadOnlyCollection<Entity> Entities
{
get { return this.entities; }
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="entity"/> parameter cannot be null.
/// </exception>
public void AddEntity(Entity entity)
{
if (entity == null)
{
throw new ArgumentNullException(nameof(entity));
}

this.world.AddEntity(entity);
this.entities.Add(entity);
}

/// <inheritdoc/>
public void Render()
{
this.world.ProcessAll(GameLoopType.Render);
}
}
13 changes: 13 additions & 0 deletions FinalEngine.Editor.Common/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="AssemblyInfo.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: AssemblyTitle("FinalEngine.Editor.Common")]
[assembly: AssemblyDescription("A common library containing services to connect view models to view for the Final Engine editor.")]
[assembly: Guid("3D606010-8CAF-4781-98D1-EB67BCDD8CC1")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// <copyright file="ApplicationContext.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Application;

using System;
using System.IO.Abstractions;
using System.Reflection;
using FinalEngine.Editor.Common.Services.Environment;

/// <summary>
/// Provides a standard implementation of an <see cref="IApplicationContext"/>.
/// </summary>
/// <seealso cref="IApplicationContext" />
public sealed class ApplicationContext : IApplicationContext
{
/// <summary>
/// The environment service, used when locating the applications local data directory.
/// </summary>
private readonly IEnvironmentContext environment;

/// <summary>
/// The file system service, used to potentially create the applications local data directory.
/// </summary>
private readonly IFileSystem fileSystem;

/// <summary>
/// Initializes a new instance of the <see cref="ApplicationContext"/> class.
/// </summary>
/// <param name="fileSystem">
/// The file system service, used to create the required directories for <see cref="DataDirectory"/>, if required.
/// </param>
/// <param name="environment">
/// The environment, used to locate the application data folder for the local user.
/// </param>
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="fileSystem"/> or <paramref name="environment"/> parameter cannot be null.
/// </exception>
public ApplicationContext(IFileSystem fileSystem, IEnvironmentContext environment)
{
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.environment = environment ?? throw new ArgumentNullException(nameof(environment));
}

/// <inheritdoc/>
/// <remarks>
/// Accessing <see cref="DataDirectory"/> will ensure the applications data directory is created before returning it's location.
/// </remarks>
public string DataDirectory
{
get
{
string directory = this.fileSystem.Path.Combine(this.environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Final Engine");

if (!this.fileSystem.Directory.Exists(directory))
{
this.fileSystem.Directory.CreateDirectory(directory);
}

return directory;
}
}

/// <inheritdoc/>
public string Title
{
get { return $"Final Engine - {this.Version}"; }
}

/// <inheritdoc/>
public Version Version
{
get { return Assembly.GetExecutingAssembly().GetName().Version!; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <copyright file="IApplicationContext.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Application;

using System;

/// <summary>
/// Defines an interface that represents contextual information related to the current application and it's associated data.
/// </summary>
public interface IApplicationContext
{
/// <summary>
/// Gets the directory that serves as a common repository for Final Engine application-specific data for the current local user.
/// </summary>
/// <value>
/// The directory that serves as a common repository for application-specific data for the current local user.
/// </value>
string DataDirectory { get; }

/// <summary>
/// Gets the title of the application.
/// </summary>
/// <value>
/// The title of the application, suffixed by the <see cref="Version"/>.
/// </value>
string Title { get; }

/// <summary>
/// Gets the version of the application.
/// </summary>
/// <value>
/// The assembly version of the application.
/// </value>
Version Version { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <copyright file="EnvironmentContext.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Environment;

using System;
using System.Diagnostics.CodeAnalysis;

/// <summary>
/// Provides a standard implementation of an <see cref="IEnvironmentContext"/>.
/// </summary>
/// <seealso cref="IEnvironmentContext" />
[ExcludeFromCodeCoverage]
public sealed class EnvironmentContext : IEnvironmentContext
{
/// <inheritdoc/>
public string GetFolderPath(Environment.SpecialFolder folder)
{
return Environment.GetFolderPath(folder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// <copyright file="IEnvironmentContext.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Environment;

using System;

/// <summary>
/// Defines an interface that provides information about the current environment and platform.
/// </summary>
public interface IEnvironmentContext
{
/// <inheritdoc cref="Environment.GetFolderPath(Environment.SpecialFolder)"/>/>
string GetFolderPath(Environment.SpecialFolder folder);
}
Loading

0 comments on commit 5e8ed3f

Please sign in to comment.