From bc167b6a355219635461dd45b8f93dca39da4e6e Mon Sep 17 00:00:00 2001 From: ben_singer Date: Fri, 29 Nov 2024 22:04:32 +0000 Subject: [PATCH] Streamlined game configuration --- NetAF.Tests/TestGameConfiguration.cs | 3 --- NetAF/Commands/Frame/CommandsOff.cs | 6 ++++-- NetAF/Commands/Frame/CommandsOn.cs | 6 ++++-- NetAF/Commands/Frame/KeyOff.cs | 5 +++-- NetAF/Commands/Frame/KeyOn.cs | 5 +++-- .../Configuration/ConsoleGameConfiguration.cs | 11 ----------- NetAF/Logic/Configuration/IGameConfiguration.cs | 11 ----------- NetAF/Logic/Modes/SceneMode.cs | 17 ++++++++++++++++- 8 files changed, 30 insertions(+), 34 deletions(-) diff --git a/NetAF.Tests/TestGameConfiguration.cs b/NetAF.Tests/TestGameConfiguration.cs index 1a43bbfe..7d4ce6ec 100644 --- a/NetAF.Tests/TestGameConfiguration.cs +++ b/NetAF.Tests/TestGameConfiguration.cs @@ -3,7 +3,6 @@ using NetAF.Interpretation; using NetAF.Logic; using NetAF.Logic.Configuration; -using NetAF.Rendering; using NetAF.Rendering.FrameBuilders; namespace NetAF.Tests @@ -20,8 +19,6 @@ internal class TestGameConfiguration(Size displaySize, ExitMode exitMode, IIOAda new CustomCommandInterpreter()); public FrameBuilderCollection FrameBuilders { get; set; } = FrameBuilderCollections.Default; - public bool DisplayCommandListInSceneFrames { get; set; } = true; - public KeyType SceneMapKeyType { get; set; } = KeyType.Dynamic; public IIOAdapter Adapter { get; private set; } = adapter; } } diff --git a/NetAF/Commands/Frame/CommandsOff.cs b/NetAF/Commands/Frame/CommandsOff.cs index 597e51dc..6b8ed442 100644 --- a/NetAF/Commands/Frame/CommandsOff.cs +++ b/NetAF/Commands/Frame/CommandsOff.cs @@ -1,4 +1,6 @@ -namespace NetAF.Commands.Frame +using NetAF.Logic.Modes; + +namespace NetAF.Commands.Frame { /// /// Represents the CommandsOff command. @@ -26,7 +28,7 @@ public Reaction Invoke(Logic.Game game) if (game == null) return new(ReactionResult.Error, "No game specified."); - game.Configuration.DisplayCommandListInSceneFrames = false; + SceneMode.DisplayCommandList = false; return new(ReactionResult.Inform, "Commands have been turned off."); } diff --git a/NetAF/Commands/Frame/CommandsOn.cs b/NetAF/Commands/Frame/CommandsOn.cs index f2ad2dc8..44d1f0af 100644 --- a/NetAF/Commands/Frame/CommandsOn.cs +++ b/NetAF/Commands/Frame/CommandsOn.cs @@ -1,4 +1,6 @@ -namespace NetAF.Commands.Frame +using NetAF.Logic.Modes; + +namespace NetAF.Commands.Frame { /// /// Represents the CommandsOn command. @@ -26,7 +28,7 @@ public Reaction Invoke(Logic.Game game) if (game == null) return new(ReactionResult.Error, "No game specified."); - game.Configuration.DisplayCommandListInSceneFrames = true; + SceneMode.DisplayCommandList = true; return new(ReactionResult.Inform, "Commands have been turned on."); } diff --git a/NetAF/Commands/Frame/KeyOff.cs b/NetAF/Commands/Frame/KeyOff.cs index 9987bce5..1f68cf25 100644 --- a/NetAF/Commands/Frame/KeyOff.cs +++ b/NetAF/Commands/Frame/KeyOff.cs @@ -1,4 +1,5 @@ -using NetAF.Rendering; +using NetAF.Logic.Modes; +using NetAF.Rendering; namespace NetAF.Commands.Frame { @@ -28,7 +29,7 @@ public Reaction Invoke(Logic.Game game) if (game == null) return new(ReactionResult.Error, "No game specified."); - game.Configuration.SceneMapKeyType = KeyType.None; + SceneMode.KeyType = KeyType.None; return new(ReactionResult.Inform, "Key has been turned off."); } diff --git a/NetAF/Commands/Frame/KeyOn.cs b/NetAF/Commands/Frame/KeyOn.cs index 276ed175..de0a6892 100644 --- a/NetAF/Commands/Frame/KeyOn.cs +++ b/NetAF/Commands/Frame/KeyOn.cs @@ -1,4 +1,5 @@ -using NetAF.Rendering; +using NetAF.Logic.Modes; +using NetAF.Rendering; namespace NetAF.Commands.Frame { @@ -28,7 +29,7 @@ public Reaction Invoke(Logic.Game game) if (game == null) return new(ReactionResult.Error, "No game specified."); - game.Configuration.SceneMapKeyType = KeyType.Dynamic; + SceneMode.KeyType = KeyType.Dynamic; return new(ReactionResult.Inform, "Key has been turned on."); } diff --git a/NetAF/Logic/Configuration/ConsoleGameConfiguration.cs b/NetAF/Logic/Configuration/ConsoleGameConfiguration.cs index edf34d8c..e5fc368d 100644 --- a/NetAF/Logic/Configuration/ConsoleGameConfiguration.cs +++ b/NetAF/Logic/Configuration/ConsoleGameConfiguration.cs @@ -2,7 +2,6 @@ using NetAF.Assets; using NetAF.Interpretation; using NetAF.Rendering.FrameBuilders; -using NetAF.Rendering; namespace NetAF.Logic.Configuration { @@ -45,16 +44,6 @@ public sealed class ConsoleGameConfiguration(Size displaySize, ExitMode exitMode /// public FrameBuilderCollection FrameBuilders { get; set; } = FrameBuilderCollections.Default; - /// - /// Get or set if the command list is displayed in scene frames. - /// - public bool DisplayCommandListInSceneFrames { get; set; } = true; - - /// - /// Get or set the type of key to use on the scene map. - /// - public KeyType SceneMapKeyType { get; set; } = KeyType.Dynamic; - /// /// Get the I/O adapter. /// diff --git a/NetAF/Logic/Configuration/IGameConfiguration.cs b/NetAF/Logic/Configuration/IGameConfiguration.cs index 3006b043..da63548c 100644 --- a/NetAF/Logic/Configuration/IGameConfiguration.cs +++ b/NetAF/Logic/Configuration/IGameConfiguration.cs @@ -1,7 +1,6 @@ using NetAF.Adapters; using NetAF.Assets; using NetAF.Interpretation; -using NetAF.Rendering; using NetAF.Rendering.FrameBuilders; namespace NetAF.Logic.Configuration @@ -33,16 +32,6 @@ public interface IGameConfiguration /// public FrameBuilderCollection FrameBuilders { get; set; } - /// - /// Get or set if the command list is displayed in scene frames. - /// - public bool DisplayCommandListInSceneFrames { get; set; } - - /// - /// Get or set the type of key to use on the scene map. - /// - public KeyType SceneMapKeyType { get; set; } - /// /// Get the I/O adapter. /// diff --git a/NetAF/Logic/Modes/SceneMode.cs b/NetAF/Logic/Modes/SceneMode.cs index d52a952c..af5f8ba2 100644 --- a/NetAF/Logic/Modes/SceneMode.cs +++ b/NetAF/Logic/Modes/SceneMode.cs @@ -1,6 +1,7 @@ using NetAF.Assets.Locations; using NetAF.Commands; using NetAF.Interpretation; +using NetAF.Rendering; using System.Collections.Generic; namespace NetAF.Logic.Modes @@ -10,6 +11,20 @@ namespace NetAF.Logic.Modes /// public sealed class SceneMode : IGameMode { + #region StaticProperties + + /// + /// Get or set if the command list is displayed. + /// + public static bool DisplayCommandList { get; set; } = true; + + /// + /// Get or set the type of key to use on the map. + /// + public static KeyType KeyType { get; set; } = KeyType.Dynamic; + + #endregion + #region Implementation of IGameMode /// @@ -32,7 +47,7 @@ public void Render(Game game) commands.AddRange(Interpreter.GetContextualCommandHelp(game)); commands.AddRange(game.Configuration.Interpreter.GetContextualCommandHelp(game)); - var frame = game.Configuration.FrameBuilders.SceneFrameBuilder.Build(game.Overworld.CurrentRegion.CurrentRoom, ViewPoint.Create(game.Overworld.CurrentRegion), game.Player, game.Configuration.DisplayCommandListInSceneFrames ? [.. commands] : null, game.Configuration.SceneMapKeyType, game.Configuration.DisplaySize); + var frame = game.Configuration.FrameBuilders.SceneFrameBuilder.Build(game.Overworld.CurrentRegion.CurrentRoom, ViewPoint.Create(game.Overworld.CurrentRegion), game.Player, DisplayCommandList ? [.. commands] : null, KeyType, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); }