Skip to content

Commit

Permalink
Added editor back
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareantics committed Jan 1, 2024
1 parent f5f9b15 commit a6261b4
Show file tree
Hide file tree
Showing 221 changed files with 4,823 additions and 647 deletions.
12 changes: 6 additions & 6 deletions FinalEngine.ECS/Components/Core/TagComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ namespace FinalEngine.ECS.Components.Core;
[Category("Core")]
public sealed class TagComponent : IEntityComponent, INotifyPropertyChanged
{
private string? tag;
private string? name;

public event PropertyChangedEventHandler? PropertyChanged;

public string? Tag
public string? Name
{
get
{
return this.tag;
return this.name;
}

set
{
if (this.tag == value)
if (this.name == value)
{
return;
}

this.tag = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Tag)));
this.name = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Name)));
}
}
}
4 changes: 0 additions & 4 deletions FinalEngine.ECS/FinalEngine.ECS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Folder Include="Components\Core\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <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;

[ExcludeFromCodeCoverage(Justification = "Extensions")]
public static class ServiceCollectionExtensions
{
public static void AddFactory<TService, TImplementation>(this IServiceCollection services)
where TService : class
where TImplementation : class, TService
{
ArgumentNullException.ThrowIfNull(services, nameof(services));

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

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

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<AnalysisMode>All</AnalysisMode>
<NoWarn>SA0001</NoWarn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Platforms>x64</Platforms>
</PropertyGroup>

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

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

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.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="20.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FinalEngine.ECS\FinalEngine.ECS.csproj" />
<ProjectReference Include="..\FinalEngine.Rendering.Components\FinalEngine.Rendering.Components.csproj" />
<ProjectReference Include="..\FinalEngine.Rendering\FinalEngine.Rendering.csproj" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions FinalEngine.Editor.Common/Models/Scenes/IScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// <copyright file="IScene.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 FinalEngine.ECS;

public interface IScene
{
IReadOnlyCollection<Entity> Entities { get; }

void AddEntity(string tag, Guid uniqueID);

void RemoveEntity(Guid uniqueIdentifier);

void Render();
}
83 changes: 83 additions & 0 deletions FinalEngine.Editor.Common/Models/Scenes/Scene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// <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 System.Linq;
using FinalEngine.ECS;
using FinalEngine.ECS.Components.Core;
using FinalEngine.ECS.Exceptions;
using FinalEngine.Rendering.Components.Core;
using Microsoft.Extensions.Logging;

public sealed class Scene : IScene
{
private readonly ObservableCollection<Entity> entities;

private readonly ILogger<Scene> logger;

private readonly IEntityWorld world;

public Scene(ILogger<Scene> logger, IEntityWorld world)
{
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
this.world = world ?? throw new ArgumentNullException(nameof(world));
this.entities = [];
}

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

public void AddEntity(string tag, Guid uniqueID)
{
this.logger.LogInformation($"Adding new {nameof(Entity)} to {nameof(Scene)} with ID: '{uniqueID}'.");

ArgumentException.ThrowIfNullOrWhiteSpace(tag, nameof(tag));

var entity = new Entity(uniqueID);

entity.AddComponent(new TagComponent()
{
Name = tag,
});

entity.AddComponent(new TransformComponent());

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

this.logger.LogInformation($"Added {nameof(Entity)} to {nameof(Scene)} with ID: '{uniqueID}'.");
}

public void RemoveEntity(Guid uniqueIdentifier)
{
this.logger.LogInformation($"Removing {nameof(Entity)} from {nameof(Scene)} with ID: '{uniqueIdentifier}'.");

var entity = this.entities.FirstOrDefault(x =>
{
return x.UniqueIdentifier == uniqueIdentifier;
});

if (entity == null)
{
this.logger.LogError($"Failed to locate entity with ID: '{uniqueIdentifier}'.");
throw new EntityNotFoundException(uniqueIdentifier);
}

this.world.RemoveEntity(entity);
this.entities.Remove(entity);

this.logger.LogInformation($"Removed {nameof(Entity)} from {nameof(Scene)} with ID: '{uniqueIdentifier}'.");
}

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,48 @@
// <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;

public sealed class ApplicationContext : IApplicationContext
{
private readonly IEnvironmentContext environment;

private readonly IFileSystem fileSystem;

public ApplicationContext(IFileSystem fileSystem, IEnvironmentContext environment)
{
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.environment = environment ?? throw new ArgumentNullException(nameof(environment));
}

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;
}
}

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

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

namespace FinalEngine.Editor.Common.Services.Application;

using System;

public interface IApplicationContext
{
string DataDirectory { get; }

string Title { get; }

Version Version { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// <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;

[ExcludeFromCodeCoverage(Justification = "Invocation")]
public sealed class EnvironmentContext : IEnvironmentContext
{
public string GetFolderPath(Environment.SpecialFolder folder)
{
return Environment.GetFolderPath(folder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// <copyright file="IEnvironmentContext.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Environment;

using System;

public interface IEnvironmentContext
{
string GetFolderPath(Environment.SpecialFolder folder);
}
22 changes: 22 additions & 0 deletions FinalEngine.Editor.Common/Services/Factories/Factory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <copyright file="Factory.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Factories;

using System;

public sealed class Factory<T> : IFactory<T>
{
private readonly Func<T> factory;

public Factory(Func<T> factory)
{
this.factory = factory ?? throw new ArgumentNullException(nameof(factory));
}

public T Create()
{
return this.factory();
}
}
10 changes: 10 additions & 0 deletions FinalEngine.Editor.Common/Services/Factories/IFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// <copyright file="IFactory.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Factories;

public interface IFactory<out T>
{
T Create();
}
12 changes: 12 additions & 0 deletions FinalEngine.Editor.Common/Services/Scenes/ISceneManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// <copyright file="ISceneManager.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Scenes;

using FinalEngine.Editor.Common.Models.Scenes;

public interface ISceneManager
{
IScene ActiveScene { get; }
}
10 changes: 10 additions & 0 deletions FinalEngine.Editor.Common/Services/Scenes/ISceneRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// <copyright file="ISceneRenderer.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Editor.Common.Services.Scenes;

public interface ISceneRenderer
{
void Render();
}
Loading

0 comments on commit a6261b4

Please sign in to comment.