Esempio n. 1
0
        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
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
            }
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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>();
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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();
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
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));
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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;
                    }
                }
            }
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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]");
        }
Esempio n. 19
0
 public StubUI(Positional <MonkeyBoard> logic, BoardUI <MonkeyBoard> boardUI)
     : base(logic, new Image() { Source = ImageManager.ElementImageDictionary["Stub"] }, boardUI)
 {
 }
Esempio n. 20
0
 /// <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, "]");
 }
Esempio n. 21
0
 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
 }
Esempio n. 22
0
 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);
 }
Esempio n. 23
0
 protected override bool IsValid()
 {
     return(!Positional.IsAtPosition(Config.Owner.transform, _config.Target, _config.Tolerance));
 }