public static _GameState ParseStates(string rawEvent, string rawState) { // get pipe game event enum value _events.TryGetValue(rawEvent, out var pipeEvent); var resultState = new _GameState { RawEvent = rawEvent, RawState = rawState, Event = pipeEvent, States = CollectionHelper.GetEmptyEnumerable <ZGameState>().ToArray() }; // select handle paths switch (pipeEvent) { case ZGameEvent.StateChanged: var endOfStatesIndex = rawState.IndexOfAny("0123456789".ToCharArray()); // Some states may not have numbers, so we need to handle this situation endOfStatesIndex = endOfStatesIndex != -1 ? endOfStatesIndex : rawState.Length; var stateString = rawState.Substring(0, endOfStatesIndex); var splitStates = stateString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var states = splitStates.Select(state => { // get game state enum value _states.TryGetValue(state, out var stateEnum); return(stateEnum); }).ToArray(); resultState.States = states; break; case ZGameEvent.Alert: break; case ZGameEvent.GameWaiting: break; case ZGameEvent.Unknown: default: _log.Warning($"{nameof(_GameStateParser)} event doesn't match ({rawEvent} {rawState})"); break; } return(resultState); }
private void _OnPipeEvent(_GameState state) => PipeEvent?.Invoke(state);
private void _PipeEventHandler(_GameState state) { _onMessage(state.Event, state.RawEvent, state.States, state.RawState); }