diff --git a/README.md b/README.md index 7fb2f01..a25132b 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,6 @@ The puzzle is presented as a cube map in the same manner as in [Old Pochman](htt ![Image](./misc/netcube-system-design.png) -> Note: The above diagram depicts the end goal, rather than the current state of the system. - -> Yet to be implemented: AdminPanel, CubeProxy - ## Usage ### Setup diff --git a/Solution/AdminPanel/MainWindow.xaml b/Solution/AdminPanel/MainWindow.xaml index 5a9ad25..3cf58ba 100644 --- a/Solution/AdminPanel/MainWindow.xaml +++ b/Solution/AdminPanel/MainWindow.xaml @@ -5,14 +5,15 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:AdminPanel" mc:Ignorable="d" - Title="MainWindow" Height="200" Width="320"> - + Title="AdminPanel" Height="200" Width="320" + KeyDown="Window_KeyDown" + Focusable="True" + KeyUp="Window_KeyUp" + > - - diff --git a/Solution/AdminPanel/MainWindow.xaml.cs b/Solution/AdminPanel/MainWindow.xaml.cs index 72d3ef4..891c0f6 100644 --- a/Solution/AdminPanel/MainWindow.xaml.cs +++ b/Solution/AdminPanel/MainWindow.xaml.cs @@ -36,5 +36,22 @@ private async void Shuffle_Click(object sender, RoutedEventArgs e) { await ShuffleStrategy.ShuffleCubeAsync(); } + + private void Window_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.R) + { + Reset_Click(this, new RoutedEventArgs()); + } + else if (e.Key == Key.S) + { + Shuffle_Click(this, new RoutedEventArgs()); + } + } + + private void Window_KeyUp(object sender, KeyEventArgs e) + { + return; + } } } \ No newline at end of file diff --git a/Solution/CubeManipulator/MainWindow.xaml b/Solution/CubeManipulator/MainWindow.xaml index 855936a..15897ef 100644 --- a/Solution/CubeManipulator/MainWindow.xaml +++ b/Solution/CubeManipulator/MainWindow.xaml @@ -5,7 +5,11 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:CubeManipulator" mc:Ignorable="d" - Title="MainWindow" Height="350" Width="450"> + Title="CubeManipulator" Height="350" Width="450" + KeyDown="Window_KeyDown" + Focusable="True" + KeyUp="Window_KeyUp" + > diff --git a/Solution/CubeManipulator/MainWindow.xaml.cs b/Solution/CubeManipulator/MainWindow.xaml.cs index 9fcb7bf..b0d366a 100644 --- a/Solution/CubeManipulator/MainWindow.xaml.cs +++ b/Solution/CubeManipulator/MainWindow.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using LibCubeIntegration.PerformMoveStrategies; +using System.Windows; +using System.Windows.Input; namespace CubeManipulator { @@ -7,11 +9,46 @@ namespace CubeManipulator /// public partial class MainWindow : Window { + MoveViaApiStrategy moveStrategy = new MoveViaApiStrategy("CubeProxy"); + + private readonly Dictionary moveKeyMap = new() + { + { Key.U, "U" }, + { Key.L, "L" }, + { Key.B, "B" }, + { Key.M, "M" }, + { Key.F, "F" }, + { Key.R, "R" }, + { Key.D, "D" }, + { Key.S, "S" }, + }; + public MainWindow() { InitializeComponent(); DataContext = new CubeManipulatorViewModel(); //Get ViewModel } + + private void Window_KeyDown(object sender, KeyEventArgs e) + { + if (moveKeyMap.TryGetValue(e.Key, out string? moveFound)) + { + if (moveFound is string move) + { + ProcessMove(move); + } + } + } + + private void Window_KeyUp(object sender, KeyEventArgs e) + { + return; + } + + private void ProcessMove(string x) + { + _ = moveStrategy.PerformMoveAsync(x); + } } } \ No newline at end of file diff --git a/Solution/CubeVisualizer/CubeGame.cs b/Solution/CubeVisualizer/CubeGame.cs index 31d14bc..b882d15 100644 --- a/Solution/CubeVisualizer/CubeGame.cs +++ b/Solution/CubeVisualizer/CubeGame.cs @@ -35,6 +35,9 @@ public class CubeGame : Game float _YRotation = MathHelper.ToRadians(225); float _XRotation = MathHelper.ToRadians(45); + bool _userInteracted = false; + KeyboardState _prevKeyboardState = Keyboard.GetState(); + private HubConnection _connection; public CubeGame(string pWindowName, int pWindowHeight, int pWindowWidth, Color pBGColour) @@ -46,6 +49,8 @@ public CubeGame(string pWindowName, int pWindowHeight, int pWindowWidth, Color p _graphics.PreferredBackBufferHeight = pWindowHeight; _graphics.PreferredBackBufferWidth = pWindowWidth; _BackgroundColour = pBGColour; + + this.InactiveSleepTime = TimeSpan.Zero; } protected override void Initialize() @@ -105,8 +110,8 @@ private HubConnection GetHubConnection() protected override void Update(GameTime gameTime) { - if (!IsActive) - return; + //if (!IsActive) + // return; if (Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); @@ -116,12 +121,35 @@ protected override void Update(GameTime gameTime) float rotation = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f; MouseState mouseState = Mouse.GetState(); - if (mouseState.LeftButton == ButtonState.Pressed && _PrevMouseState.LeftButton == ButtonState.Pressed) + + if (!_userInteracted && (mouseState.LeftButton == ButtonState.Pressed || mouseState.RightButton == ButtonState.Pressed || mouseState.MiddleButton == ButtonState.Pressed)) + { + _userInteracted = true; + } + + KeyboardState keyboardState = Keyboard.GetState(); + + if (keyboardState.IsKeyDown(Keys.Enter) && _prevKeyboardState.IsKeyUp(Keys.Enter)) { - xDelta = mouseState.X - _PrevMouseState.X; - yDelta = _PrevMouseState.Y - mouseState.Y; + _userInteracted = !_userInteracted; } - _PrevMouseState = mouseState; + _prevKeyboardState = keyboardState; + + if (_userInteracted && IsActive) + { + if (mouseState.LeftButton == ButtonState.Pressed && _PrevMouseState.LeftButton == ButtonState.Pressed) + { + xDelta = mouseState.X - _PrevMouseState.X; + yDelta = _PrevMouseState.Y - mouseState.Y; + } + _PrevMouseState = mouseState; + } + else + { + xDelta = 20f * rotation; // passive Y rotation speed + yDelta = 0.0f; + } + _YRotation += xDelta * rotation * MouseSpeed; _XRotation += yDelta * rotation * MouseSpeed; diff --git a/Solution/FaceViewerCLI/Program.cs b/Solution/FaceViewerCLI/Program.cs index 3e89aff..6b364f2 100644 --- a/Solution/FaceViewerCLI/Program.cs +++ b/Solution/FaceViewerCLI/Program.cs @@ -8,8 +8,7 @@ class Program { static readonly FacePresenter Presenter = new(); static CubeState _cubeState = new(new CubePuzzle().GetState()); - - static readonly CubeServiceFacade _cubeService = new CubeServiceFacade("CubeService"); + static readonly CubeServiceFacade _cubeService = new CubeServiceFacade("CubeProxy"); static async Task Main() { diff --git a/misc/example-screenshot.png b/misc/example-screenshot.png index 722d186..e424fd2 100644 Binary files a/misc/example-screenshot.png and b/misc/example-screenshot.png differ