Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #112

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NetAF.Examples/Assets/Regions/Hub/Rooms/Clearing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Room Instantiate()
new("No thanks, keep things as they are.", new Jump(4))
]
},
new("Arrk! Color it is.", g => g.Configuration.FrameBuilders = FrameBuilderCollections.Default, new ToName("ModeQuestion")),
new("Arrk! Color it is.", g => g.Configuration.FrameBuilders = ConsoleFrameBuilderCollections.Default, new ToName("ModeQuestion")),
new("Eeek, simple be fine too! Shame it's been deleted. Maybe it will be implemented again one day! Eeek!", new ToName("ModeQuestion")),
new("Squarrk! Legacy, looks old. Shame it's been deleted. Maybe it will be implemented again one day! Arrk!", new ToName("ModeQuestion")),
new("Fine, suit yourself! Squarrk!", new ToName("ModeQuestion"))
Expand Down
12 changes: 0 additions & 12 deletions NetAF.Tests/Rendering/Console/TextWriterPresenter_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ namespace NetAF.Tests.Rendering.Console
[TestClass]
public class TextWriterPresenter_Tests
{
[TestMethod]
public void GivenCharacter_WhenWrite_ThenCharacterIsWritten()
{
var textWriter = new StringWriter();
var character = 'C';
var presenter = new TextWriterPresenter(textWriter);

presenter.Write(character);

Assert.AreEqual(character, presenter.ToString().First());
}

[TestMethod]
public void GivenString_WhenWrite_ThenStringIsWritten()
{
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Tests/TestGameConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class TestGameConfiguration(Size displaySize, ExitMode exitMode, IIOAda
new GlobalCommandInterpreter(),
new CustomCommandInterpreter());

public FrameBuilderCollection FrameBuilders { get; set; } = FrameBuilderCollections.Default;
public FrameBuilderCollection FrameBuilders { get; set; } = ConsoleFrameBuilderCollections.Default;
public IIOAdapter Adapter { get; private set; } = adapter;
}
}
7 changes: 5 additions & 2 deletions NetAF/Adapters/SystemConsoleAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@

frame.Render(presenter);

System.Console.CursorVisible = frame.ShowCursor;
System.Console.SetCursorPosition(frame.CursorLeft, frame.CursorTop);
if (frame is IConsoleFrame consoleFrame)
{
System.Console.CursorVisible = consoleFrame.ShowCursor;
System.Console.SetCursorPosition(consoleFrame.CursorLeft, consoleFrame.CursorTop);
}

Check warning on line 61 in NetAF/Adapters/SystemConsoleAdapter.cs

View check run for this annotation

Codecov / codecov/patch

NetAF/Adapters/SystemConsoleAdapter.cs#L58-L61

Added lines #L58 - L61 were not covered by tests
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion NetAF/Logic/Configuration/ConsoleGameConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public sealed class ConsoleGameConfiguration(Size displaySize, ExitMode exitMode
/// <summary>
/// Get or set the collection of frame builders to use to render the game.
/// </summary>
public FrameBuilderCollection FrameBuilders { get; set; } = FrameBuilderCollections.Default;
public FrameBuilderCollection FrameBuilders { get; set; } = ConsoleFrameBuilderCollections.Default;

/// <summary>
/// Get the I/O adapter.
Expand Down
12 changes: 8 additions & 4 deletions NetAF/Rendering/Console/GridTextFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NetAF.Rendering.Console
/// <param name="cursorLeft">The cursor left position.</param>
/// <param name="cursorTop">The cursor top position.</param>
/// <param name="backgroundColor">The background color.</param>
public sealed class GridTextFrame(GridStringBuilder builder, int cursorLeft, int cursorTop, AnsiColor backgroundColor) : IFrame
public sealed class GridTextFrame(GridStringBuilder builder, int cursorLeft, int cursorTop, AnsiColor backgroundColor) : IConsoleFrame
{
#region Properties

Expand Down Expand Up @@ -46,7 +46,7 @@ public override string ToString()

#endregion

#region Implementation of IFrame
#region Implementation of IConsoleFrame

/// <summary>
/// Get the cursor left position.
Expand All @@ -63,6 +63,10 @@ public override string ToString()
/// </summary>
public bool ShowCursor { get; set; } = true;

#endregion

#region Implementation of IFrame

/// <summary>
/// Render this frame on a presenter.
/// </summary>
Expand All @@ -89,7 +93,7 @@ public void Render(IFramePresenter presenter)
presenter.Write(Ansi.GetAnsiForegroundEscapeSequence(builder.GetCellColor(x, y)));
}

presenter.Write(c);
presenter.Write(c.ToString());
}
else
{
Expand All @@ -98,7 +102,7 @@ public void Render(IFramePresenter presenter)
}

