コード例 #1
0
 private void ConnectionOpened(StreamDeckService conn)
 {
     _clients.Add(conn);
     conn.Send(new CurrentCharactersMessage
     {
         Player1CharacterIconPath = _runningSetVM.Opponent1.Character.FilePath,
         Player2CharacterIconPath = _runningSetVM.Opponent2.Character.FilePath
     });
     conn.Send(new CurrentScoreMessage
     {
         ScoreP1 = _runningSetVM.Opponent1.Score,
         ScoreP2 = _runningSetVM.Opponent2.Score
     });
 }
コード例 #2
0
        private void MessageReceived(StreamDeckService conn, BaseMessage mess)
        {
            if (mess is IncrementPlayerScoreMessage incrementMessage)
            {
                if (incrementMessage.Player == 1)
                {
                    _runningSetVM.IncrementEntrant1Command?.Execute(null);
                }
                else if (incrementMessage.Player == 2)
                {
                    _runningSetVM.IncrementEntrant2Command?.Execute(null);
                }
            }
            else if (mess is DecrementPlayerScoreMessage decrementMessage)
            {
                if (decrementMessage.Player == 1)
                {
                    _runningSetVM.DecrementEntrant1Command?.Execute(null);
                }
                else if (decrementMessage.Player == 2)
                {
                    _runningSetVM.DecrementEntrant2Command?.Execute(null);
                }
            }
            else if (mess is ChangeCharacterMessage changeCharacter)
            {
                var availableCharacter = _runningSetVM.CharacterList.Where(c => c.Category == _runningSetVM.SelectedCharacterCategory).ToList();

                if (availableCharacter.Find(c => c.Name == changeCharacter.CharacterName) == null)
                {
                    return;
                }

                if (changeCharacter.PlayerId == 1)
                {
                    _runningSetVM.Opponent1.Character = availableCharacter.Find(c => c.Name == changeCharacter.CharacterName);
                }
                else if (changeCharacter.PlayerId == 2)
                {
                    _runningSetVM.Opponent2.Character = availableCharacter.Find(c => c.Name == changeCharacter.CharacterName);
                }
                else if (changeCharacter.PlayerId == 3)
                {
                    _runningSetVM.Opponent3.Character = availableCharacter.Find(c => c.Name == changeCharacter.CharacterName);
                }
                else if (changeCharacter.PlayerId == 4)
                {
                    _runningSetVM.Opponent4.Character = availableCharacter.Find(c => c.Name == changeCharacter.CharacterName);
                }
            }
            else if (mess is GetCharacterListMessage)
            {
                var availableCharacter         = _runningSetVM.CharacterList.ToList().Where(c => c.Category == _runningSetVM.SelectedCharacterCategory).ToList();
                List <CharacterInfo> charaList = new List <CharacterInfo>();
                foreach (var character in availableCharacter)
                {
                    string[] info = character.Name.Split('_');
                    if (info.Length == 1) // No alt
                    {
                        charaList.Add(new CharacterInfo {
                            Name = character.Name, IconPath = character.FilePath
                        });
                    }
                    else // There is alt
                    {
                        string charaName   = string.Join("_", info.SubArray(0, info.Length - 1));
                        string charaAlt    = info.Last();
                        var    sourceChara = charaList.Find(c => c.Name == charaName);
                        if (sourceChara == null) // But we have to create the first entry
                        {
                            var characterEntry = new CharacterInfo {
                                Name = charaName, IconPath = character.FilePath
                            };
                            var altEntry = new CharacterAltInfo()
                            {
                                Name = character.Name, IconPath = character.FilePath
                            };
                            characterEntry.Alts.Add(altEntry);
                            charaList.Add(characterEntry);
                        }
                        else
                        {
                            if (sourceChara.Alts.Count == 0) // In the case of the first entry was not created with the good alt, replace it by the good first one.
                            {
                                var mainAltEntry = new CharacterAltInfo()
                                {
                                    Name = sourceChara.Name, IconPath = sourceChara.IconPath
                                };
                                sourceChara.Alts.Add(mainAltEntry);
                            }
                            var altEntry = new CharacterAltInfo()
                            {
                                Name = character.Name, IconPath = character.FilePath
                            };
                            sourceChara.Alts.Add(altEntry);
                        }
                    }
                }
                conn.Send(new CharacterListMessage {
                    Characters = charaList
                });
            }
            else if (mess is SwapPlayerMessage)
            {
                _runningSetVM.SwapPlayerCommand?.Execute(null);
            }
            else if (mess is ResetScoreMessage)
            {
                _runningSetVM.ResetCommand?.Execute(null);
            }
            else if (mess is GetCurrentCharactersMessage)
            {
                conn.Send(new CurrentCharactersMessage
                {
                    Player1CharacterIconPath = _runningSetVM.Opponent1.Character.FilePath,
                    Player2CharacterIconPath = _runningSetVM.Opponent2.Character.FilePath
                });
            }
            else if (mess is GetCurrentScoreMessage)
            {
                conn.Send(new CurrentScoreMessage
                {
                    ScoreP1 = _runningSetVM.Opponent1.Score,
                    ScoreP2 = _runningSetVM.Opponent2.Score
                });
            }
        }