コード例 #1
0
ファイル: _GameStateParser.cs プロジェクト: GVNCoder/Zlo4NET
        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);
        }
コード例 #2
0
ファイル: _GamePipe.cs プロジェクト: GVNCoder/Zlo4NET
 private void _OnPipeEvent(_GameState state) => PipeEvent?.Invoke(state);
コード例 #3
0
ファイル: ZGameProcess.cs プロジェクト: GVNCoder/Zlo4NET
 private void _PipeEventHandler(_GameState state)
 {
     _onMessage(state.Event, state.RawEvent, state.States, state.RawState);
 }