if (y < builder.DisplaySize.Height - 1)
presenter.Write(builder.LineTerminator);
presenter.Write(builder.LineTerminator.ToString());
}

presenter.Write(Ansi.ANSI_SHOW_CURSOR);
Expand Down
4 changes: 2 additions & 2 deletions NetAF/Rendering/Console/GridVisualFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void RenderCharacter(IFramePresenter presenter, int x, int y, bool suppr
{
var foregroundColor = GetForegroundColor(x, y, suppressColor);
UpdateForegroundColor(presenter, x, y, foregroundColor, ref lastForeground);
presenter.Write(c);
presenter.Write(c.ToString());
}
else
{
Expand Down Expand Up @@ -162,7 +162,7 @@ public void Render(IFramePresenter presenter)
}

if (y < builder.DisplaySize.Height - 1)
presenter.Write(builder.LineTerminator);
presenter.Write(builder.LineTerminator.ToString());
}
}

Expand Down
21 changes: 21 additions & 0 deletions NetAF/Rendering/Console/IConsoleFrame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NetAF.Rendering
{
/// <summary>
/// Represents any object that is a frame that can display a command based interface.
/// </summary>
public interface IConsoleFrame : IFrame
{
/// <summary>
/// Get the cursor left position.
/// </summary>
int CursorLeft { get; }
/// <summary>
/// Get the cursor top position.
/// </summary>
int CursorTop { get; }
/// <summary>
/// Get or set if the cursor should be shown.
/// </summary>
bool ShowCursor { get; set; }
}
}
9 changes: 0 additions & 9 deletions NetAF/Rendering/Console/TextWriterPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ public override string ToString()

#region Implementation of IFramePresenter

/// <summary>
/// Write a character.
/// </summary>
/// <param name="value">The character to write.</param>
public void Write(char value)
{
writer.Write(value);
}

/// <summary>
/// Write a string.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace NetAF.Rendering.FrameBuilders
{
/// <summary>
/// Provides a container from frame builder collections.
/// Provides a container for console frame builder collections.
/// </summary>
public static class FrameBuilderCollections
public static class ConsoleFrameBuilderCollections
{
/// <summary>
/// Get the default frame builder collection.
Expand Down
14 changes: 1 addition & 13 deletions NetAF/Rendering/IFrame.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
namespace NetAF.Rendering
{
/// <summary>
/// Represents any object that is a frame that can display a command based interface.
/// Represents any object that is a frame for displaying an interface.
/// </summary>
public interface IFrame
{
/// <summary>
/// Get the cursor left position.
/// </summary>
int CursorLeft { get; }
/// <summary>
/// Get the cursor top position.
/// </summary>
int CursorTop { get; }
/// <summary>
/// Get or set if the cursor should be shown.
/// </summary>
bool ShowCursor { get; set; }
/// <summary>
/// Render this frame on a presenter.
/// </summary>
Expand Down
7 changes: 1 addition & 6 deletions NetAF/Rendering/IFramePresenter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
namespace NetAF.Rendering
{
/// <summary>
/// Represents an object that can render a frame.
/// Represents an object that can present a frame.
/// </summary>
public interface IFramePresenter
{
/// <summary>
/// Write a character.
/// </summary>
/// <param name="value">The character to write.</param>
void Write(char value);
/// <summary>
/// Write a string.
/// </summary>
Expand Down
Loading