public override ActivityStep ResolveStep(GameEntity entity) { float chanceToStop = entity.isAggressive ? 0.2f : 0.07f; if (!_targetToKeepDistanceTo.hasPosition || _rng.Check(chanceToStop)) { return(Succeed(entity)); } int turnsPassed = 1; // osnowatodo Contexts.sharedInstance.game.turMinelo.Tur; bool targetPositionHasChanged = _targetToKeepDistanceTo.position.Position != _lastTargetPosition; float chanceToKeepPosition = 0.8f; bool shouldKeepPosition = !targetPositionHasChanged && _rng.Check(chanceToKeepPosition); if (shouldKeepPosition) { return(KeepPosition(entity)); } bool recalculateCooldownHasPassed = turnsPassed >= _turnsPassedToRecalculate; bool shouldRecalculate = (_navigationDataToGoodPosition == null) || (recalculateCooldownHasPassed && (targetPositionHasChanged || _rng.Check(0.2f))); if (shouldRecalculate) { _turnsPassedToRecalculate = turnsPassed + 3; _lastTargetPosition = _targetToKeepDistanceTo.position.Position; IFloodArea targetFlood = _calculatedAreaAccessor.FetchWalkableFlood(_lastTargetPosition, _preferredDistance); _navigationDataToGoodPosition = FindNavigationDataToGoodPosition(entity, targetFlood, _preferredDistance); if (_navigationDataToGoodPosition == null) { return(Fail(entity)); } } Position nextStep; NavigationResult navigationResult = _navigator.ResolveNextStep(_navigationDataToGoodPosition, entity.position.Position, out nextStep); if (navigationResult == NavigationResult.Finished) { return(new ActivityStep { GameAction = _actionFactory.CreatePassAction(entity), State = ActivityState.InProgress }); } if (nextStep == PositionUtilities.Min) { return(Fail(entity)); } IGameAction moveGameAction = CreateMoveAction(entity, nextStep); return(new ActivityStep { State = ActivityState.InProgress, GameAction = moveGameAction }); }
/// <summary> /// Navigations the completed. /// </summary> /// <param name="result">The result.</param> private void NavigationCompleted(NavigationResult result) { if (result.Result != null && !result.Result.Value && result.Error != null) { throw new InvalidOperationException(result.Error.Message); } }
public async Task <INavigationResult> ShowFlyoutAsync(string name, INavigationParameters parameters) { var result = new NavigationResult(); var page = CreatePageFromSegment(name); if (page is BottomFlyoutPage flyoutPage) { _flyoutPage = flyoutPage; var useModalNavigation = true; var animated = false; var uri = UriParsingHelper.Parse(name); var navigationSegments = UriParsingHelper.GetUriSegments(uri); var nextSegment = navigationSegments.Dequeue(); await ProcessNavigation(flyoutPage, navigationSegments, parameters, useModalNavigation, animated); await DoNavigateAction(page, nextSegment, flyoutPage, parameters, async() => { await DoPush(GetCurrentPage(), flyoutPage, useModalNavigation, animated); }); await flyoutPage.AppearingAnimation(); result.Success = true; return(result); } return(await NavigateAsync(name, parameters)); }
public async Task <INavigationResult> CloseFlyoutAsync() { if (_flyoutPage != null) { await _flyoutPage.DisappearingAnimation(); } /* * Workaround for Prism 8.1.97 * PopUp Page wasnt completely removed */ var result = new NavigationResult(); var page = GetCurrentPage(); var poppedPage = await DoPop(page.Navigation, true, false); if (poppedPage != null) { Prism.Common.PageUtilities.DestroyPage(poppedPage); result.Success = true; return(result); } /* * End of workaround */ return(await GoBackInternal(null, useModalNavigation : true, animated : false)); }
private void NavigationCallback(NavigationResult result) { if (result.Result == true) { RaiseUpdateMenuEvent(result); } }
protected virtual void NavigationComplete(NavigationResult result) { IsNavButtonChecked = true; RaisePropertyChanged(nameof(DropShadowColor)); Log.Debug($"Navigating to {result.Context.Uri.ToString()}"); event_aggregator.GetEvent <NavigationEvent>().Publish(Module); }
private void CheckForError(NavigationResult nr) { if (nr.Result == false) { //throw new Exception(nr.Error.Message); } }
public void ResolveNextStep_NextStepIsWalkableDestination_ReturnsInProgressWithNextStepAndUpcomingStepsAreCorrect() { var currentPosition = new Position(2, 2); var destination = new Position(3, 2); IPathfinder pathfinder = Mock.Of <IPathfinder>(); IGridInfoProvider gridInfoProvider = Mock.Of <IGridInfoProvider>(p => p.IsWalkable(It.IsAny <Position>()) == true); var navigator = new Navigator(pathfinder, gridInfoProvider, Mock.Of <INaturalLineCalculator>(), Mock.Of <IRasterLineCreator>(), Mock.Of <IUiFacade>()); var navigationData = new NavigationData { Destination = destination, RemainingStepsInCurrentSegment = new Stack <Position>(new[] { destination }), RemainingNodes = new List <Position> { destination }, LastStep = currentPosition }; Position nextStep; NavigationResult result = navigator.ResolveNextStep(navigationData, currentPosition, out nextStep); result.Should().Be(NavigationResult.InProgress); nextStep.Should().Be(destination); navigationData.RemainingStepsInCurrentSegment.Should().BeEmpty(); navigationData.LastStep.Should().Be(destination); navigationData.RemainingNodes.Should().BeEmpty(); }
public void WhenNavigatingWithNullUri_Throws() { // Prepare IRegion region = new Region(); var containerMock = new Mock <IContainerExtension>(); containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(new RegionNavigationJournalEntry()); IContainerExtension container = containerMock.Object; RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(container).Object; IRegionNavigationJournal journal = new Mock <IRegionNavigationJournal>().Object; RegionNavigationService target = new RegionNavigationService(container, contentLoader, journal) { Region = region }; // Act NavigationResult navigationResult = null; target.RequestNavigate((Uri)null, nr => navigationResult = nr); // Verify Assert.False(navigationResult.Result.Value); Assert.NotNull(navigationResult.Error); Assert.IsType <ArgumentNullException>(navigationResult.Error); }
public void WhenNavigatingWithNullUri_Throws() { // Prepare IRegion region = new Region(); var serviceLocatorMock = new Mock <IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance <IRegionNavigationJournalEntry>()).Returns(new RegionNavigationJournalEntry()); IServiceLocator serviceLocator = serviceLocatorMock.Object; RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object; IRegionNavigationJournal journal = new Mock <IRegionNavigationJournal>().Object; RegionNavigationService target = new RegionNavigationService(serviceLocator, contentLoader, journal); target.Region = region; // Act NavigationResult navigationResult = null; target.RequestNavigate((Uri)null, nr => navigationResult = nr); // Verify Assert.IsFalse(navigationResult.Result.Value); Assert.IsNotNull(navigationResult.Error); Assert.IsInstanceOfType(navigationResult.Error, typeof(ArgumentNullException)); }
/// <summary> /// The navigation callback gets the view and stores a reference to it in the /// navigation settings. It also gets the data paremeter and passes it to the /// view model's by calling the Publish method. /// </summary> /// <param name="navigationResult">The navigation result.</param> private void NavigationCompleted(NavigationResult navigationResult) { if (navigationResult.Context.NavigationService.Region.Name.Equals("DocumentRegion")) { if (navigationResult.Result.HasValue && !navigationResult.Result.Value) { // Navigation has been cancelled. return; } var query = navigationResult.Context.Parameters; var navigationId = query["NavigationId"].ToString(); NavigationSettings navigationSettings; if (navigationSettingsList.TryGetValue(navigationId, out navigationSettings)) { object data = navigationSettings.Data; var view = navigationResult.Context.NavigationService.Region.Views.FirstOrDefault( v => (((DocumentViewBase)v).ViewModel.NavigationId.Equals(navigationId))); var documentView = (DocumentViewBase)view; navigationSettings.DocumentView = documentView; documentView.ViewModel.PublishData(data); return; } var message = String.Format("The navigation list does not contain a Uri for navigation id {0}.", navigationId); throw new Exception(message); } }
public override ActivityStep ResolveStep(GameEntity entity) { if (_navigationData == null) { _navigationData = _navigator.GetNavigationData(entity.position.Position, _destination); if (_navigationData == null) { return(Fail(entity)); } } Position nextStep; NavigationResult navigationResult = _navigator.ResolveNextStep(_navigationData, entity.position.Position, out nextStep); if (navigationResult == NavigationResult.Finished) { return(Succeed(entity)); } IGameAction moveGameAction = CreateMoveAction(nextStep, entity); return(new ActivityStep { State = ActivityState.InProgress, GameAction = moveGameAction }); }
public void ResolveNextStep_ActorWasDisplacedToPositionNeighboringLastStepButNotNextStep_ReturnsInProgressWithMovementToLastStepAndStackIsCorrect() { var currentPosition = new Position(-1, 1); var lastStepPosition = new Position(0, 1); var nextPosition = new Position(1, 1); IPathfinder pathfinder = Mock.Of <IPathfinder>(); IGridInfoProvider gridInfoProvider = Mock.Of <IGridInfoProvider>(p => p.IsWalkable(It.IsAny <Position>()) == true); var navigator = new Navigator(pathfinder, gridInfoProvider, Mock.Of <INaturalLineCalculator>(), Mock.Of <IRasterLineCreator>(), Mock.Of <IUiFacade>()); var navigationData = new NavigationData { RemainingStepsInCurrentSegment = new Stack <Position>(new[] { nextPosition, lastStepPosition }), Destination = nextPosition, LastStep = lastStepPosition, RemainingNodes = new [] { nextPosition }.ToList() }; Position nextStep; NavigationResult result = navigator.ResolveNextStep(navigationData, currentPosition, out nextStep); result.Should().Be(NavigationResult.InProgress); nextStep.Should().Be(lastStepPosition); var expectedSteps = new Stack <Position>(new[] { nextPosition }); navigationData.RemainingStepsInCurrentSegment. Should().BeEquivalentTo(expectedSteps, options => options.WithStrictOrderingFor(position => position)); }
private void ShowLiveTweetsUserListNavigationCompleted(NavigationResult result) { if (result.Result == true) { _eventAggregator.GetEvent <ModuleNavigationEvent>().Publish(DestinationModuleType.LiveTweets); } }
private void Callback(NavigationResult result) { if (result.Error != null) { //handle error } }
public void ResolveNextStep_ActorWasDisplacedToPositionNeighboringLastStepAndNextStep_ReturnsInProgressWithMovementToNextStepAndStackIsEmpty() { var currentPosition = new Position(1, 1); var lastStepPosition = new Position(1, 0); var nextPosition = new Position(2, 0); IPathfinder pathfinder = Mock.Of <IPathfinder>(); IGridInfoProvider gridInfoProvider = Mock.Of <IGridInfoProvider>(p => p.IsWalkable(It.IsAny <Position>()) == true); var bresenham = new BresenhamLineCreator(); var navigator = new Navigator(pathfinder, gridInfoProvider, new NaturalLineCalculator(bresenham), bresenham, Mock.Of <IUiFacade>()); var navigationData = new NavigationData { RemainingStepsInCurrentSegment = new Stack <Position>(new[] { nextPosition }), Destination = nextPosition, RemainingNodes = new[] { nextPosition }.ToList(), LastStep = lastStepPosition }; Position nextStep; NavigationResult result = navigator.ResolveNextStep(navigationData, currentPosition, out nextStep); result.Should().Be(NavigationResult.InProgress); nextStep.Should().Be(nextPosition); navigationData.RemainingStepsInCurrentSegment. Should().BeEmpty(); }
protected virtual void DefaultNavigationCallback(NavigationResult result) { if (result.Error != null) { MessageBoxService.Alert(this, result.Error.Message); } }
private void NavigationCompleted(NavigationResult result) { if (result.Result == true) { Events.GetEvent <ChatOnDisplayEvent>().Publish(null); } }
public void ResolveNextStep_NextStepIsNextNode_ReturnsInProgressWithNextStepAndNavigationDataIsCorrect() { var currentPosition = new Position(2, 2); var nextNode = new Position(3, 2); IPathfinder pathfinder = Mock.Of <IPathfinder>(); IGridInfoProvider gridInfoProvider = Mock.Of <IGridInfoProvider>(p => p.IsWalkable(It.IsAny <Position>()) == true); var navigator = new Navigator(pathfinder, gridInfoProvider, Mock.Of <INaturalLineCalculator>(), Mock.Of <IRasterLineCreator>(), Mock.Of <IUiFacade>()); var nodesToVisit = new[] { nextNode, new Position(213, 34254), }; var navigationData = new NavigationData { RemainingNodes = nodesToVisit.ToList(), RemainingStepsInCurrentSegment = new Stack <Position>(new[] { nextNode }), Destination = new Position(4, 2), LastStep = currentPosition }; Position nextStep; NavigationResult result = navigator.ResolveNextStep(navigationData, currentPosition, out nextStep); result.Should().Be(NavigationResult.InProgress); nextStep.Should().Be(nextNode); navigationData.RemainingStepsInCurrentSegment.Should().BeEmpty(); navigationData.RemainingNodes.Should().BeEquivalentTo(nodesToVisit.Skip(1)); }
private void NavigationComplete(NavigationResult result) { _ServerService.RemoveProxyResponseEventHandler(OnResponse); _ServerService.RemoveProxyRequestEventHandler(OnRequest); _ServerService.StopProxy(); _ServerService.RemoveProxy(); Dispose(); }
private void NavigationComplete(NavigationResult result) { if (result.Result == true) { Debug.WriteLine($"Navigation to {result.Context.Uri} completed"); NavigationParameter = string.Empty; } }
/// <summary> /// 遷移処理の結果に応じた処理を行います。 /// </summary> /// <param name="nr"></param> private void NavigateResult(NavigationResult nr) { if (nr.Error != null) { Logger.Error($"画面遷移中にエラーが発生しました。: [Uri] {nr.Context.Uri}", nr.Error); Navigate(nameof(Error)); } }
public override ActivityStep ResolveStep(GameEntity entity) { if (!_targetEntity.hasPosition) { return(Succeed(entity)); } if (Position.Distance(_targetEntity.position.Position, entity.position.Position) >= _giveUpDistance) { return(Fail(entity)); } Position targetCurrentPosition = _targetEntity.position.Position; bool targetIsOneStepAway = PositionUtilities.IsOneStep(entity.position.Position - targetCurrentPosition); if (targetIsOneStepAway) { return(new ActivityStep { State = ActivityState.InProgress, GameAction = _actionFactory.CreateAttackAction(entity, _targetEntity), }); } if (_rng.Check(0.03f)) { return(Fail(entity, _actionFactory.CreatePassAction(entity, 3f))); } bool targetPositionHasChanged = targetCurrentPosition != _lastTargetPosition; if (targetPositionHasChanged) { _lastTargetPosition = targetCurrentPosition; } if (targetPositionHasChanged || _navigationData == null) { // performance: should in fact be done every couple of turns _navigationData = _navigator.GetNavigationData(entity.position.Position, targetCurrentPosition); } Position nextStep; NavigationResult navigationResult = _navigator.ResolveNextStep(_navigationData, entity.position.Position, out nextStep); if (navigationResult == NavigationResult.Finished) { return(Succeed(entity)); } IGameAction moveGameAction = CreateMoveAction(nextStep, entity); return(new ActivityStep { State = ActivityState.InProgress, GameAction = moveGameAction }); }
/// <summary> /// User this as Default NavigationCallback. Override this for custom handle logic. /// </summary> /// <param name="result"></param> protected virtual void DefaultNavigationCallback(NavigationResult result) { if (result.Error == null) { return; } Logger.Exception(result.Error); MessageBoxService?.Alert(this, result.Error.Message); }
private void ProcessNavigationResult(NavigationResult navigationResult) { if (navigationResult.Result == false) { var navigationErrorViewModel = new NavigationErrorViewModel(navigationResult.Error, this); RegionManager.AddToRegion(RegionNames.MainTabRegion, navigationErrorViewModel); } }
public static String Parse(NavigationResult navigationResult) { if (navigationResult.Error == null) { return(navigationResult.Result.ToString()); } return(navigationResult.Error.Message); }
protected override async Task <INavigationResult> GoBackInternal(INavigationParameters parameters, bool?useModalNavigation, bool animated) { INavigationResult result = null; try { NavigationSource = PageNavigationSource.NavigationService; switch (PopupUtilities.TopPage(_popupNavigation, _applicationProvider)) { case PopupPage popupPage: var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters); ((INavigationParametersInternal)segmentParameters).Add("__NavigationMode", NavigationMode.Back); var previousPage = PopupUtilities.GetOnNavigatedToTarget(_popupNavigation, _applicationProvider); PageUtilities.OnNavigatingTo(previousPage, segmentParameters); await DoPop(popupPage.Navigation, false, animated); if (popupPage != null) { PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(popupPage, a => a.IsActive = false); PageUtilities.OnNavigatedFrom(popupPage, segmentParameters); PageUtilities.OnNavigatedTo(previousPage, segmentParameters); await InvokeOnNavigatedToAsync(previousPage, segmentParameters); PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(previousPage, a => a.IsActive = true); PageUtilities.DestroyPage(popupPage); result = new NavigationResult { Success = true }; break; } throw new NullReferenceException("The PopupPage was null following the Pop"); default: result = await base.GoBackInternal(parameters, useModalNavigation, animated); break; } } catch (Exception e) { #if DEBUG System.Diagnostics.Debugger.Break(); #endif _logger.Log(e.ToString(), Category.Exception, Priority.High); result = new NavigationResult { Success = false, Exception = e };; } finally { NavigationSource = PageNavigationSource.Device; } return(result); }
private void NavigateComplete(NavigationResult result) { var viewName = result.Context.Uri; var message = $"Navigation to {viewName} complete"; var caption = "Information"; var button = MessageBoxButton.OK; var messageType = MessageBoxImage.Information; MessageBox.Show(message, caption, button, messageType); }
private void NavigationCallBack(NavigationResult navigationResult) { if (navigationResult.Error != null) { if (!(navigationResult.Error is SecurityNavigationAccessDeniedException)) { throw navigationResult.Error; } } }
/// <summary> /// Se ejecuta cuando se ha completado la navegación. /// </summary> /// <param name="result"> /// Indica información sobre el resultado de la navegación. /// </param> protected virtual void NavigationCompleted(NavigationResult result) { if (result.Result.HasValue && result.Result.Value) { // Propagamos el nombre del módulo activo para desactivar // los TaskButtons del resto de módulos cargados en la región TaskbarRegion. var navigationCompletedEvent = this.EventAggregator.GetEvent <NavigationCompletedEvent>(); navigationCompletedEvent.Publish(this.ModuleType.Name); } }
public static string BuildNavigationLink(NavigationResult navigation, DimensionValue refinement) { string link = null; List<String> navStates = new List<string>(); foreach (var item in navigation.AppliedFiltersResult.DimensionValues) { if (!(item.Dimension.Id == refinement.Dimension.Id && refinement.Dimension.MultiSelect == MultiSelect.None && refinement.Parent != null)) { link = link + "/" + item.Dimension.DisplayName + "/" + item.DisplayName; navStates.Add(Base36Encode(long.Parse(item.Id))); } } navStates.Add(Base36Encode(long.Parse(refinement.Id))); link = link + "/" + refinement.Dimension.DisplayName + "/" + refinement.DisplayName + "/" + String.Join("Z", navStates); return link.Replace(' ', '-'); }
public static string BuildBreadCrumbLink(NavigationResult navigation, DimensionValue refinement) { string link = null; List<String> navStates = new List<string>(); foreach (var item in navigation.AppliedFiltersResult.DimensionValues) { if (item.Id == refinement.Id) { link = link + "/" + item.Dimension.DisplayName + "/" + item.DisplayName; navStates.Add(Base36Encode(long.Parse(item.Id))); break; } else { link = link + "/" + item.Dimension.DisplayName + "/" + item.DisplayName; navStates.Add(Base36Encode(long.Parse(item.Id))); } } link = link + "/" + String.Join("Z", navStates); return link.Replace(' ', '-'); }