public MainWindowViewModel(IEliteDangerousApi api, MissionCatchUp missionCatchUp, MissionTargetManager missionTargetManager, StateTracker tracker) { Router = new RoutingState(); Activator = new ViewModelActivator(); api.Events().OnCatchedUp .Select(_ => true) .ObserveOn(RxApp.MainThreadScheduler) .ToPropertyEx(this, x => x.DoneLoading); // Change what is showing this.WhenActivated(disposables => { var filledMissionCountChanged = missionTargetManager .Connect() .Where(m => m.IsFilled) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out var stationMissions) .DisposeMany(); api.Events().OnStart .Select(_ => new LocationUpdate(false, "", "")) .Merge(tracker.Location) .CombineLatest(filledMissionCountChanged.Select(_ => 0).Prepend(0), (dockedLocation, _) => dockedLocation) .CombineLatest(api.Events().OnCatchedUp.Delay(TimeSpan.FromMilliseconds(50)), (location, _) => location) // .Where(_ => DoneLoading) .ObserveOn(RxApp.MainThreadScheduler) .Select(e => { var showTurnIn = e.IsDocked ? stationMissions.Any(m => m.Station == e.Station) : stationMissions.Any(m => m.System == e.System); return(showTurnIn // true ? (IRoutableViewModel)((App)Application.Current).Services .GetService <TurnInViewModel>() ! : (IRoutableViewModel)((App)Application.Current).Services .GetService <MissionStatsViewModel>() !); } ) .Do(vm => Router.Navigate.Execute(vm)) .Subscribe(_ => { }) .DisposeWith(disposables); }); Task.Run(() => { missionCatchUp.CatchUp(); api.StartAsync(); }); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); _api = host.Services.GetRequiredService <IEliteDangerousApi>(); _socketHandler = host.Services.GetRequiredService <WebSocketHandler>(); _variableService = host.Services.GetRequiredService <VariablesService>(); _eliteVaInstaller = host.Services.GetRequiredService <EliteVaInstaller>(); _log = host.Services.GetRequiredService <ILogger <Program> >(); await _api.InitializeAsync(); // Sub to events _api.Events.AllEvent += async(sender, e) => await Broadcast("Event", e, true, false); // Sub to statuses _api.Cargo.OnChange += async(sender, e) => await Broadcast("Cargo", _api.Cargo, true, true); _api.Market.OnChange += async(sender, e) => await Broadcast("Market", _api.Market, true, true); _api.Modules.OnChange += async(sender, e) => await Broadcast("Modules", _api.Modules, true, true); _api.Outfitting.OnChange += async(sender, e) => await Broadcast("Outfitting", _api.Outfitting, true, true); _api.Shipyard.OnChange += async(sender, e) => await Broadcast("Shipyard", _api.Shipyard, true, true); _api.Ship.OnChange += async(sender, e) => await Broadcast("Status", _api.Ship, true, true); _api.NavRoute.OnChange += async(sender, e) => await Broadcast("NavRoute", _api.NavRoute, true, true); _api.Backpack.OnChange += async(sender, e) => await Broadcast("Backpack", _api.Backpack, true, true); // Sub to options _api.Bindings.OnChange += async(sender, e) => await _socketHandler.Broadcast(new WebSocketMessage("Bindings", RemoveLineEndings(_api.Bindings.ToXml())), true, true); // Send userprofile await _socketHandler.Broadcast(new WebSocketMessage("UserProfile", UserProfile.Get()), true, true); // Send latest eliteva version await _socketHandler.Broadcast(new WebSocketMessage("EliteVA.Latest", await _eliteVaInstaller.GetLatestVersion()), true, true); await _api.StartAsync(); await host.RunAsync(); }
public async Task Run() { DisableAutostartOnDebug(); LCD.LCDController.InitLcdApp(); /* * // Log whenever we change the landing gear * _api.Status.Gear.OnChange += (sender, isDeployed) => * { * _log.LogInformation(isDeployed ? "Landing gear deployed" : "Landing gear retracted"); * }; * * _api.Events.DockingGrantedEvent += (sender, e) => * { * _log.LogInformation("Landing garanted Event XXX"); * }; */ // Start EliteAPI await _api.StartAsync(); }
public async Task Run() { _api.Status.Gear.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_GEAR = isDeployed; UpdateUI(); }; _api.Status.CargoScoop.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_CARGO = isDeployed; UpdateUI(); }; _api.Status.SilentRunning.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_SILENT = isDeployed; UpdateUI(); }; _api.Status.FlightAssist.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_FLIGHTASSIST = isDeployed; UpdateUI(); }; _api.Status.Hardpoints.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_HARDPOINTS = isDeployed; UpdateUI(); }; _api.Status.NightVision.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_NIGHTVISION = isDeployed; UpdateUI(); }; _api.Status.Lights.OnChange += (sender, isDeployed) => { BTN_STATES.BTN_LIGHTS = isDeployed; UpdateUI(); }; //Taking Damage orange _api.Events.HeatDamageEvent += (sender, e) => { matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: "#FF6500", buttonName: "BTN_HEATSINK"); }; //Close to taking damage yellow _api.Events.HeatWarningEvent += (sender, e) => { matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: "yellow", buttonName: "BTN_HEATSINK"); }; //On Docking event start make icon yellow _api.Events.DockingRequestedEvent += (sender, e) => { matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: "yellow", buttonName: "BTN_DOCKING"); }; //If event was denied make it Traffic Cone Orange _api.Events.DockingDeniedEvent += (sender, e) => { matric.SetActivePage(CLIENT_ID, DeckPages.Flight); UpdateAll(); UpdateUI(); matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: "orange", buttonName: "BTN_DOCKING"); }; //If Granted Go Green _api.Events.DockingGrantedEvent += (sender, e) => { matric.SetActivePage(CLIENT_ID, DeckPages.Docking); UpdateAll(); UpdateUI(); matric.SetButtonProperties(CLIENT_ID, Buttons.LandindPad, text: "Landing Pad: " + e.LandingPad, backgroundcolorOff: "#df1616", backgroundcolorOn: "white"); matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: "green", buttonName: "BTN_DOCKING"); }; //If we cancel it go back to null _api.Events.DockingCancelledEvent += (sender, e) => { matric.SetActivePage(CLIENT_ID, DeckPages.Flight); UpdateAll(); UpdateUI(); matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: null, buttonName: "BTN_DOCKING"); }; //If timeout go back to clear, Would like to go error color for a moment then clear but another day _api.Events.DockingTimeoutEvent += (sender, e) => { matric.SetActivePage(CLIENT_ID, DeckPages.Flight); UpdateAll(); UpdateUI(); matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: null, buttonName: "BTN_DOCKING"); }; _api.Events.DockedEvent += (sender, e) => { matric.SetActivePage(CLIENT_ID, DeckPages.Docking); UpdateAll(); UpdateUI(); matric.SetButtonProperties(CLIENT_ID, Buttons.LandindPad, text: "Docked: " + e.StationName, backgroundcolorOff: "#df1616", backgroundcolorOn: "white"); matric.SetButtonProperties(CLIENT_ID, null, backgroundcolorOff: null, buttonName: "BTN_DOCKING"); }; _api.Events.UndockedEvent += (sender, e) => { matric.SetActivePage(CLIENT_ID, DeckPages.Flight); UpdateAll(); UpdateUI(); }; _api.OnCatchedUp += (sender, e) => { UpdateAll(); UpdateUI(); }; // Start EliteAPI await _api.StartAsync(); }