public void GetNextInput_Should_Return_Next_Input(int previousCount, int nextCount, string expectedInput) { // arrange var inputHistory = new InputHistory(); foreach (var index in Enumerable.Range(0, 4)) { var input = $"test input # {index}"; inputHistory.Add(input); Console.WriteLine($"[debug] {input}"); } // act foreach (var _ in Enumerable.Range(1, previousCount)) { inputHistory.GetPreviousInput(); } var nextInput = ""; foreach (var _ in Enumerable.Range(1, nextCount)) { nextInput = inputHistory.GetNextInput(); } // assert Assert.That(nextInput, Is.EqualTo(expectedInput)); }
/// <summary> /// Adds a command into the history buffer. /// </summary> /// <param name="cmd"></param> public void AddInputHistory(string cmd) { // Add the command to the history if it wasn't a blank return if (cmd.Length > 0) { // If the command was a duplicate of the last command entered also don't enter it. // We will have people spamming stuff in the game and it doesn't make sense (nor does // any other client) dupliate those in the input history. if (InputHistory.Count > 0 && InputHistory.Last() == cmd) { return; } // Don't add it if it's two letters or less, these are common for directions which are spammed. // n, e, s, w, ne, se, sw, nw, u, d, etc. Also don't add it if it was the same as the previous // last command. if (cmd.Length > 2) { this.InputHistory.Add(cmd); this.Conveyor.SetVariable("LastCommand", cmd); } else { if (!cmd.In(new string[] { "n", "s", "e", "w", "nw", "sw", "ne", "se", "u", "d" })) { this.InputHistory.Add(cmd); this.Conveyor.SetVariable("LastCommand", cmd); } } } // Reset the history position. InputHistoryPosition = 0; }
public void LoadContent(Console console) { Console = console; Console.FontChanged += (s, e) => { CalculateInputPrefixWidth(); _inputBuffer.Font = console.Font; SetDirty(); }; _inputBuffer.Font = console.Font; Console.WindowAreaChanged += (s, e) => SetDirty(); Caret.Moved += (s, e) => SetDirty(); CalculateInputPrefixWidth(); Caret.LoadContent(this); RepeatingInput.LoadContent(this); InputHistory.LoadContent(this); Autocompletion.LoadContent(this); CopyPasting.LoadContent(this); Movement.LoadContent(this); Tabbing.LoadContent(this); Deletion.LoadContent(this); CommandExecution.LoadContent(this); CaseSenitivity.LoadContent(this); Selection.LoadContent(this); _loaded = true; }
public void TODO_State_CanRecordHistory() { var gamepad1 = InputSystem.AddDevice <Gamepad>(); var gamepad2 = InputSystem.AddDevice <Gamepad>(); using (var history = new InputHistory <Vector2>("<Gamepad>/*stick")) { Assert.That(history.controls, Is.EquivalentTo( new[] { gamepad1.leftStick, gamepad1.rightStick, gamepad2.leftStick, gamepad2.rightStick })); history.Enable(); InputSystem.QueueStateEvent(gamepad1, new GamepadState { leftStick = new Vector2(0.123f, 0.234f) }); InputSystem.QueueStateEvent(gamepad1, new GamepadState { leftStick = new Vector2(0.345f, 0.456f) }); InputSystem.QueueStateEvent(gamepad2, new GamepadState { rightStick = new Vector2(0.321f, 0.432f) }); InputSystem.Update(); InputSystem.QueueStateEvent(gamepad1, new GamepadState { leftStick = new Vector2(0.567f, 0.678f) }); InputSystem.Update(); Assert.That(history.Count, Is.EqualTo(3)); Assert.That(history[0], Is.EqualTo(new Vector2(0.123f, 0.234f)).Using(Vector2EqualityComparer.Instance)); Assert.That(history[1], Is.EqualTo(new Vector2(0.345f, 0.456f)).Using(Vector2EqualityComparer.Instance)); Assert.That(history[2], Is.EqualTo(new Vector2(0.567f, 0.678f)).Using(Vector2EqualityComparer.Instance)); } }
public void InitialStartup(ref int progress) { InputHistory.Initialize(); progress++; InputHandlers.Initialize(); progress++; }
internal bool ValidateInput(ICalculatorInput calculatorinput) { if (calculatorinput == null) { return(false); } var input = InputHistory.LastOrDefault(); if (input == null && double.Parse(Result) == 0) { return(calculatorinput is CalculatorValue || calculatorinput == null); } if (input is CalculatorOperator && ((CalculatorOperator)input).OperatorType == OperatorTypes.Divide) { return(!(calculatorinput.Value == "0")); } var last = Input.Replace(" ", "").Split(OperatorButtons.Select(o => o.Value).ToArray(), StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); if ((last == "0." || last == "0") && (calculatorinput is CalculatorOperator && ((CalculatorOperator)calculatorinput).OperatorType == OperatorTypes.Equals)) { return(false); } if ((calculatorinput.Value == "." || calculatorinput.Value == "0.") && last != null && last.Contains(".") && !(input is CalculatorOperator)) { return(false); } return(true); }
public Model() { userScore = 0; opponentScore = 0; roundsPlayed = 0; ihist = new InputHistory(0, 0, 0); }
public void InitialStartup() { InputHistory.Initialize(); InputHandlers.Initialize(); SettingsManager.Initialize(); MusicPlayer.Init(); EffectPlayer.Init(); }
internal Client(INetworkClient client, MatchConfig config) : base(client, config) { NetworkClient.OnRecievedState += OnRecievedState; NetworkClient.OnRecievedInputs += OnRecievedInputs; InputContext = new MatchInputContext(config); InputHistory = new InputHistory <MatchInput>(new MatchInput(config)); NetworkConfig = Config.Get <NetworkConfig>(); InputSendTimer = 0; }
internal Server(INetworkServer server, MatchConfig config) : base(server, config) { NetworkServer.ReceivedInputs += OnRecievedInputs; NetworkServer.PlayerRemoved += OnRemovePlayer; InputContext = new MatchInputContext(config); InputHistory = new InputHistory <MatchInput>(new MatchInput(config)); NetworkConfig = Config.Get <NetworkConfig>(); ClientTimesteps = new Dictionary <int, uint>(); StateSendTimer = 0; }
void AssertHistoryMaintainsOrder <T>(InputHistory <T> history) { var lastTimestep = uint.MinValue; foreach (var timedInput in history.GetFullSequence()) { Assert.That(timedInput.Timestep, Is.GreaterThanOrEqualTo(lastTimestep)); lastTimestep = timedInput.Timestep; } }
public void DropBefore_updates_Current(int start, int count, int dropPoint) { var inputHistory = new InputHistory <int>(0, (uint)start, Merger <int> .FromDelegate((a, b) => a)); inputHistory.MergeWith(0, Enumerable.Range(start, count)); inputHistory.DropBefore((uint)dropPoint); Assert.That(inputHistory.Oldest.Timestep, Is.LessThanOrEqualTo(inputHistory.Current.Timestep)); AssertHistoryMaintainsOrder(inputHistory); }
public void DropBefore_always_leaves_one_input(int start, int count, int dropPoint) { var inputHistory = new InputHistory <int>(0, (uint)start, Merger <int> .FromDelegate((a, b) => a)); inputHistory.MergeWith(0, Enumerable.Range(start, count)); inputHistory.DropBefore((uint)dropPoint); Assert.That(inputHistory.GetFullSequence().Count(), Is.GreaterThanOrEqualTo(1)); AssertHistoryMaintainsOrder(inputHistory); }
internal Server(INetworkServer server, MatchConfig config) : base(server, config) { NetworkServer.ReceivedInputs += OnRecievedInputs; InputContext = new MatchInputContext(config); LatestInput = new MatchInput[1]; LatestInput[0] = new MatchInput(config); InputHistory = new InputHistory <MatchInput>(LatestInput[0]); NetworkConfig = Config.Get <NetworkConfig>(); ClientTimesteps = new Dictionary <uint, uint>(); StateSendTimer = 0; }
public void ProcessSymbol(Symbol symbol) { if (Selection.HasSelection) { Remove(Selection.SelectionStart, Selection.SelectionLength); } Append(CaseSenitivity.ProcessSymbol(symbol)); InputHistory.OnSymbol(symbol); }
public void ProcessAction(ConsoleAction action) { InputHistory.OnAction(action); Autocompletion.OnAction(action); CopyPasting.OnAction(action); Movement.OnAction(action); Tabbing.OnAction(action); Deletion.OnAction(action); CommandExecution.OnAction(action); CaseSenitivity.OnAction(action); }
public void InitialStartup() { if (MagicalLifeSettings.Storage.Player.Default.PlayerID == Guid.Empty) { MagicalLifeSettings.Storage.Player.Default.PlayerID = Guid.NewGuid(); } InputHistory.Initialize(); InputHandlers.Initialize(); SettingsManager.Initialize(); MusicPlayer.Init(); }
public void DropBefore_drops_inputs(int start, int count, int dropPoint) { var inputHistory = new InputHistory <int>(0, (uint)start, Merger <int> .FromDelegate((a, b) => a)); inputHistory.MergeWith(0, Enumerable.Range(start, count)); var expectedCount = dropPoint < start?inputHistory.GetFullSequence().Count() : start + count - dropPoint; inputHistory.DropBefore((uint)dropPoint); Assert.That(inputHistory.Oldest.Timestep, Is.GreaterThanOrEqualTo(dropPoint)); Assert.That(inputHistory.GetFullSequence().Count(), Is.EqualTo(expectedCount)); AssertHistoryMaintainsOrder(inputHistory); }
public void InitialStartup() { SettingsManager.Initialize(); if (SettingsManager.PlayerSettings.Settings.PlayerID == Guid.Empty) { SettingsManager.PlayerSettings.Settings.PlayerID = Guid.NewGuid(); } InputHistory.Initialize(); InputHandlers.Initialize(); MusicPlayer.Init(); this.SaveSettings(); }
public void Append_updates_CurrentInput(int playerCount) { var latestInput = InputUtility.RandomInput(playerCount); var inputHistory = new InputHistory <MatchInput>(latestInput); Assert.That(inputHistory.Current.Input, Is.EqualTo(latestInput)); for (var i = 0; i < 20; i++) { latestInput = InputUtility.RandomInput(playerCount); inputHistory.Append(latestInput); Assert.That(inputHistory.Current.Input, Is.EqualTo(latestInput)); } AssertHistoryMaintainsOrder(inputHistory); }
private static void ContainerDoubleClick(MouseEventArgs clickData) { foreach (GUIContainer item in GUIWindows) { GUIContainer youngest = GetYoungestChild(item); if (youngest.Visible && youngest.DrawingBounds.Contains(clickData.Position)) { DoubleClick(clickData, youngest.Controls, youngest); return; } } //TODO: Make a special map double click handler InputHistory.MapMouseClick(clickData); }
public void Append_increments_CurrentTimestep(int playerCount) { var inputHistory = new InputHistory <MatchInput>(InputUtility.RandomInput(playerCount), 20); Assert.That(inputHistory.Current.Timestep, Is.EqualTo(20)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Current.Timestep, Is.EqualTo(21)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Current.Timestep, Is.EqualTo(22)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Current.Timestep, Is.EqualTo(23)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Current.Timestep, Is.EqualTo(24)); AssertHistoryMaintainsOrder(inputHistory); }
public void Append_increments_Count(int playerCount) { var inputHistory = new InputHistory <MatchInput>(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Count, Is.EqualTo(1)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Count, Is.EqualTo(2)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Count, Is.EqualTo(3)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Count, Is.EqualTo(4)); inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Count, Is.EqualTo(5)); AssertHistoryMaintainsOrder(inputHistory); }
public void Append_does_not_update_Oldest(int playerCount) { var firstInput = InputUtility.RandomInput(playerCount); var inputHistory = new InputHistory <MatchInput>(firstInput, 42); Assert.That(inputHistory.Oldest.Timestep, Is.EqualTo(42)); Assert.That(inputHistory.Oldest.Input, Is.EqualTo(firstInput)); for (var i = 0; i < 20; i++) { inputHistory.Append(InputUtility.RandomInput(playerCount)); Assert.That(inputHistory.Oldest.Input, Is.EqualTo(firstInput)); Assert.That(inputHistory.Oldest.Timestep, Is.EqualTo(42)); } AssertHistoryMaintainsOrder(inputHistory); }
/// <summary> /// Handles container clicks before handling normal UI elements. /// </summary> /// <param name="clickData"></param> /// <returns></returns> private static void ContainerClick(MouseEventArgs clickData) { foreach (GUIContainer item in GUIWindows) { GUIContainer youngest = GetYoungestChild(item); if (youngest.Visible && youngest.DrawingBounds.Contains(clickData.Position)) { Click(clickData, youngest.Controls, youngest); MasterLog.DebugWriteLine("Clicking in menu: " + youngest.GetType().FullName); return; } } //If the click isn't in a GUI, then it must be in the map... InputHistory.MapMouseClick(clickData); }
public void SaveInputsToImage() { Image bm = Bitmap.FromFile($@"blackboard/{connectedUsers[0].SessionId}/save.png"); Graphics g = Graphics.FromImage(bm); foreach (UserInput ui in InputHistory) { //send sessionid just to be sure it saves ui.renderToBitmap(g, Width, Height, connectedUsers[0].SessionId); } bm.Save($@"blackboard/{connectedUsers[0].SessionId}/save.png", ImageFormat.Png); InputHistory.Clear(); bm.Dispose(); g.Dispose(); }
/// <summary> /// Handles container clicks before handling normal UI elements. /// </summary> /// <param name="clickData"></param> /// <returns></returns> private static void ContainerClick(MouseEventArgs clickData) { foreach (GUIContainer item in GUIWindows) { if (item.Visible && item.DrawingBounds.Contains(clickData.Position)) { Click(clickData, item.Controls, item); MasterLog.DebugWriteLine("Clicking in menu: " + item.GetType().FullName); return; } } if (!Click(clickData, Bounds)) { InputHistory.MapMouseClick(clickData); } }
public void MergeWith_merges_stored_values() { var inputHistory = new InputHistory <int>(0, Merger <int> .FromDelegate((a, b) => a + b)); inputHistory.Append(1); inputHistory.Append(2); inputHistory.Append(3); inputHistory.Append(4); inputHistory.Append(5); inputHistory.Append(6); inputHistory.MergeWith(2, new ArraySlice <int>(new[] { 5, 5, 5, 5 })); Assert.That(inputHistory.Select(i => i.Input).ToArray(), Is.EqualTo(new[] { 0, 1, 7, 8, 9, 10, 6 })); AssertHistoryMaintainsOrder(inputHistory); }
public void Append_maintains_order(int playerCount) { var input1 = InputUtility.RandomInput(playerCount); var input2 = InputUtility.RandomInput(playerCount); var input3 = InputUtility.RandomInput(playerCount); var input4 = InputUtility.RandomInput(playerCount); var inputHistory = new InputHistory <MatchInput>(input1); inputHistory.Append(input2); inputHistory.Append(input3); inputHistory.Append(input4); var results = new[] { input1, input2, input3, input4 }; Assert.That(inputHistory.Select(i => i.Input), Is.EqualTo(results)); AssertHistoryMaintainsOrder(inputHistory); }
public static void Change(List <Calculation> calcList, int count) { Console.WriteLine("Enter what you would like to change(Input1, Input2, Operation, Result): "); string userInput = Console.ReadLine(); Calculation tempCalc = calcList[count]; switch (userInput) { case "Input1": Console.WriteLine("Enter input: "); double a = Double.Parse(Console.ReadLine()); tempCalc.SetInputA(a); Calculator.GetResult(tempCalc); InputHistory.GetInstance().InsertHistory(tempCalc, count); break; case "Input2": Console.WriteLine("Enter input: "); double b = Double.Parse(Console.ReadLine()); tempCalc.SetInputB(b); Calculator.GetResult(tempCalc); InputHistory.GetInstance().InsertHistory(tempCalc, count); break; case "Operation": Console.WriteLine("Enter input: "); string op = Console.ReadLine(); tempCalc.SetOperation(op); Calculator.GetResult(tempCalc); InputHistory.GetInstance().InsertHistory(tempCalc, count); break; case "Result": Console.WriteLine("Enter input: "); double res = Double.Parse(Console.ReadLine()); tempCalc.SetResult(res); Calculator.GetResult(tempCalc); InputHistory.GetInstance().InsertHistory(tempCalc, count); break; default: break; } }