public TitleViewModel(IScreen screen) : base(screen, "main") { using var store = new ModsDataStore(); IsLoaded = store.GetPlayableMods().Any(); SettingsAction = ReactiveCommand.CreateFromObservable(() => HostScreen.Router.Navigate.Execute(new SettingsViewModel(HostScreen))); ModsAction = ReactiveCommand.CreateFromObservable(() => HostScreen.Router.Navigate.Execute(new ModsViewModel(HostScreen))); MatchupAction = ReactiveCommand.CreateFromObservable(() => HostScreen.Router.Navigate.Execute(new GenerationViewModel(HostScreen))); CloseApp = ReactiveCommand.Create(() => Environment.Exit(0)); }
public GenerationViewModel(IScreen screen) : base(screen, "generation") { GameTab = new GameTabViewModel(); TeamTab = new TeamTabViewModel(); using var store = new ModsDataStore(); DowMod[] mods = store.GetPlayableMods().ToArray(); IEnumerable <DowMod> addonMods = mods.Where(mod => !mod.IsVanilla && DowConstants.IsVanilla(mod.ModFolder)); IEnumerable <DowMod> baseMods = mods.Where(mod => mod.IsVanilla || !DowConstants.IsVanilla(mod.ModFolder)); GeneralTab = new GeneralTabViewModel(addonMods.SelectMany(mod => mod.Maps).ToList()); Mod = new OptionInputViewModel <DowMod>(mod => mod.Name, baseMods.ToArray()); RefreshMod = ReactiveCommand.Create((DowMod mod) => { GeneralTab.Mod = mod; }); GenerateMatchupAction = ReactiveCommand.CreateFromObservable(() => { var settings = new GenerationSettings() { Mod = Mod.SelectedItem.Item, Maps = GeneralTab.Maps.Items.Concat(GeneralTab.AddonMaps.Items) .Where(map => map.IsEnabled && map.IsToggled) .Select(map => map.Item).ToList(), Rules = GeneralTab.Rules.Items .Where(rule => rule.IsToggled) .Select(rule => rule.Item).ToList() }; foreach (var diff in GameTab.DiffOption.Items) { settings.GameDifficultyTickets[(int)diff.Item] = diff.Input; } foreach (var speed in GameTab.SpeedOption.Items) { settings.GameSpeedTickets[(int)speed.Item] = speed.Input; } foreach (var rate in GameTab.RateOption.Items) { settings.ResourceRateTickets[(int)rate.Item] = rate.Input; } foreach (var start in GameTab.StartingOption.Items) { settings.StartResourceTickets[(int)start.Item] = start.Input; } return(HostScreen.Router.Navigate.Execute(new MatchupViewModel(HostScreen, settings))); }); this.WhenAnyValue(x => x.Mod.SelectedItem) .DistinctUntilChanged() .Select(mod => mod.Item) .InvokeCommand(RefreshMod); }