private void Awake() { if (!_registeredToLevelLoadedEvent) { _registeredToLevelLoadedEvent = true; App.OnLevelLoaded += OnLevelLoaded; } Position = transform.position; Platform = Positional.GetPlatform(Position); Debug.Assert(Platform != null); Neighbours.RemoveAll(x => x == null); //Don't add orphans to the graph if (Neighbours.Count > 0) { Debug.Assert(!AllNodes.Contains(this)); AllNodes.Add(this); } #if UNITY_EDITOR && DRAW_DEBUG _debugDrawer = FindObjectOfType <LineDrawer>(); if (_debugDrawer == null) { LineDrawer.OnDrawerAwake += OnDrawerAwake; } GenerateDebugGraph(); #endif //UNITY_EDITOR && DRAW_DEBUG }
public override void OnEnable() { base.OnEnable(); _currentPlatform = Positional.GetPlatform(Config.Owner.transform, 50.0f); Debug.Assert(_currentPlatform != null); _currentTarget = Rand.GetRandomPointOnPlatform(_currentPlatform); _waitTimeRemaining = Rand.Next(_idleConfig.MaxWaitDuration); }
public override void OnEnable() { base.OnEnable(); if (!Positional.IsAtPosition(Config.Owner.transform, _stealConfig.ToStealFrom.transform.position, 3.0f)) { Config.Owner.PushState(new MoveToState.MoveToConfig(_stealConfig.ToStealFrom.transform.position, Config.Owner, 3.0f)); } }
/// <summary> /// Configure a positional argument with a single value. /// </summary> /// <typeparam name="TArg">Argument type.</typeparam> /// <param name="getExpr"> /// Getter expression describing where the value is stored. /// </param> /// <returns></returns> public Positional <TConf, TArg> HasPositionalArgument <TArg>( Expression <Func <TConf, TArg> > getExpr) { var positional = new Positional <TConf, TArg>(this, GetDefinitionFromExpression(getExpr)); FluentConfig.Add(positional); return(positional); }
public override void OnEnable() { base.OnEnable(); if (!Positional.IsAtPosition(Config.Owner.transform, ToMine.transform.position)) { Config.Owner.PushState(new PathToState.PathToConfig(Config.Owner, ToMine.transform.position)); return; } }
protected override bool IsValid() { if (_path == null || !_config.IsPathStillValid()) { return(false); } return(Time.time - _stateEnterTime < _maxStateDuration && !Positional.IsAtPosition(Config.Owner.transform, _config.Target, 2.0f)); }
public void Throw_If_Given_An_Incompatible_Instance() { // arrange var positional = new Positional <string>(new Parser("a"), (o, strings) => { }); var info = new IterationInfo("a b c".Split(' ')); Action mightThrow = () => positional.Consume(new object(), new ConsumptionRequest(info)); // act // assert mightThrow.Should().Throw <ArgumentException>(); }
public void Provide_A_Generic_Version() { // arrange var positional = new Positional <string>(new Parser("a"), (o, strings) => { }); var info = new IterationInfo("a b c".Split(' ')); // act var res = positional.CanConsume("", info); // assert res.NumConsumed.Should().Be(3); }
public void Create_A_Message_For_Switch_And_Positional_Differently() { // arrange var param = new BooleanSwitch(new Parser("a"), 'h', "help", o => { }); var pos = new Positional(new Parser("a"), (o, strings) => { }); var ex0 = new MissingRequiredParameterException(param, new object()); var ex1 = new MissingRequiredParameterException(pos, new object()); // act // assert ex0.Message.Should().NotBe(ex1.Message); }
public override bool Update() { if (!base.Update()) { return(false); } if (Positional.IsAtPosition(Config.Owner.transform, _stealConfig.ToStealFrom.transform.position, 3.0f)) { Config.Owner.CharacterYoke.Interact = true; } return(true); }
public override bool Update() { if (!base.Update()) { return(false); } Config.Owner.CharacterYoke.Movement = _moveLeft ? Vector2.left : Vector2.right; Config.Owner.CharacterYoke.Jump = _jump && (_moveLeft ? Config.Owner.transform.position.x - _config.JumpThreshold <= _launchPoint.x : Config.Owner.transform.position.x + _config.JumpThreshold >= _launchPoint.x) && Positional.GetPlatform(Config.Owner.transform) != _config.Target; return(true); }
protected internal PositionalUI(Positional <TBoard> positional, Image imageToDisplay, BoardUI <TBoard> boardUI = null) { // set the resizing mode to high quality so that the UI looks nicer SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality); // set stretch mode to fill Stretch = System.Windows.Media.Stretch.Fill; Logic = positional; ImageToDisplay = imageToDisplay; BoardUI = boardUI; // set this.Source to bind to ImageToDisplay.Source InitializeBindings(); }
public void Indicate_It_Cannot_Consume_If_It_Has_Already_Consumed() { // arrange var positional = new Positional(new Parser("a"), (o, strings) => { }) { HasBeenConsumed = true }; var info = new IterationInfo("a b c".Split(' ')); // act var res = positional.CanConsume("", info); // assert res.NumConsumed.Should().Be(0); }
private void PushMoveState(Vector3 target, Transform targetPlatform = null) { if (targetPlatform == null) { targetPlatform = Positional.GetPlatform(target); } if (targetPlatform == Positional.GetPlatform(Config.Owner.transform)) { Config.Owner.PushState(new MoveToState.MoveToConfig(target, Config.Owner)); } else { Config.Owner.PushState(new TraverseState.TraverseStateConfig(Config.Owner, targetPlatform)); } }
public void Consume_The_Min_Of_The_Number_It_Wants_Vs_The_Number_It_Can_Have() { // arrange var positional = new Positional <string>(new Parser("a"), (o, strings) => { }) { MaxAllowed = 3 }; var info = new IterationInfo("a b c d e f".Split(' ')); // act var res0 = positional.Consume("", new ConsumptionRequest(info, int.MaxValue)); var res1 = positional.Consume("", new ConsumptionRequest(info, 2)); // assert res0.NumConsumed.Should().Be(3); res1.NumConsumed.Should().Be(2); }
public TraverseState(TraverseStateConfig config) : base(config) { _config = config; _currentPlatform = Positional.GetPlatform(Config.Owner.transform, 50.0f); if (_currentPlatform != null) { BoxCollider2D currentPlatformCollider = _currentPlatform.GetComponent <BoxCollider2D>(); Bounds currentPlatformBounds = currentPlatformCollider.bounds; //Jump if the target is higher, or there's a gap between the platforms _jump = currentPlatformBounds.max.y <= _config.TargetBounds.max.y || currentPlatformBounds.max.x + 1.0f <= _config.TargetBounds.min.x || currentPlatformBounds.min.x - 1.0f >= _config.TargetBounds.max.x; //If the target is on the left if (_config.TargetBounds.max.x <= currentPlatformBounds.center.x) { _moveLeft = true; //If the targets rhs overlaps if (_config.TargetBounds.max.x >= currentPlatformBounds.min.x && _config.TargetBounds.max.y > currentPlatformBounds.max.y) { _launchPoint = _config.TargetBounds.max; } else { _launchPoint = currentPlatformBounds.min; } } else if (_config.TargetBounds.min.x >= currentPlatformBounds.center.x) { _moveLeft = false; //if the targets lhs overlaps if (_config.TargetBounds.min.x <= currentPlatformBounds.max.x && _config.TargetBounds.max.y > currentPlatformBounds.max.y) { _launchPoint = _config.TargetBounds.min; } else { _launchPoint = currentPlatformBounds.max; } } } }
public override bool Update() { if (!base.Update()) { return(false); } Transform platform = Positional.GetPlatform(_config.Target, 5.0f); if (platform != Positional.GetPlatform(Config.Owner.transform)) { PushMoveState(_config.Target, platform); return(true); } //This is for when the last node in the path isn't actually the target //but we still want to move towards it MoveToState.MoveTowards(Config.Owner, _config.Target); return(true); }
public void Generate_The_Correct_Prefix_For_Positionals() { // arrange var mock = new Mock <IInlineSequence>(); mock.SetupAllProperties(); var builder = DefaultBuilder.CreateDefaultBuilder(); var parameter = new Positional(builder.Context.ParserRepository.Get("util"), (o, strings) => { }, 1, 1); parameter.Help.ValueAlias = "val"; var vm = new ParameterViewModel(parameter, Theme.Default); var usage = new ParameterUsage { ViewModel = vm }; // act usage.GenerateSequence(mock.Object); // assert usage.StringBuilder.ToString().Should().Be("[val]"); }
public StubUI(Positional <MonkeyBoard> logic, BoardUI <MonkeyBoard> boardUI) : base(logic, new Image() { Source = ImageManager.ElementImageDictionary["Stub"] }, boardUI) { }
/// <summary> /// Generates the positional sequence. /// </summary> /// <param name="positional">The positional.</param> /// <param name="seq">The seq.</param> public virtual void GeneratePositionalSequence(Positional positional, IInlineSequence seq) { WritePrimary(seq, "["); WriteSecondary(seq, GenerateValueAlias(positional)); WritePrimary(seq, "]"); }
protected override bool IsValid() { return(_currentPlatform != null && Positional.GetPlatform(Config.Owner.transform) != _config.Target); //Distance being small means that we're also implicitly checking that we're grounded }
internal protected virtual void AddFromLogic(Positional <TBoard> positional) { // no need to call add // the convert method automatically adds the UI to the boardUI LogicUICreatorManager.Convert(positional); }
protected override bool IsValid() { return(!Positional.IsAtPosition(Config.Owner.transform, _config.Target, _config.Tolerance)); }