Beispiel #1
0
        protected override void OnPropertyChanged(string name = null)
        {
            if (!isUpdating)
            {
                switch (name)
                {
                case nameof(TeamName):
                    string shortName = Teams.Where(t => string.Equals(t.Name, TeamName, StringComparison.CurrentCultureIgnoreCase))
                                       .SingleOrDefault()?.ShortName;
                    dispatcher.Dispatch(new SetTeamNameAction(TeamType, TeamName, shortName));
                    var team = Teams.Where(t => string.Equals(t.Name, TeamName, StringComparison.CurrentCultureIgnoreCase)).SingleOrDefault();
                    if (team != null)
                    {
                        dispatcher.Dispatch(new SetTeamColorAction(TeamType, (uint)(team.Color | 0xFF << 24)));
                        dispatcher.Dispatch(new SetTeamLogoAction(TeamType, team.Logo));
                    }
                    break;

                case nameof(TeamColor):
                    dispatcher.Dispatch(new SetTeamColorAction(TeamType, TeamColor));
                    break;
                }
            }
            base.OnPropertyChanged(name);
        }
Beispiel #2
0
 public TeamControlsViewModel(IMainReduxDispatcher dispatcher, TeamType teamType)
 {
     this.dispatcher          = dispatcher;
     dispatcher.StateChanged += Dispatcher_StateChanged;
     TeamType           = teamType;
     EnabledEditCommand = new RelayCommand(() => dispatcher.Dispatch(new StartTeamEditAction()));
     DisableEditCommand = new RelayCommand(() => dispatcher.Dispatch(new EndTeamEditAction()));
     ChangeScoreCommand = new RelayCommand <string>(i => dispatcher.Dispatch(new ChangeScoreAction(teamType, int.Parse(i))));
     ChangeFoulsCommand = new RelayCommand <string>(i => dispatcher.Dispatch(new ChangeFoulsAction(teamType, int.Parse(i))));
 }
 public MainViewModel(IMainReduxDispatcher dispatcher, Func <TeamType, TeamControlsViewModel> teamControlsViewModelFactory,
                      RoosterViewModel rooster)
 {
     this.dispatcher          = dispatcher;
     RoosterViewModel         = rooster;
     dispatcher.StateChanged += UpdateReduxState;
     HomeTeamControls         = teamControlsViewModelFactory(TeamType.Home);
     AwayTeamControls         = teamControlsViewModelFactory(TeamType.Away);
     AdvancePeriodCommand     = new RelayCommand(() => dispatcher.Dispatch(new ChangePeriodAction(+1)));
     BackPeriodCommand        = new RelayCommand(() => dispatcher.Dispatch(new ChangePeriodAction(-1)));
     ResetCommand             = new RelayCommand(() => dispatcher.Dispatch(new ResetAction()));
     EndGameCommand           = new RelayCommand(() => dispatcher.Dispatch(new EndGameAction()));
     ToggleTeamEditCommand    = new RelayCommand(() => dispatcher.Dispatch(new ToggleTeamEditAction()));
     persistenceFileName      = Path.Combine(Path.GetDirectoryName(typeof(MainViewModel).Assembly.Location), "persistence.json");
 }
 public void Start()
 {
     dispatcher.Start();
     try
     {
         if (File.Exists(persistenceFileName))
         {
             var content     = File.ReadAllText(persistenceFileName);
             var loadedState = JsonConvert.DeserializeObject <RootState>(content);
             dispatcher.Dispatch(new LoadStateAction(loadedState));
         }
         var configuration = ConfigLoader.Load();
         if (configuration != null)
         {
             dispatcher.Dispatch(new LoadConfigurationAction(configuration));
         }
     }
     catch (Exception)
     { }
 }