Skip to content

Commit

Permalink
Added cheese menu (online only)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krapht committed Jun 2, 2024
1 parent 00944a2 commit 5fe413d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
37 changes: 37 additions & 0 deletions InsightLogParser.Client/Menu/CheeseMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Linq;

namespace InsightLogParser.Client.Menu;

internal class CheeseMenu : IMenu
{
private readonly Spider _spider;

public CheeseMenu(Spider spider)
{
_spider = spider;
}

public IEnumerable<(char? key, string text)> MenuOptions
{
get
{
yield return (null, "Cheesing. Press [h] to display this menu again and backspace to back");
if (_spider.IsOnline())
{
yield return ('s', "Open solution to last opened puzzle, if available");
}
}
}

public async Task<MenuResult> HandleOptionAsync(char keyChar)

Check warning on line 26 in InsightLogParser.Client/Menu/CheeseMenu.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
switch (keyChar)
{
case 's':
_spider.OpenSolutionScreenshot();
return MenuResult.Ok;
default:
return MenuResult.NotValidOption;
}
}
}
6 changes: 5 additions & 1 deletion InsightLogParser.Client/Menu/RootMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ internal class RootMenu : IMenu
('h', "Show this list again"),
('c', "--> Configuration [WIP]"),
('s', "--> Statistics"),
('a', "--> Advanced or risky")
('a', "--> Advanced or risky"),
('C', "--> Che....ese (online only)"),
};

public RootMenu(MenuHandler menuHandler, Spider spider, MessageWriter writer, UserComputer computer)
Expand All @@ -39,6 +40,9 @@ public Task<MenuResult> HandleOptionAsync(char keyChar)
case 'a':
_menuHandler.EnterMenu(new AdvancedMenu(_menuHandler, _computer, _writer, _spider));
return Task.FromResult(MenuResult.Ok);
case 'C':
_menuHandler.EnterMenu(new CheeseMenu(_spider));
return Task.FromResult(MenuResult.Ok);
default:
return Task.FromResult(MenuResult.NotValidOption);
}
Expand Down
21 changes: 21 additions & 0 deletions InsightLogParser.Client/Spider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using System.Diagnostics;
using InsightLogParser.Client.Cetus;
using InsightLogParser.Client.Screenshots;
using InsightLogParser.Common;
Expand All @@ -24,6 +25,7 @@ internal class Spider
//State
private DateTimeOffset? _sessionStart;
private string? _serverAddress;
private int? _lastOpenedWithSolution;

public Spider(MessageWriter messageWriter
, Configuration configuration
Expand Down Expand Up @@ -183,6 +185,8 @@ public async Task OpenedAsync(DateTimeOffset timestamp, int puzzleId, PuzzleZone
{
_beeper.BeepForMissingScreenshot();
}

_lastOpenedWithSolution = seenResponse.Screenshots.Any(x => x == ScreenshotCategory.Solved) ? puzzleId : default(int?);
}
_messageWriter.WriteEndOpened();
_screenshotManager?.SetLastPuzzle(puzzleId, false);
Expand Down Expand Up @@ -391,5 +395,22 @@ public async Task OpenCetusWebAsync()
_messageWriter.WriteError($"Failed to launch browser: {e}");
}
}

public void OpenSolutionScreenshot()
{
if (_lastOpenedWithSolution == null)
{
_messageWriter.WriteError("Last opened puzzle did not have a solved screenshot");
return;
}
try
{
_computer.LaunchBrowser($"{_configuration.CetusUri}/goto/solution/{_lastOpenedWithSolution}");
}
catch (Exception e)
{
_messageWriter.WriteError($"Failed to launch browser: {e}");
}
}
}
}

0 comments on commit 5fe413d

Please sign in to comment.