private void DeviceOnReport(DS4Device sender, EventArgs args) { _isAlive = !sender.IsRemoved; var state = sender.getCurrentState(); var previousState = sender.getPreviousState(); var current = state.GetType().GetFields().Where(field => field.FieldType == typeof(bool)) .ToDictionary(field => field.Name, field => (bool)field.GetValue(state)); var previous = state.GetType().GetFields().Where(field => field.FieldType == typeof(bool)) .ToDictionary(field => field.Name, field => (bool)field.GetValue(previousState)); var activeCurrent = current.Where(val => val.Value).ToDictionary(i => i.Key, i => i.Value); var activePrevious = previous.Where(val => val.Value).ToDictionary(i => i.Key, i => i.Value); var inativeCurrent = current.Where(val => !val.Value).ToDictionary(i => i.Key, i => i.Value); var inactivePrevious = previous.Where(val => !val.Value).ToDictionary(i => i.Key, i => i.Value); var l3 = GetNormalized(state.LX, state.LY); var l3P = GetNormalized(previousState.LX, previousState.LY); Move?.Invoke(l3); if (state.L2Btn || state.R2Btn) { Breath?.Invoke(new Vector2(state.L2, state.R2)); } else { BreathRelease?.Invoke(); } //Move Up if (l3.Y > .5f) { if (l3P.Y < .5 && l3P.Y > 0) { Next?.Invoke(); } } //Move Down if (l3.Y < -.5) { if (l3P.Y > -.5) { Previous?.Invoke(); } } OnButtonPressedEvent(sender, state); foreach (var c in activeCurrent.Where(c => !activePrevious.ContainsKey(c.Key))) { if (CanReceiveInput) { OnOnButtonClickEvent(sender, state, c.Key); } } foreach (var c in inativeCurrent.Where(c => activePrevious.ContainsKey(c.Key))) { if (CanReceiveInput) { OnReleaseClickEvent(sender, state, c.Key); } } }
void Update() { if (_isAlive) { return; } var move = new Vector2(0, 0); if (_input.KeyPressed(Key.W)) { move.Y = 1; } if (_input.KeyPressed(Key.S)) { move.Y = -1; } if (_input.KeyPressed(Key.D)) { move.X = 1; } if (_input.KeyPressed(Key.A)) { move.X = -1; } Move?.Invoke(move); var breath = new Vector2(0, 0); if (_input.KeyPressed(Key.LShift)) { breath.X = 1; } if (_input.KeyPressed(Key.RShift)) { breath.Y = 1; } Breath?.Invoke(breath); if (_input.KeyPressed(Key.Space)) { Jump?.Invoke(); } if (_input.KeyDown(Key.J)) { Attack?.Invoke(); } if (_input.KeyPressed(Key.F)) { Interact?.Invoke(); } if (_input.KeyPressed(Key.Down)) { Previous?.Invoke(); } if (_input.KeyPressed(Key.Up)) { Next?.Invoke(); } if (_input.KeyPressed(Key.Escape)) { CallAction(Menu, "Menu"); } if (_input.KeyPressed(Key.P)) { CallAction(Pause, "Pause"); } if (_input.KeyPressed(Key.Return)) { CallAction(Select, "Select"); } }