/// <summary> /// Starts the timer to update map objects and the handler to update position /// </summary> public static async Task InitializeDataUpdate() { _geolocator = new Geolocator { DesiredAccuracy = PositionAccuracy.High, DesiredAccuracyInMeters = 5, ReportInterval = 5000, MovementThreshold = 5 }; Busy.SetBusy(true, Resources.CodeResources.GetString("GettingGpsSignalText")); Geoposition = Geoposition ?? await _geolocator.GetGeopositionAsync(); GeopositionUpdated?.Invoke(null, Geoposition); _geolocator.PositionChanged += async(s, e) => { Geoposition = e.Position; // Updating player's position var position = Geoposition.Coordinate.Point.Position; await _client.Player.UpdatePlayerLocation(position.Latitude, position.Longitude, position.Altitude); GeopositionUpdated?.Invoke(null, Geoposition); }; // Before starting we need game settings GameSetting = await DataCache.GetAsync(nameof(GameSetting), async() => (await _client.Download.GetSettings()).Settings, DateTime.Now.AddMonths(1)); // Update geolocator settings based on server _geolocator.MovementThreshold = GameSetting.MapSettings.GetMapObjectsMinDistanceMeters; _mapUpdateTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(GameSetting.MapSettings.GetMapObjectsMinRefreshSeconds) }; _mapUpdateTimer.Tick += async(s, e) => { // Update before starting but only if more than 10s passed since the last one if ((DateTime.Now - _lastUpdate).Seconds <= GameSetting.MapSettings.GetMapObjectsMinRefreshSeconds) { return; } Logger.Write("Updating map"); try { await UpdateMapObjects(); } catch (Exception ex) { await ExceptionHandler.HandleException(ex); } }; // Update before starting timer Busy.SetBusy(true, Resources.CodeResources.GetString("GettingUserDataText")); await UpdateMapObjects(); await UpdateInventory(); await UpdateItemTemplates(); Busy.SetBusy(false); }
/// <summary> /// Starts the timer to update map objects and the handler to update position /// </summary> public static async Task InitializeDataUpdate() { _geolocator = new Geolocator { DesiredAccuracy = PositionAccuracy.High, DesiredAccuracyInMeters = 5, ReportInterval = 5000, MovementThreshold = 5 }; Busy.SetBusy(true, Resources.Translation.GetString("GettingGPSSignal")); Geoposition = Geoposition ?? await _geolocator.GetGeopositionAsync(); GeopositionUpdated?.Invoke(null, Geoposition); _geolocator.PositionChanged += (s, e) => { Geoposition = e.Position; GeopositionUpdated?.Invoke(null, Geoposition); }; _mapUpdateTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(10) }; _mapUpdateTimer.Tick += async(s, e) => { Logger.Write("Updating map"); await UpdateMapObjects(); }; // Update before starting timer Busy.SetBusy(true, Resources.Translation.GetString("GettingUserData")); await UpdateMapObjects(); await UpdateInventory(); Busy.SetBusy(false); }
/// <summary> /// Starts the timer to update map objects and the handler to update position /// </summary> public static async Task InitializeDataUpdate() { if (SettingsService.Instance.IsCompassEnabled) { _compass = Compass.GetDefault(); if (_compass != null) { _compassTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(Math.Max(_compass.MinimumReportInterval, 50)) }; _compassTimer.Tick += (s, e) => { if (SettingsService.Instance.IsAutoRotateMapEnabled) { HeadingUpdated?.Invoke(null, _compass.GetCurrentReading()); } }; _compassTimer.Start(); } } _geolocator = new Geolocator { DesiredAccuracy = PositionAccuracy.High, DesiredAccuracyInMeters = 5, ReportInterval = 1000, MovementThreshold = 5 }; Busy.SetBusy(true, Resources.CodeResources.GetString("GettingGpsSignalText")); Geoposition = Geoposition ?? await _geolocator.GetGeopositionAsync(); GeopositionUpdated?.Invoke(null, Geoposition); _geolocator.PositionChanged += GeolocatorOnPositionChanged; // Before starting we need game settings GameSetting = await DataCache.GetAsync(nameof(GameSetting), async() => (await _client.Download.GetSettings()).Settings, DateTime.Now.AddMonths(1)); // Update geolocator settings based on server _geolocator.MovementThreshold = GameSetting.MapSettings.GetMapObjectsMinDistanceMeters; if (_heartbeat == null) { _heartbeat = new Heartbeat(); } await _heartbeat.StartDispatcher(); // Update before starting timer Busy.SetBusy(true, Resources.CodeResources.GetString("GettingUserDataText")); //await UpdateMapObjects(); await UpdateInventory(); await UpdateItemTemplates(); Busy.SetBusy(false); }
private static async void GeolocatorOnPositionChanged(Geolocator sender, PositionChangedEventArgs args) { Geoposition = args.Position; // Updating player's position var position = Geoposition.Coordinate.Point.Position; if (_client != null) { await _client.Player.UpdatePlayerLocation(position.Latitude, position.Longitude, Geoposition.Coordinate.Accuracy); } GeopositionUpdated?.Invoke(null, Geoposition); }
/// <summary> /// Starts the timer to update map objects and the handler to update position /// </summary> public static async Task InitializeDataUpdate() { #region Compass management SettingsService.Instance.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { if (e.PropertyName == nameof(SettingsService.Instance.MapAutomaticOrientationMode)) { switch (SettingsService.Instance.MapAutomaticOrientationMode) { case MapAutomaticOrientationModes.Compass: _compass = Compass.GetDefault(); _compass.ReportInterval = Math.Max(_compass.MinimumReportInterval, 50); _compass.ReadingChanged += compass_ReadingChanged; break; case MapAutomaticOrientationModes.None: case MapAutomaticOrientationModes.GPS: default: if (_compass != null) { _compass.ReadingChanged -= compass_ReadingChanged; _compass = null; } break; } } }; //Trick to trigger the PropertyChanged for MapAutomaticOrientationMode ;) SettingsService.Instance.MapAutomaticOrientationMode = SettingsService.Instance.MapAutomaticOrientationMode; #endregion _geolocator = new Geolocator { DesiredAccuracy = PositionAccuracy.High, DesiredAccuracyInMeters = 5, ReportInterval = 1000, MovementThreshold = 5 }; Busy.SetBusy(true, Resources.CodeResources.GetString("GettingGpsSignalText")); Geoposition = Geoposition ?? await _geolocator.GetGeopositionAsync(); GeopositionUpdated?.Invoke(null, Geoposition); _geolocator.PositionChanged += GeolocatorOnPositionChanged; // Before starting we need game settings GameSetting = await DataCache.GetAsync(nameof(GameSetting), async() => (await _client.Download.GetSettings()).Settings, DateTime.Now.AddMonths(1)); // Update geolocator settings based on server _geolocator.MovementThreshold = GameSetting.MapSettings.GetMapObjectsMinDistanceMeters; if (_heartbeat == null) { _heartbeat = new Heartbeat(); } await _heartbeat.StartDispatcher(); // Update before starting timer Busy.SetBusy(true, Resources.CodeResources.GetString("GettingUserDataText")); //await UpdateMapObjects(); await UpdateInventory(); await UpdateItemTemplates(); Busy.SetBusy(false); }