Skip to content

Commit

Permalink
exposing more functionality for manually registering services + added…
Browse files Browse the repository at this point in the history
… "UI" and "GSM" to project dictionary
  • Loading branch information
BenMakesGames committed Apr 21, 2024
1 parent ef197ab commit 44ff8f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions BenMakesGames.PlayPlayMini.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GSM/@EntryIndexedValue">GSM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions BenMakesGames.PlayPlayMini/BenMakesGames.PlayPlayMini.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Ben Hendel-Doying</Company>
<Description>An opinionated framework for making smallish games with MonoGame.</Description>
<Copyright>2021-2024 Ben Hendel-Doying</Copyright>
<Version>4.5.0</Version>
<Version>4.6.0</Version>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>monogame game engine framework di state</PackageTags>
Expand All @@ -27,7 +27,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
</ItemGroup>
Expand Down
20 changes: 15 additions & 5 deletions BenMakesGames.PlayPlayMini/GameStateManagerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GameStateManagerBuilder

private AssetCollection GameAssets { get; } = new();

private Action<ContainerBuilder, IConfiguration>? AddServicesCallback { get; set; }
private Action<ContainerBuilder, IConfiguration, ServiceWatcher>? AddServicesCallback { get; set; }
private Action<IConfigurationBuilder>? ConfigurationCallback { get; set; }
private string WindowTitle { get; set; } = "PlayPlayMini Game";
private (int Width, int Height, int Zoom) WindowSize { get; set; } = (1920 / 3, 1080 / 3, 2);
Expand Down Expand Up @@ -69,7 +69,7 @@ public GameStateManagerBuilder AddAssets(IList<IAsset> assets)
return this;
}

public GameStateManagerBuilder AddServices(Action<ContainerBuilder, IConfiguration> callback)
public GameStateManagerBuilder AddServices(Action<ContainerBuilder, IConfiguration, ServiceWatcher> callback)
{
if (AddServicesCallback is not null)
throw new ArgumentException("AddServices may only be called once!");
Expand All @@ -79,13 +79,23 @@ public GameStateManagerBuilder AddServices(Action<ContainerBuilder, IConfigurati
return this;
}

[Obsolete("Use AddServices(Action<ContainerBuilder, IConfiguration> callback) instead.")]
public GameStateManagerBuilder AddServices(Action<ContainerBuilder, IConfiguration> callback)
{
if (AddServicesCallback is not null)
throw new ArgumentException("AddServices may only be called once!");

AddServicesCallback = (s, c, _) => callback(s, c);

return this;
}

[Obsolete("Use AddServices(Action<ContainerBuilder, IConfiguration, ServiceWatcher> callback) instead.")]
public GameStateManagerBuilder AddServices(Action<ContainerBuilder> callback)
{
if (AddServicesCallback is not null)
throw new ArgumentException("AddServices may only be called once!");

AddServicesCallback = (s, _) => callback(s);
AddServicesCallback = (s, _, _) => callback(s);

return this;
}
Expand Down Expand Up @@ -179,7 +189,7 @@ public void Run()
.As(typeof(ILogger<>))
.SingleInstance();

AddServicesCallback?.Invoke(builder, configuration);
AddServicesCallback?.Invoke(builder, configuration, serviceWatcher);

if(InitialGameState is null)
throw new ArgumentException("No initial game state set! You must call GameStateManagerBuilder's SetInitialGameState method before calling its Run method.");
Expand Down

0 comments on commit 44ff8f7

Please # to comment.