public void UpdateTriggersOnPressedCallback() { var system = new KeyboardSystem(); // set up callback var timesCalled = 0; var component = new KeyboardComponent(); component.OnPress(Keys.F, () => timesCalled++); var e = new Cobalt.Ecs.CobaltEntity(); e.Set(component); system.Add(e); // update: should be called this.pressedKeys = new[] { Keys.F }; system.Update(1); Assert.That(timesCalled == 1); // update: shouldn't be called again system.Update(1); Assert.That(timesCalled == 1); // release: shouldn't be called this.pressedKeys = new Keys[0]; system.Update(1); Assert.That(timesCalled == 1); // presss G instead; shouldn't be called this.pressedKeys = new[] { Keys.G }; system.Update(1); Assert.That(timesCalled == 1); }
public void MoveToKeyboardOverridesExistingKeyboardComponent() { // The only way to test this is to change the velocity and see if the new velocity number is used // Set velocity to 100, press D, wait one second; we should move 100px to the right. var expectedVelocity = 100; var entity = new CobaltEntity(); entity.MoveToKeyboard(1); entity.MoveToKeyboard(expectedVelocity); KeyboardSystem.GenerateKeysCallback(() => { // Press D to move X positively return(new Keys[] { Keys.D }); }); // Simulate keypress var keyboardSystem = new KeyboardSystem(); keyboardSystem.Add(entity); keyboardSystem.Update(1); var velocitySystem = new VelocitySystem(); velocitySystem.Add(entity); velocitySystem.Update(1); Assert.That(entity.Get <PositionComponent>().X, Is.EqualTo(expectedVelocity)); }
public void SetupKeyInputInjection() { // This technically has side-effects, but no other tests should care // (outside of this suite) about keyboard input. KeyboardSystem.GenerateKeysCallback(() => { return(this.pressedKeys); }); }
public void IsPressedReturnsTrueIfKeyIsPressed() { var system = new KeyboardSystem(); this.pressedKeys = new[] { Keys.W }; Assert.IsTrue(system.IsPressed(Keys.W)); Assert.IsFalse(system.IsPressed(Keys.A)); Assert.IsFalse(system.IsPressed(Keys.Z)); Assert.IsFalse(system.IsPressed(Keys.X)); Assert.IsFalse(system.IsPressed(Keys.J)); }
private static void UseMonogameCodePaths() { // DI stuff KeyboardSystem.GenerateKeysCallback(() => { var state = Keyboard.GetState(); var toReturn = new List <Keys>(); foreach (Keys key in Enum.GetValues(typeof(Keys))) { if (state.IsKeyDown(key)) { toReturn.Add(key); } } return(toReturn.ToArray()); }); }
public void ConstructorSetsStaticInstance() { var expected = new KeyboardSystem(); Assert.That(KeyboardSystem.Instance, Is.EqualTo(expected)); }
void Awake() { stageBoard = GetComponent <KeyboardSystem>(); controller = GetComponent <MiniGameController>(); }