diff --git a/MonoGame.sln b/MonoGame.sln index f9cc9d1..cc61ecc 100644 --- a/MonoGame.sln +++ b/MonoGame.sln @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Monogame.ImGuiNet", "src\Li EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompositionRoots", "src\Libs\CompositionRoots\CompositionRoots.csproj", "{53310E88-636A-4CA2-A1C8-D1C3FF8B5A61}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Constants", "src\Libs\Constants\Constants.csproj", "{B2BD6683-41F9-414C-AD9C-7F6B4E22B5DC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -108,6 +110,10 @@ Global {53310E88-636A-4CA2-A1C8-D1C3FF8B5A61}.Debug|Any CPU.Build.0 = Debug|Any CPU {53310E88-636A-4CA2-A1C8-D1C3FF8B5A61}.Release|Any CPU.ActiveCfg = Release|Any CPU {53310E88-636A-4CA2-A1C8-D1C3FF8B5A61}.Release|Any CPU.Build.0 = Release|Any CPU + {B2BD6683-41F9-414C-AD9C-7F6B4E22B5DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2BD6683-41F9-414C-AD9C-7F6B4E22B5DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2BD6683-41F9-414C-AD9C-7F6B4E22B5DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2BD6683-41F9-414C-AD9C-7F6B4E22B5DC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5E3B6238-A92E-4703-8527-1C2410D7906A} = {F5258F7E-B0BA-466D-8CF8-4DAB84722BE3} @@ -127,5 +133,6 @@ Global {B7BAA8DC-A62F-4746-B6C4-9908C0AFD30A} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA} {62A786A2-BC48-453E-8185-01A403B15159} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E} {53310E88-636A-4CA2-A1C8-D1C3FF8B5A61} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA} + {B2BD6683-41F9-414C-AD9C-7F6B4E22B5DC} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA} EndGlobalSection EndGlobal diff --git a/src/Apps/GameDesktop/Builders/ConfigurationBuilder.cs b/src/Apps/GameDesktop/Builders/ConfigurationBuilder.cs new file mode 100644 index 0000000..60e238a --- /dev/null +++ b/src/Apps/GameDesktop/Builders/ConfigurationBuilder.cs @@ -0,0 +1,22 @@ +using System; +using System.IO; +using Constants; +using Microsoft.Extensions.Configuration; + +namespace GameDesktop.Builders; + +internal static class ConfigurationBuilder +{ + private static string BasePath => Directory.GetParent(AppContext.BaseDirectory)!.FullName; + + private static string InEnvironment => + Environment.GetEnvironmentVariable(EnvironmentNames.DotNetEnvironment) ?? "Production"; + + public static IConfigurationRoot Create() => + new Microsoft.Extensions.Configuration.ConfigurationBuilder() + .SetBasePath(BasePath) + .AddJsonFile($"{AppVariables.SettingsFileName}.json", optional: false, reloadOnChange: true) + .AddJsonFile($"{AppVariables.SettingsFileName}.{InEnvironment}.json", optional: true) + .AddEnvironmentVariables() + .Build(); +} diff --git a/src/Apps/GameDesktop/Factories/LogFactory.cs b/src/Apps/GameDesktop/Builders/LoggerBuilder.cs similarity index 79% rename from src/Apps/GameDesktop/Factories/LogFactory.cs rename to src/Apps/GameDesktop/Builders/LoggerBuilder.cs index a6b3c69..b2f4d5f 100644 --- a/src/Apps/GameDesktop/Factories/LogFactory.cs +++ b/src/Apps/GameDesktop/Builders/LoggerBuilder.cs @@ -2,9 +2,9 @@ using Serilog; using Serilog.Core; -namespace GameDesktop.Factories; +namespace GameDesktop.Builders; -internal static class LogFactory +internal static class LoggerBuilder { public static Logger Create(IConfiguration configuration) => new LoggerConfiguration() diff --git a/src/Apps/GameDesktop/Factories/UIFactory.cs b/src/Apps/GameDesktop/Builders/UIBuilder.cs similarity index 90% rename from src/Apps/GameDesktop/Factories/UIFactory.cs rename to src/Apps/GameDesktop/Builders/UIBuilder.cs index 49f48c2..7ed2941 100644 --- a/src/Apps/GameDesktop/Factories/UIFactory.cs +++ b/src/Apps/GameDesktop/Builders/UIBuilder.cs @@ -1,8 +1,8 @@ using Myra.Graphics2D.UI; -namespace GameDesktop.Factories; +namespace GameDesktop.Builders; -public class UIFactory(Grid grid, Label label, ComboBox comboBox, Button button, SpinButton spinButton) +public class UIBuilder(Grid grid, Label label, ComboBox comboBox, Button button, SpinButton spinButton) { // Stylesheet.Current.ButtonStyle = new ButtonStyle // { diff --git a/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs deleted file mode 100644 index c70fb7c..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs +++ /dev/null @@ -1,27 +0,0 @@ -// using Features.Debugging; - -using LightInject; -using MonoGame.ImGuiNet; - -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.DebugFeatures.DebugRootFeatureCompositionRoot))] -namespace GameDesktop.CompositionRoots.DebugFeatures; - -internal class DebugRootFeatureCompositionRoot : ICompositionRoot -{ - public void Compose(IServiceRegistry serviceRegistry) - { - RegisterSystems(serviceRegistry); - // RegisterFeature(serviceRegistry); - } - - private static void RegisterSystems(IServiceRegistry serviceRegistry) - { - // serviceRegistry.RegisterSingleton(factory => - // { - // return new DrawRectangleCollisionComponentsSystem(factory.GetInstance()); - // }); - } - - // private static void RegisterFeature(IServiceRegistry serviceRegistry) => - // serviceRegistry.RegisterSingleton(); -} diff --git a/src/Apps/GameDesktop/CompositionRoots/Entities/PlayerEntityCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Entities/PlayerEntityCompositionRoot.cs deleted file mode 100644 index 6f9ffcb..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Entities/PlayerEntityCompositionRoot.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Components.Data; -using Components.Render.Animation; -using Components.Tags; -using LightInject; - -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Entities.PlayerEntityCompositionRoot))] - -namespace GameDesktop.CompositionRoots.Entities; - -internal class PlayerEntityCompositionRoot : ICompositionRoot -{ - public void Compose(IServiceRegistry serviceRegistry) - { - // RegisterEntity(serviceRegistry); - } - - // private static void RegisterEntity(IServiceRegistry serviceRegistry) => - // serviceRegistry.RegisterTransient(factory => new PlayerEntityFactory( - // new NameComponent("Player"), // factory.GetInstance("Player"), - // factory.GetInstance(), - // factory.GetInstance(), - // factory.GetInstance("PlayerEntity"), - // factory.GetInstance(), - // factory.GetInstance("PlayerEntity"), - // factory.GetInstance(), - // factory.GetInstance("PlayerEntity"), - // factory.GetInstance())); -} diff --git a/src/Apps/GameDesktop/CompositionRoots/Entities/RockEntityCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Entities/RockEntityCompositionRoot.cs deleted file mode 100644 index 95ab0ff..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Entities/RockEntityCompositionRoot.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Components.Data; -using Components.Render.Static; -using Entities.Factories.Items; -using LightInject; - -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Entities.RockEntityCompositionRoot))] -namespace GameDesktop.CompositionRoots.Entities; - -public class RockEntityCompositionRoot : ICompositionRoot -{ - public void Compose(IServiceRegistry serviceRegistry) - { - // RegisterEntity(serviceRegistry); - } - - - // private static void RegisterEntity(IServiceRegistry serviceRegistry) => - // serviceRegistry.RegisterTransient(factory => new RockEntityFactory( - // new NameComponent("Rock"), // factory.GetInstance("Rock") - // factory.GetInstance("Rock"), - // factory.GetInstance("RockEntity"), - // factory.GetInstance() //factory.GetInstance("Rock") - // )); -} diff --git a/src/Apps/GameDesktop/CompositionRoots/Entities/StaticEntityCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Entities/StaticEntityCompositionRoot.cs deleted file mode 100644 index e76d37c..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Entities/StaticEntityCompositionRoot.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Components.Data; -using Components.Render.Static; -using LightInject; - -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Entities.StaticEntityCompositionRoot))] - -namespace GameDesktop.CompositionRoots.Entities; - -internal class StaticEntityCompositionRoot : ICompositionRoot -{ - public void Compose(IServiceRegistry serviceRegistry) - { - // RegisterEntity(serviceRegistry); - } - - - // private static void RegisterEntity(IServiceRegistry serviceRegistry) => - // serviceRegistry.RegisterTransient(factory => new DummyEntityFactory( - // new NameComponent("Dummy"), // factory.GetInstance("Dummy") - // factory.GetInstance("DummyEntity"), - // factory.GetInstance(), - // factory.GetInstance("DummyEntity"))); -} diff --git a/src/Apps/GameDesktop/CompositionRoots/Features/CameraFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Features/CameraFeatureCompositionRoot.cs deleted file mode 100644 index 81a3e73..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Features/CameraFeatureCompositionRoot.cs +++ /dev/null @@ -1,36 +0,0 @@ -// using System; -// using Entitas; -// using Entitas.Extended; -// using Features; -// using GameDesktop.Resources.Internal; -// using LightInject; -// using Systems; -// -// namespace GameDesktop.CompositionRoots.Features; -// -// internal class CameraFeatureCompositionRoot : ICompositionRoot -// { -// private static readonly IMatcher[] Matchers = { GameMatcher.Transform, GameMatcher.Drawable }; -// -// public void Compose(IServiceRegistry serviceRegistry) -// { -// RegisterSystem(serviceRegistry); -// RegisterFeature(serviceRegistry); -// } -// -// private static void RegisterSystem(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(factory => -// { -// var getGroup = -// factory.GetInstance[], IGroup>>(Matcher.AllOf); -// IGroup group = getGroup(Matchers); -// -// // return new CameraFollowingSystem(factory.GetInstance(), group); -// return new DefaultDrawSystem(group); -// }); -// } -// -// private static void RegisterFeature(IServiceRegistry serviceRegistry) => -// serviceRegistry.RegisterSingleton(); -// } diff --git a/src/Apps/GameDesktop/CompositionRoots/Features/InputFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Features/InputFeatureCompositionRoot.cs deleted file mode 100644 index de11420..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Features/InputFeatureCompositionRoot.cs +++ /dev/null @@ -1,46 +0,0 @@ -// using System; -// using Entitas; -// using Features; -// using GameDesktop.Resources.Internal; -// using LightInject; -// using Serilog; -// using Services.Input; -// using Systems; -// -// namespace GameDesktop.CompositionRoots.Features; -// -// internal class InputFeatureCompositionRoot : ICompositionRoot -// { -// private static readonly IMatcher[] Matchers = -// { -// GameMatcher.Transform, GameMatcher.Movable, GameMatcher.Player -// }; -// -// public void Compose(IServiceRegistry serviceRegistry) -// { -// RegisterImpl(serviceRegistry); -// RegisterSystem(serviceRegistry); -// RegisterFeature(serviceRegistry); -// } -// -// private static void RegisterImpl(IServiceRegistry serviceRegistry) => -// serviceRegistry.RegisterSingleton(); -// -// private static void RegisterSystem(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(factory => -// { -// var inputScanner = factory.GetInstance(); -// -// var getGroup = factory.GetInstance[], IGroup>>(Matcher.AllOf); -// IGroup group = getGroup(Matchers); -// -// var logger = factory.GetInstance(); -// -// return new Systems.InputSystem(inputScanner, group, logger); -// }); -// } -// -// private static void RegisterFeature(IServiceRegistry serviceRegistry) => -// serviceRegistry.RegisterSingleton(); -// } diff --git a/src/Apps/GameDesktop/CompositionRoots/Features/MovementFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Features/MovementFeatureCompositionRoot.cs deleted file mode 100644 index b82a20b..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Features/MovementFeatureCompositionRoot.cs +++ /dev/null @@ -1,74 +0,0 @@ -// using System; -// using Entitas; -// using Features; -// using GameDesktop.Resources.Internal; -// using LightInject; -// using Serilog; -// using Services; -// using Services.Movement; -// using Systems; -// -// namespace GameDesktop.CompositionRoots.Features; -// -// internal class MovementFeatureCompositionRoot : ICompositionRoot -// { -// private static readonly IMatcher[] CollisionMatchers = -// { -// GameMatcher.RectangleCollision, GameMatcher.Transform -// }; -// -// private static readonly IMatcher[] MovableMatchers = { GameMatcher.Transform, GameMatcher.Movable }; -// -// private static readonly IMatcher[] AnimatedMovableMatchers = -// { -// GameMatcher.Movable, GameMatcher.MovementAnimation -// }; -// -// public void Compose(IServiceRegistry serviceRegistry) -// { -// RegisterImpl(serviceRegistry); -// RegisterSystems(serviceRegistry); -// RegisterFeature(serviceRegistry); -// } -// -// private static void RegisterImpl(IServiceRegistry serviceRegistry) => -// serviceRegistry.RegisterSingleton(); -// -// private static void RegisterSystems(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(factory => -// { -// var getGroup = factory.GetInstance[], IGroup>>(Matcher.AllOf); -// IGroup group = getGroup(CollisionMatchers); -// -// var logger = factory.GetInstance(); -// -// return new CollisionSystem(group, logger); -// }); -// -// serviceRegistry.RegisterSingleton(factory => -// { -// var movement = factory.GetInstance(); -// -// var getGroup = factory.GetInstance[], IGroup>>(Matcher.AllOf); -// IGroup group = getGroup(MovableMatchers); -// -// var logger = factory.GetInstance(); -// -// return new MovementSystem(movement, group, logger); -// }); -// -// serviceRegistry.RegisterSingleton(factory => -// { -// var getGroup = factory.GetInstance[], IGroup>>(Matcher.AllOf); -// IGroup group = getGroup(AnimatedMovableMatchers); -// -// var logger = factory.GetInstance(); -// -// return new AnimatedMovementSystem(group, logger); -// }); -// } -// -// private static void RegisterFeature(IServiceRegistry serviceRegistry) => -// serviceRegistry.RegisterSingleton(); -// } diff --git a/src/Apps/GameDesktop/CompositionRoots/Features/WorldInitializeFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Features/WorldInitializeFeatureCompositionRoot.cs deleted file mode 100644 index 4e9ffcd..0000000 --- a/src/Apps/GameDesktop/CompositionRoots/Features/WorldInitializeFeatureCompositionRoot.cs +++ /dev/null @@ -1,15 +0,0 @@ -// using Features; -// using LightInject; -// -// namespace GameDesktop.CompositionRoots.Features; -// -// internal class WorldInitializeFeatureCompositionRoot : ICompositionRoot -// { -// public void Compose(IServiceRegistry serviceRegistry) -// { -// RegisterFeature(serviceRegistry); -// } -// -// private static void RegisterFeature(IServiceRegistry serviceRegistry) => -// serviceRegistry.RegisterSingleton(); -// } diff --git a/src/Apps/GameDesktop/Factories/ConfigurationFactory.cs b/src/Apps/GameDesktop/Factories/ConfigurationFactory.cs deleted file mode 100644 index 2786dad..0000000 --- a/src/Apps/GameDesktop/Factories/ConfigurationFactory.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.IO; -using GameDesktop.Resources.Internal; -using Microsoft.Extensions.Configuration; - -namespace GameDesktop.Factories; - -internal static class ConfigurationFactory -{ - private static string BasePath => Directory.GetParent(AppContext.BaseDirectory)!.FullName; - - private static string InEnvironment => - Environment.GetEnvironmentVariable(EnvironmentVariable.DotNetEnvironment) ?? "Production"; - - public static IConfigurationRoot Create() => - new ConfigurationBuilder() - .SetBasePath(BasePath) - .AddJsonFile($"{AppVariable.SettingsName}.json", optional: false, reloadOnChange: true) - .AddJsonFile($"{AppVariable.SettingsName}.{InEnvironment}.json", optional: true) - .AddEnvironmentVariables() - .Build(); -} diff --git a/src/Apps/GameDesktop/Game.cs b/src/Apps/GameDesktop/Game.cs index 1e726d6..b42c2ae 100644 --- a/src/Apps/GameDesktop/Game.cs +++ b/src/Apps/GameDesktop/Game.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; +using CompositionRoots; using Features; -using GameDesktop.CompositionRoots.Features; -using GameDesktop.Factories; -using GameDesktop.Resources.Internal; using ImGuiNET; using JetBrains.Annotations; using MonoGame.ImGuiNet; @@ -39,11 +33,8 @@ public class Game : Microsoft.Xna.Framework.Game private GraphicsDeviceManager _graphicsDeviceManager; private Desktop _desktop; - // TODO: Frames updating - // TODO: Player position & other things debug showing, input, etc // TODO: Nez has cool physics & other projects libs to use as deps, ImGUI viewports, solutions, etc. - // https://gafferongames.com/post/fix_your_timestep/ // https://lajbert.wordpress.com/2021/05/02/fix-your-timestep-in-monogame/ private RootFeature _rootFeature; @@ -119,14 +110,19 @@ protected override void Update(GameTime gameTime) float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; _rootFeature.OnUpdate(deltaTime); + FixedUpdate(deltaTime); + + _rootFeature.OnLateUpdate(deltaTime); + } + + private void FixedUpdate(float deltaTime) + { _fixedDeltaTime += deltaTime; while (_fixedDeltaTime >= TargetElapsedTime.TotalSeconds) { _rootFeature.OnFixedUpdate(_fixedDeltaTime); _fixedDeltaTime -= (float)TargetElapsedTime.TotalSeconds; } - - _rootFeature.OnLateUpdate(deltaTime); } protected override void Draw(GameTime gameTime) @@ -166,11 +162,12 @@ private void RegisterWindowSettings() private void RegisterGraphicsDeviceManager() { _graphicsDeviceManager = _container.GetInstance(); + _container.RegisterInstance(GraphicsDevice); } private void RegisterSpriteBatch() { - _container.RegisterSingleton(_ => new SpriteBatch(GraphicsDevice)); + _container.RegisterSingleton(_ => new SpriteBatch(_container.GetInstance())); _spriteBatch = _container.GetInstance(); } @@ -194,7 +191,7 @@ private void RegisterImGuiRenderer() ImGui.GetIO().ConfigFlags = ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable; } - private void RegisterMyraUIEnvironment() => MyraEnvironment.Game = this; + private void RegisterMyraUIEnvironment() => MyraEnvironment.Game = _container.GetInstance(); private void RegisterMyraUI() => _desktop = _container.GetInstance(); } diff --git a/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs b/src/Apps/GameDesktop/GameCompositionRoot.cs similarity index 84% rename from src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs rename to src/Apps/GameDesktop/GameCompositionRoot.cs index 86084f5..412a385 100644 --- a/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs +++ b/src/Apps/GameDesktop/GameCompositionRoot.cs @@ -1,13 +1,14 @@ using System; using System.Linq; -using GameDesktop.Resources.Internal; +using Constants; +using GameDesktop; using LightInject; using Microsoft.Xna.Framework; using Serilog; -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.GameCompositionRoot))] +[assembly: CompositionRootType(typeof(GameCompositionRoot))] -namespace GameDesktop.CompositionRoots; +namespace GameDesktop; internal class GameCompositionRoot : ICompositionRoot { @@ -36,12 +37,12 @@ public void Compose(IServiceRegistry serviceRegistry) IsMouseVisible = IsMouseVisible, IsFixedTimeStep = IsFixedTimeStep, TargetElapsedTime = TimeSpan.FromMilliseconds(SecondInMs / TargetFramesPerSecond), - Content = { RootDirectory = AppVariable.ContentRootDirectory, }, + Content = { RootDirectory = Contents.RootDirectory, }, }; serviceRegistry.RegisterInstance(game); // Hack. Resolving cycle dependency issue (fundamental architecture) - // Implicitly adds itself in the game services container. + // Implicitly adds itself in the game services' container. GraphicsDeviceManager graphicsDeviceManager = new(game) { SynchronizeWithVerticalRetrace = IsVSyncOn, diff --git a/src/Apps/GameDesktop/GameDesktop.csproj b/src/Apps/GameDesktop/GameDesktop.csproj index fe835be..ef1e0c3 100644 --- a/src/Apps/GameDesktop/GameDesktop.csproj +++ b/src/Apps/GameDesktop/GameDesktop.csproj @@ -26,18 +26,6 @@ - - ResXFileCodeGenerator - SpriteSheets.Designer.cs - - - ResXFileCodeGenerator - AppVariable.Designer.cs - - - ResXFileCodeGenerator - EnvironmentVariable.Designer.cs - @@ -59,19 +47,14 @@ + + - - - True - True - SpriteSheet.resx - - Content\%(RecursiveDir)%(FileName)%(Extension) diff --git a/src/Apps/GameDesktop/Program.cs b/src/Apps/GameDesktop/Program.cs index 622313b..ef456a8 100644 --- a/src/Apps/GameDesktop/Program.cs +++ b/src/Apps/GameDesktop/Program.cs @@ -1,20 +1,20 @@ using System; using System.IO; +using Constants; using GameDesktop; -using GameDesktop.CompositionRoots; -using GameDesktop.Factories; -using GameDesktop.Resources.Internal; +using GameDesktop.Builders; using LightInject; using Microsoft.Extensions.Configuration; using Serilog; using Serilog.Core; +using ConfigurationBuilder = GameDesktop.Builders.ConfigurationBuilder; -IConfigurationRoot configuration = ConfigurationFactory.Create(); -Environment.SetEnvironmentVariable(EnvironmentVariable.AppBaseDirectory, +IConfigurationRoot configuration = ConfigurationBuilder.Create(); +Environment.SetEnvironmentVariable(EnvironmentNames.AppBaseDirectory, Directory.GetParent(AppContext.BaseDirectory)!.FullName); -using Logger logger = LogFactory.Create(configuration); -Log.Logger = logger; +using Logger logger = LoggerBuilder.Create(configuration); +Log.Logger = Logger.None; // To disable logging, use this instead: // ILogger logger = Logger.None; @@ -48,10 +48,7 @@ catch (Exception e) { #if IS_CI - if (e.Message.Contains(Error.FailedToCreateGraphicsDevice)) - { - Environment.Exit(0); - } + if (e.Message.Contains(Errors.FailedToCreateGraphicsDevice)) Environment.Exit(0); #endif logger.ForContext().Fatal(e.ToString()); diff --git a/src/Apps/GameDesktop/Resources/Internal/AppVariable.Designer.cs b/src/Apps/GameDesktop/Resources/Internal/AppVariable.Designer.cs deleted file mode 100644 index 06598d4..0000000 --- a/src/Apps/GameDesktop/Resources/Internal/AppVariable.Designer.cs +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace GameDesktop.Resources.Internal { - using System; - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [System.Diagnostics.DebuggerNonUserCodeAttribute()] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class AppVariable { - - private static System.Resources.ResourceManager resourceMan; - - private static System.Globalization.CultureInfo resourceCulture; - - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal AppVariable() { - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Resources.ResourceManager ResourceManager { - get { - if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("GameDesktop.Resources.Internal.AppVariable", typeof(AppVariable).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - internal static string SettingsName { - get { - return ResourceManager.GetString("SettingsName", resourceCulture); - } - } - - internal static string ContentRootDirectory { - get { - return ResourceManager.GetString("ContentRootDirectory", resourceCulture); - } - } - } -} diff --git a/src/Apps/GameDesktop/Resources/Internal/AppVariable.resx b/src/Apps/GameDesktop/Resources/Internal/AppVariable.resx deleted file mode 100644 index 4435433..0000000 --- a/src/Apps/GameDesktop/Resources/Internal/AppVariable.resx +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - appsettings - - - Content - - \ No newline at end of file diff --git a/src/Apps/GameDesktop/Resources/Internal/EnvironmentVariable.Designer.cs b/src/Apps/GameDesktop/Resources/Internal/EnvironmentVariable.Designer.cs deleted file mode 100644 index 2fc0e25..0000000 --- a/src/Apps/GameDesktop/Resources/Internal/EnvironmentVariable.Designer.cs +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace GameDesktop.Resources.Internal { - using System; - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [System.Diagnostics.DebuggerNonUserCodeAttribute()] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class EnvironmentVariable { - - private static System.Resources.ResourceManager resourceMan; - - private static System.Globalization.CultureInfo resourceCulture; - - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal EnvironmentVariable() { - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Resources.ResourceManager ResourceManager { - get { - if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("GameDesktop.Resources.Internal.EnvironmentVariable", typeof(EnvironmentVariable).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - internal static string AppBaseDirectory { - get { - return ResourceManager.GetString("AppBaseDirectory", resourceCulture); - } - } - - internal static string DotNetEnvironment { - get { - return ResourceManager.GetString("DotNetEnvironment", resourceCulture); - } - } - } -} diff --git a/src/Apps/GameDesktop/Resources/Internal/EnvironmentVariable.resx b/src/Apps/GameDesktop/Resources/Internal/EnvironmentVariable.resx deleted file mode 100644 index 4ca83cf..0000000 --- a/src/Apps/GameDesktop/Resources/Internal/EnvironmentVariable.resx +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - APP_BASE_DIRECTORY - - - DOTNET_ENVIRONMENT - - \ No newline at end of file diff --git a/src/Apps/GameDesktop/Resources/Internal/Error.Designer.cs b/src/Apps/GameDesktop/Resources/Internal/Error.Designer.cs deleted file mode 100644 index be3d5ce..0000000 --- a/src/Apps/GameDesktop/Resources/Internal/Error.Designer.cs +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace GameDesktop.Resources.Internal { - using System; - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [System.Diagnostics.DebuggerNonUserCodeAttribute()] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Error { - - private static System.Resources.ResourceManager resourceMan; - - private static System.Globalization.CultureInfo resourceCulture; - - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Error() { - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Resources.ResourceManager ResourceManager { - get { - if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("GameDesktop.Resources.Internal.Error", typeof(Error).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - internal static string FailedToCreateGraphicsDevice { - get { - return ResourceManager.GetString("FailedToCreateGraphicsDevice", resourceCulture); - } - } - } -} diff --git a/src/Apps/GameDesktop/Resources/Internal/Error.resx b/src/Apps/GameDesktop/Resources/Internal/Error.resx deleted file mode 100644 index 3df0b70..0000000 --- a/src/Apps/GameDesktop/Resources/Internal/Error.resx +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - Failed to create graphics device! - \ No newline at end of file diff --git a/src/Apps/GameDesktop/Resources/SpriteSheet.Designer.cs b/src/Apps/GameDesktop/Resources/SpriteSheet.Designer.cs deleted file mode 100644 index b535061..0000000 --- a/src/Apps/GameDesktop/Resources/SpriteSheet.Designer.cs +++ /dev/null @@ -1,54 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace GameDesktop.Resources { - using System; - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [System.Diagnostics.DebuggerNonUserCodeAttribute()] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class SpriteSheet { - - private static System.Resources.ResourceManager resourceMan; - - private static System.Globalization.CultureInfo resourceCulture; - - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal SpriteSheet() { - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Resources.ResourceManager ResourceManager { - get { - if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("GameDesktop.Resources.SpriteSheet", typeof(SpriteSheet).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - internal static string Player { - get { - return ResourceManager.GetString("Player", resourceCulture); - } - } - } -} diff --git a/src/Apps/GameDesktop/Resources/SpriteSheet.resx b/src/Apps/GameDesktop/Resources/SpriteSheet.resx deleted file mode 100644 index 1459163..0000000 --- a/src/Apps/GameDesktop/Resources/SpriteSheet.resx +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - - Content/SpriteSheets/Player.aseprite - - \ No newline at end of file diff --git a/src/Libs/CompositionRoots/Components/Class1.cs b/src/Libs/CompositionRoots/Components/Class1.cs deleted file mode 100644 index b929e12..0000000 --- a/src/Libs/CompositionRoots/Components/Class1.cs +++ /dev/null @@ -1,192 +0,0 @@ - -// using LightInject; -// -// [assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Components.ComponentsCompositionRoot))] -// -// namespace GameDesktop.CompositionRoots.Components; -// -// internal class ComponentsCompositionRoot : ICompositionRoot -// { -// private static readonly string PlayerSpriteSheetPath = System.IO.Path.Join( -// Environment.GetEnvironmentVariable(EnvironmentVariable.AppBaseDirectory), -// Resources.SpriteSheet.Player); -// -// public void Compose(IServiceRegistry serviceRegistry) -// { -// RegisterTagComponents(serviceRegistry); -// RegisterDataComponents(serviceRegistry); -// RegisterStaticRenderComponents(serviceRegistry); -// RegisterAnimatedRenderComponents(serviceRegistry); -// -// // Removed camera as it's a system, existing globally and singly -// } -// -// private static void RegisterDataComponents(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.Register((factory, path) => -// { -// var fileName = Path.Join( -// Environment.GetEnvironmentVariable(EnvironmentVariable.AppBaseDirectory), -// path -// ); -// return Texture2D.FromFile(factory.GetInstance().GraphicsDevice, fileName); -// }); -// -// // TODO: Automatically get texture & its rect from a tile set (by aseprite?) -// serviceRegistry.RegisterSingleton(factory => -// { -// var texture = factory.GetInstance("Content/SpriteSheets/Main.png"); -// var sprite = new Sprite("Pebble", new TextureRegion("Pebble", texture, new(208, 48, 16, 16))); -// -// return new SpriteComponent(sprite, factory.GetInstance()); -// }, "Pebble"); -// -// serviceRegistry.RegisterSingleton(factory => -// { -// var texture = factory.GetInstance("Content/SpriteSheets/Main.png"); -// var sprite = new Sprite("Tree", new TextureRegion("Tree", texture, new(144, 0, 48, 96))); -// -// return new SpriteComponent(sprite, factory.GetInstance()); -// }, "Tree"); -// RegisterTransformComponent(serviceRegistry); -// RegisterRectangleColliderComponent(serviceRegistry); -// RegisterItemComponent(serviceRegistry); -// RegisterInventoryComponent(serviceRegistry); -// -// #if DEBUG -// serviceRegistry.RegisterSingleton(); -// #endif -// } -// -// private static void RegisterItemComponent(IServiceRegistry serviceRegistry) -// { -// // TODO: make this accessible globally? So, the name, etc. of an item are reused between classes easily -// // Dictionary items = new() -// // { -// // { ItemId.Rock, new Item(name: "Rock", isStackable: true, maximumInStack: 16) } -// // }; -// -// serviceRegistry.RegisterSingleton(_ => new ItemComponent(ItemId.Rock), ItemsTable.Items[ItemId.Rock].Name); -// } -// -// private static void RegisterTagComponents(IServiceRegistry serviceRegistry) -// { -// RegisterCameraComponent(serviceRegistry); -// RegisterPlayerMovementComponent(serviceRegistry); -// } -// -// -// private static void RegisterStaticRenderComponents(IServiceRegistry serviceRegistry) -// { -// RegisterSpriteComponent(serviceRegistry); -// } -// -// private static void RegisterAnimatedRenderComponents(IServiceRegistry serviceRegistry) -// { -// RegisterMovementAnimationsComponent(serviceRegistry); -// RegisterCharacterAnimatorComponent(serviceRegistry); -// } -// -// private static void RegisterCameraComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(_ => new Viewport(0, 0, 801, 480), "CameraComponent"); -// serviceRegistry.RegisterSingleton(factory => -// new CameraComponent(factory.GetInstance("CameraComponent"))); -// } -// -// private static void RegisterPlayerMovementComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(_ => new InputMovableComponent()); -// // If 7.5f -> Math.Ceiling fixes this, else Math.Round -// serviceRegistry.RegisterSingleton(_ => new MovableComponent(7f)); -// } -// -// private static void RegisterSpriteComponent(IServiceRegistry serviceRegistry) -// { -// // todo: put non-game strings in internal resources -// serviceRegistry.RegisterSingleton(factory => -// { -// var getAnimations = -// factory.GetInstance>>("Character"); -// Dictionary idle = getAnimations(PlayerSpriteSheetPath, "Idle"); -// AnimatedSprite defaultSprite = idle[Sector.Down]; -// -// return new SpriteComponent(defaultSprite, factory.GetInstance()); -// }, "Player"); -// -// // serviceRegistry.RegisterSingleton(factory => -// // { -// // TODO: add the sprite of a rock -// // }) -// } -// -// private static void RegisterMovementAnimationsComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterTransient(factory => -// { -// var getAnimations = -// factory.GetInstance>>("Character"); -// -// return new MovementAnimationsComponent(getAnimations(PlayerSpriteSheetPath, "Idle"), -// getAnimations(PlayerSpriteSheetPath, "Walking")); -// }, "PlayerEntity"); -// } -// -// -// // private static void RegisterCameraComponent(IServiceRegistry serviceRegistry) => -// // serviceRegistry.RegisterSingleton(_ => new CameraComponent { Size = new Rectangle(0, 0, 640, 480) }); -// -// private static void RegisterTransformComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.Register((factory, name) => new NameComponent(name)); -// serviceRegistry.RegisterTransient(_ => new TransformComponent()); -// -// serviceRegistry.RegisterSingleton(_ => -// new TransformComponent { Position = new(0, 3) }, "PlayerAnimationsOffset"); -// -// serviceRegistry.RegisterSingleton(_ => -// new TransformComponent { Position = new(316, 116), Pivot = Sector.Up }, "PlayerEntity"); -// -// serviceRegistry.RegisterSingleton(_ => -// new TransformComponent { Position = new(300, 100) }, "DummyEntity"); -// -// serviceRegistry.RegisterSingleton(_ => -// new TransformComponent { Position = new(180, 50) }, "RockEntity"); -// } -// -// private static void RegisterRectangleColliderComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(_ => -// new RectangleColliderComponent { Size = new(0, 0, 8, 8), IsTrigger = true }, "DummyEntity"); -// -// serviceRegistry.RegisterSingleton(_ => -// new RectangleColliderComponent { Size = new(0, 0, 8, 8) }, "PlayerEntity"); -// } -// -// private static void RegisterInventoryComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterTransient(_ => -// { -// const int count = 9; -// Slot[] slots = new Slot[count]; -// -// // Put items in slots like that: -// slots[3].Item = ItemId.Rock; -// slots[3].Amount = 3; -// -// return new InventoryComponent(slots); -// }); -// } -// -// private static void RegisterCharacterAnimatorComponent(IServiceRegistry serviceRegistry) -// { -// serviceRegistry.RegisterSingleton(factory => -// { -// var movementAnimations = factory.GetInstance("PlayerEntity"); -// const Sector facing = Sector.Right; -// -// return new CharacterAnimatorComponent(facing, movementAnimations.IdleAnimations[facing], -// factory.GetInstance("PlayerAnimationsOffset")); -// }, "PlayerEntity"); -// } -// } diff --git a/src/Apps/GameDesktop/CompositionRoots/Components/ComponentsCompositionRoot.cs b/src/Libs/CompositionRoots/ComponentsCompositionRoot.cs similarity index 92% rename from src/Apps/GameDesktop/CompositionRoots/Components/ComponentsCompositionRoot.cs rename to src/Libs/CompositionRoots/ComponentsCompositionRoot.cs index d653532..0026246 100644 --- a/src/Apps/GameDesktop/CompositionRoots/Components/ComponentsCompositionRoot.cs +++ b/src/Libs/CompositionRoots/ComponentsCompositionRoot.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Components.Data; +using Components.Data; using Components.Render.Animation; using Components.Render.Static; using Components.Tags; -using GameDesktop.Resources.Internal; +using CompositionRoots; +using Constants; using LightInject; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -13,16 +11,15 @@ using MonoGame.Aseprite.Sprites; using Services.Math; +[assembly: CompositionRootType(typeof(ComponentsCompositionRoot))] -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Components.ComponentsCompositionRoot))] - -namespace GameDesktop.CompositionRoots.Components; +namespace CompositionRoots; internal class ComponentsCompositionRoot : ICompositionRoot { private static readonly string PlayerSpriteSheetPath = Path.Join( - Environment.GetEnvironmentVariable(EnvironmentVariable.AppBaseDirectory), - Resources.SpriteSheet.Player); + Environment.GetEnvironmentVariable(EnvironmentNames.AppBaseDirectory), + Contents.SpriteSheets.Player); public void Compose(IServiceRegistry serviceRegistry) { @@ -39,7 +36,7 @@ private static void RegisterDataComponents(IServiceRegistry serviceRegistry) serviceRegistry.Register((factory, path) => { var fileName = Path.Join( - Environment.GetEnvironmentVariable(EnvironmentVariable.AppBaseDirectory), + Environment.GetEnvironmentVariable(EnvironmentNames.AppBaseDirectory), path ); return Texture2D.FromFile(factory.GetInstance().GraphicsDevice, fileName); @@ -48,7 +45,7 @@ private static void RegisterDataComponents(IServiceRegistry serviceRegistry) // TODO: Automatically get texture & its rect from a tile set (by aseprite?) serviceRegistry.RegisterSingleton(factory => { - var texture = factory.GetInstance("Content/SpriteSheets/Main.png"); + var texture = factory.GetInstance(Contents.Textures.Main); var sprite = new Sprite("Pebble", new TextureRegion("Pebble", texture, new(208, 48, 16, 16))); return new SpriteComponent(sprite, factory.GetInstance()); @@ -56,7 +53,7 @@ private static void RegisterDataComponents(IServiceRegistry serviceRegistry) serviceRegistry.RegisterSingleton(factory => { - var texture = factory.GetInstance("Content/SpriteSheets/Main.png"); + var texture = factory.GetInstance(Contents.Textures.Main); var sprite = new Sprite("Tree", new TextureRegion("Tree", texture, new(144, 0, 48, 96))); return new SpriteComponent(sprite, factory.GetInstance()); diff --git a/src/Libs/CompositionRoots/CompositionRoots.csproj b/src/Libs/CompositionRoots/CompositionRoots.csproj index 89b6cf2..fafdbdb 100644 --- a/src/Libs/CompositionRoots/CompositionRoots.csproj +++ b/src/Libs/CompositionRoots/CompositionRoots.csproj @@ -11,4 +11,12 @@ + + + + + + + + diff --git a/src/Apps/GameDesktop/CompositionRoots/FundamentalCompositionRoot.cs b/src/Libs/CompositionRoots/FundamentalCompositionRoot.cs similarity index 74% rename from src/Apps/GameDesktop/CompositionRoots/FundamentalCompositionRoot.cs rename to src/Libs/CompositionRoots/FundamentalCompositionRoot.cs index a5fd1d1..c0050d0 100644 --- a/src/Apps/GameDesktop/CompositionRoots/FundamentalCompositionRoot.cs +++ b/src/Libs/CompositionRoots/FundamentalCompositionRoot.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using GameDesktop.Resources.Internal; +using CompositionRoots; +using Constants; using LDtk; using LightInject; using Microsoft.Xna.Framework; @@ -11,16 +8,16 @@ using Services.Builders; using Services.Math; -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.FundamentalCompositionRoot))] +[assembly: CompositionRootType(typeof(FundamentalCompositionRoot))] -namespace GameDesktop.CompositionRoots; +namespace CompositionRoots; internal class FundamentalCompositionRoot : ICompositionRoot { public void Compose(IServiceRegistry serviceRegistry) { RegisterLdtk(serviceRegistry); - RegisterAnimationsFactory(serviceRegistry); + RegisterAsepriteAnimatedCharacter(serviceRegistry); } private static void RegisterLdtk(IServiceRegistry serviceRegistry) @@ -28,15 +25,15 @@ private static void RegisterLdtk(IServiceRegistry serviceRegistry) serviceRegistry.RegisterSingleton(_ => { var fileName = Path.Join( - Environment.GetEnvironmentVariable(EnvironmentVariable.AppBaseDirectory), - "Content/TileMaps/Test.ldtk" + Environment.GetEnvironmentVariable(EnvironmentNames.AppBaseDirectory), + Contents.TileMaps.Test ); return LDtkFile.FromFile(fileName); }); } - private static void RegisterAnimationsFactory(IServiceRegistry serviceRegistry) + private static void RegisterAsepriteAnimatedCharacter(IServiceRegistry serviceRegistry) { serviceRegistry.RegisterTransient(); // Warning: binding to where T is any type, is dangerous and you should have a different diff --git a/src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs b/src/Libs/CompositionRoots/RootFeatureCompositionRoot.cs similarity index 85% rename from src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs rename to src/Libs/CompositionRoots/RootFeatureCompositionRoot.cs index 92fbb8b..6622e27 100644 --- a/src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs +++ b/src/Libs/CompositionRoots/RootFeatureCompositionRoot.cs @@ -1,18 +1,14 @@ -using System; -using System.Linq; -using Components.Data; +using CompositionRoots; +using Constants; using Entities.Factories; using Entities.Factories.Characters; -using Entities.Factories.Items; using Entities.Factories.Items.Rocks; using Entities.Factories.Items.Trees; using Entities.Factories.Meta; using Features; using FontStashSharp.RichText; -using LightInject; -using GameDesktop.CompositionRoots.Components; -using GameDesktop.CompositionRoots.Entities; using LDtk; +using LightInject; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Myra.Graphics2D.UI; @@ -20,22 +16,19 @@ using Services.Movement; using Systems; using Systems.Debugging.Diagnostics; +using Systems.Debugging.Render; using Systems.Debugging.World; using Systems.Render; using UI.Blocks; using UI.Factories; using UI.Feature; using World = Scellecs.Morpeh.World; -#if DEBUG -using Systems.Debugging.Render; -using GameDesktop.CompositionRoots.DebugFeatures; -#endif -[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Features.RootFeatureCompositionRoot))] +[assembly: CompositionRootType(typeof(RootFeatureCompositionRoot))] -namespace GameDesktop.CompositionRoots.Features; +namespace CompositionRoots; -internal class RootFeatureCompositionRoot : ICompositionRoot +public class RootFeatureCompositionRoot : ICompositionRoot { public void Compose(IServiceRegistry serviceRegistry) { @@ -49,12 +42,10 @@ public void Compose(IServiceRegistry serviceRegistry) RegisterFundamental(serviceRegistry); RegisterComponents(serviceRegistry); - RegisterEntities(serviceRegistry); // RegisterFeatures(serviceRegistry); #if DEBUG - serviceRegistry.RegisterFrom(); serviceRegistry.RegisterSingleton(); #endif serviceRegistry.RegisterSingleton(); @@ -79,21 +70,6 @@ private static void RegisterFundamental(IServiceRegistry serviceRegistry) private static void RegisterComponents(IServiceRegistry serviceRegistry) => serviceRegistry.RegisterFrom(); - private static void RegisterEntities(IServiceRegistry serviceRegistry) - { - serviceRegistry.RegisterFrom(); - serviceRegistry.RegisterFrom(); - serviceRegistry.RegisterFrom(); - } - - // private static void RegisterFeatures(IServiceRegistry serviceRegistry) - // { - // serviceRegistry.RegisterFrom(); - // serviceRegistry.RegisterFrom(); - // serviceRegistry.RegisterFrom(); - // serviceRegistry.RegisterFrom(); - // } - private static void RegisterEntryPoint(IServiceRegistry serviceRegistry) { serviceRegistry.RegisterSingleton(factory => new CollisionSystem(factory.GetInstance())); @@ -187,7 +163,7 @@ private static void RegisterEntryPoint(IServiceRegistry serviceRegistry) Left = -30, Top = -20, TextAlign = TextHorizontalAlignment.Right, - Text = "Pre-alpha v0.3.2" + Text = AppVariables.GameVersion })); serviceRegistry.RegisterSingleton>(factory => factory.GetInstance); diff --git a/src/Libs/Constants/Constants.csproj b/src/Libs/Constants/Constants.csproj new file mode 100644 index 0000000..1009f5b --- /dev/null +++ b/src/Libs/Constants/Constants.csproj @@ -0,0 +1,10 @@ + + + + net8.0 + preview + enable + enable + + + diff --git a/src/Libs/Constants/Contents/Contents.cs b/src/Libs/Constants/Contents/Contents.cs new file mode 100644 index 0000000..2b1ad59 --- /dev/null +++ b/src/Libs/Constants/Contents/Contents.cs @@ -0,0 +1,6 @@ +namespace Constants; + +public static partial class Contents +{ + public const string RootDirectory = "Content"; +} diff --git a/src/Libs/Constants/Contents/SpriteSheets.cs b/src/Libs/Constants/Contents/SpriteSheets.cs new file mode 100644 index 0000000..0a4a02f --- /dev/null +++ b/src/Libs/Constants/Contents/SpriteSheets.cs @@ -0,0 +1,9 @@ +namespace Constants; + +public static partial class Contents +{ + public static class SpriteSheets + { + public const string Player = $"{RootDirectory}/SpriteSheets/Player.aseprite"; + } +} diff --git a/src/Libs/Constants/Contents/Textures.cs b/src/Libs/Constants/Contents/Textures.cs new file mode 100644 index 0000000..84096a2 --- /dev/null +++ b/src/Libs/Constants/Contents/Textures.cs @@ -0,0 +1,9 @@ +namespace Constants; + +public static partial class Contents +{ + public static class Textures + { + public const string Main = $"{RootDirectory}/SpriteSheets/Main.png"; + } +} diff --git a/src/Libs/Constants/Contents/TileMaps.cs b/src/Libs/Constants/Contents/TileMaps.cs new file mode 100644 index 0000000..ab1ec8d --- /dev/null +++ b/src/Libs/Constants/Contents/TileMaps.cs @@ -0,0 +1,9 @@ +namespace Constants; + +public static partial class Contents +{ + public static class TileMaps + { + public const string Test = $"{RootDirectory}/TileMaps/Test.ldtk"; + } +} diff --git a/src/Libs/Constants/Errors.cs b/src/Libs/Constants/Errors.cs new file mode 100644 index 0000000..ff6817f --- /dev/null +++ b/src/Libs/Constants/Errors.cs @@ -0,0 +1,7 @@ +namespace Constants; + +public static class Errors +{ + // Used in Program.cs of the GameDesktop project, at the block-scope of: #if IS_CI + public const string FailedToCreateGraphicsDevice = "Failed to create graphics device!"; +} diff --git a/src/Libs/Constants/Meta/AppVariables.cs b/src/Libs/Constants/Meta/AppVariables.cs new file mode 100644 index 0000000..c67e5f8 --- /dev/null +++ b/src/Libs/Constants/Meta/AppVariables.cs @@ -0,0 +1,7 @@ +namespace Constants; + +public static class AppVariables +{ + public const string SettingsFileName = "appsettings"; + public const string GameVersion = "Pre-Alpha v0.3.6"; +} diff --git a/src/Libs/Constants/Meta/DINames.cs b/src/Libs/Constants/Meta/DINames.cs new file mode 100644 index 0000000..a559902 --- /dev/null +++ b/src/Libs/Constants/Meta/DINames.cs @@ -0,0 +1,6 @@ +namespace Constants; + +public static class DINames +{ + +} diff --git a/src/Libs/Constants/Meta/EnvironmentNames.cs b/src/Libs/Constants/Meta/EnvironmentNames.cs new file mode 100644 index 0000000..b3756d0 --- /dev/null +++ b/src/Libs/Constants/Meta/EnvironmentNames.cs @@ -0,0 +1,7 @@ +namespace Constants; + +public static class EnvironmentNames +{ + public const string AppBaseDirectory = "APP_BASE_DIRECTORY"; + public const string DotNetEnvironment = "DOTNET_ENVIRONMENT"; +} diff --git a/src/Libs/Services/Builders/AsepriteAnimatedCharactersBuilder.cs b/src/Libs/Services/Builders/AsepriteAnimatedCharactersBuilder.cs index 27b7e16..85905ce 100644 --- a/src/Libs/Services/Builders/AsepriteAnimatedCharactersBuilder.cs +++ b/src/Libs/Services/Builders/AsepriteAnimatedCharactersBuilder.cs @@ -8,7 +8,7 @@ namespace Services.Builders; public class AsepriteAnimatedCharactersBuilder { - public Dictionary? Animations { get; private set; } + public Dictionary Animations { get; private set; } = new(); private SpriteSheet? _spriteSheet; diff --git a/src/Libs/UI/UI.csproj b/src/Libs/UI/UI.csproj index a68cd0c..6b83b42 100644 --- a/src/Libs/UI/UI.csproj +++ b/src/Libs/UI/UI.csproj @@ -16,8 +16,4 @@ - - - -