public void CanConvertTo()
        {
            PointConverter r = new PointConverter();

            Assert.IsTrue(r.CanConvertTo(typeof(string)));
            Assert.IsFalse(r.CanConvertTo(typeof(Point)));
        }
예제 #2
0
        public IEnumerator JumpCoroutine(Unit unit, Point pointDestination)
        {
            Logcat.I($"Jump Coroutine, initial position {unit.GetPosition()}, final position {pointDestination}");
            Vector3 destination = PointConverter.ToVector(pointDestination);

            destination.y = unit.Height;

            float JumpProgress = 0;
            var   startPos     = unit.transform.position;

            while (JumpProgress <= 1.0)
            {
                JumpProgress += Time.deltaTime / jumpingTime;
                var height = Mathf.Sin(Mathf.PI * JumpProgress) * jumpingHeight;
                if (height < 0f)
                {
                    height = 0f;
                }
                unit.transform.position = Vector3.Lerp(startPos, destination, JumpProgress) + Vector3.up * height;
                yield return(null);
            }

            unit.transform.position = destination;
            PlacementHelper.Move(unit, pointDestination, new MovementActionValidator());
        }
예제 #3
0
        public static Object ParseValue(String value, Type type)
        {
            PointConverter pC = new PointConverter();

            try
            {
                if (type == typeof(Point))
                {
                    //{X=100,Y=580}
                    value = value.Replace("{X=", "").Replace("}", "").Replace("Y=", "");
                    return(new Point(int.Parse(value.Split(',')[0]), int.Parse(value.Split(',')[1])));
                }
                if (type == typeof(int))
                {
                    return(int.Parse(value));
                }
                if (type == typeof(bool))
                {
                    return(bool.Parse(value));
                }
                if (type == typeof(float))
                {
                    return(float.Parse(value));
                }
                if (type == typeof(double))
                {
                    return(double.Parse(value));
                }
            }
            catch
            {
                return(null);
            }
            return(value);
        }
예제 #4
0
 [TestCase(-5, -12, 13, -1.96f, TestName = "RandomCoordinates2")] //theta is -Acos(-5/13)
 public void TransformCartesianToPolar_ReturnsCorrectValues(float x, float y, float expectedR,
                                                            float expectedTheta)
 {
     var(r, theta) = PointConverter.TransformCartesianToPolar(x, y);
     r.Should().BeApproximately(expectedR, (float)Epsilon);
     theta.Should().BeApproximately(expectedTheta, (float)Epsilon);
 }
예제 #5
0
 public void TransformPolarToCartesian_ReturnsCorrectValues(float r, float theta, float expectedX,
                                                            float expectedY)
 {
     var(x, y) = PointConverter.TransformPolarToCartesian(r, theta);
     x.Should().BeApproximately(expectedX, (float)Epsilon);
     y.Should().BeApproximately(expectedY, (float)Epsilon);
 }
예제 #6
0
        internal static Point ReadAttributePoint(XmlNode node, string attributeName)
        {
            CheckAttributeExists(node, attributeName);
            string text = node.Attributes[attributeName].Value;

            return(PointConverter.ConvertFromString(null, System.Globalization.CultureInfo.CurrentCulture, text));
        }
예제 #7
0
        public static IEnumerator FallingMovement(Unit unit, Vector3 initialPosition, Vector3 finalPosition, float time)
        {
            if (unit == null)
            {
                yield return(null);
            }

            float elapsedTime = 0;

            unit.transform.position = initialPosition;

            while (elapsedTime < time)
            {
                float yPosition = Mathf.Lerp(unit.transform.position.y, finalPosition.y, elapsedTime / time);
                if (yPosition < unit.Height)
                {
                    yPosition = unit.Height;
                }

                unit.transform.position = new Vector3(unit.transform.position.x, yPosition, unit.transform.position.z);
                elapsedTime            += Time.deltaTime;
                yield return(new WaitForEndOfFrame());
            }

            PlacementHelper.Move(unit, PointConverter.ToPoint(finalPosition), new MovementActionValidator());
            yield return(null);
        }
        private GameObject Instanciate(Point position)
        {
            Vector3    vector   = PointConverter.ToVector(position);
            GameObject instance = MonoBehaviour.Instantiate(this.decal, vector, this.decal.transform.rotation);

            this.decalInstances?.Add(instance);
            return(instance);
        }
예제 #9
0
        public override void Execute()
        {
            CardinalDirections direction = Direction.GetCardinalDirection(this.Unit.GetPosition(), this.Target);
            Vector3            point     = PointConverter.ToVector(Direction.GetDirection(direction));

            Destroy(Instantiate(lasserVFX, this.transform.position, RotationHelper.GetRotation(direction)), delay);
            StartCoroutine(Attack(direction, point));
        }
예제 #10
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueObject)
        {
            if (!(valueObject is string value))
            {
                throw new InvalidOperationException($"Cannot convert from type {valueObject.GetType()}");
            }

            return(new Wrapper.Point(PointConverter.ConvertFromString(value)));
        }
예제 #11
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// pointconverter.ConvertTo<int>(context, culture, value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this PointConverter pointconverter, System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value)
        {
            if (pointconverter == null)
            {
                throw new ArgumentNullException("pointconverter");
            }

            return((T)pointconverter.ConvertTo(context, culture, value, typeof(T)));
        }
예제 #12
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// typeconverter.ConvertTo<int>(value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this PointConverter typeconverter, Object value)
        {
            if (typeconverter == null)
            {
                throw new ArgumentNullException("typeconverter");
            }

            return((T)typeconverter.ConvertTo(value, typeof(T)));
        }
예제 #13
0
        private void SpawnSplit(CardinalDirections direction, Vector3 otherPosition)
        {
            Vector3 position = otherPosition + PointConverter.ToVector(Direction.GetDirection(direction));

            Quaternion     rotation = RotationHelper.GetRotation(direction);
            HoloBlastSplit bullet   = Instantiate(this.blast, position, rotation);

            Logcat.I($"Other position {otherPosition} Splitted bullet {position} rotation {rotation}");
            bullet.SetUp(boardController, unitsMap, this.secondAttackDamage, secondKnockback, new Point((int)otherPosition.x, 0, (int)otherPosition.z));
        }
예제 #14
0
        public void SetUp()
        {
            pt    = new Point(1, 2);
            ptStr = pt.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + pt.Y;

            ptneg    = new Point(-2, -3);
            ptnegStr = ptneg.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + ptneg.Y;

            ptconv = (PointConverter)TypeDescriptor.GetConverter(pt);
        }
예제 #15
0
        public RadialGradientConverter(Boolean repeating)
            : base(repeating)
        {
            var position = PointConverter.StartsWithKeyword(Keywords.At).Option(Point.Center);
            var circle   = WithOrder(WithAny(Assign(Keywords.Circle, true).Option(true), LengthConverter.Option()), position);
            var ellipse  = WithOrder(WithAny(Assign(Keywords.Ellipse, false).Option(false), LengthOrPercentConverter.Many(2, 2).Option()), position);
            var extents  = WithOrder(WithAny(Toggle(Keywords.Circle, Keywords.Ellipse).Option(false), Map.RadialGradientSizeModes.ToConverter()), position);

            _converter = circle.Or(ellipse.Or(extents));
        }
예제 #16
0
        public override void Execute()
        {
            CardinalDirections direction = Direction.GetCardinalDirection(this.Unit.GetPosition(), this.Target);
            Vector3            point     = PointConverter.ToVector(Direction.GetDirection(direction));

            this.transform.localPosition += point;
            HoloBlast blast = MonoBehaviour.Instantiate(this.bullet, this.gameObject.transform.position, RotationHelper.GetRotation(direction));

            blast.SetUp(this.UnitsMap, this.BoardController, this.Unit.GetPosition(), PlayerUtils.HoloBlastSplitDirections(direction), this.firstAttackDamage, this.secondAttackDamage, this.Knockback);
            this.transform.localPosition -= point;
        }
예제 #17
0
        private void SpawnAttackParticles(Unit unit)
        {
            if (!this.ValidPositions.Contains(unit.GetPosition()))
            {
                return;
            }

            this.Target = unit.GetPosition();
            this.FaceTargetDirection(this.Target);
            this.SkillActionFX?.Play(PointConverter.ToVector(this.Target));
        }
예제 #18
0
        public IEnumerator LerpMovementPath(MonoBehaviour caller, Unit unit, List <Point> path)
        {
            Logcat.I($"Lerp Movement Path moving unit {unit.GetPosition()}");
            path.ForEach(p => Logcat.I($"Lerp Path {p}"));

            for (int i = 1; i < path.Count; i++)
            {
                yield return(LerpMovement(unit, unit.gameObject.transform.position, PointConverter.ToVector(path[i])));
            }
            yield return(null);
        }
예제 #19
0
        private void set_position(int x, int y)
        {
            PointConverter pc = new PointConverter();
            Point          pt = new Point();


            pt.X = x;
            pt.Y = y;

            Cursor.Position = pt;
        }
예제 #20
0
        static GridUnitExtension()
        {
            _dipMultiplier = DipHelper.GetDipMultiplier();

            _thicknessConverter    = new ThicknessConverter();
            _cornerRadiusConverter = new CornerRadiusConverter();
            _sizeConverter         = new SizeConverter();
            _pointConverter        = new PointConverter();
            _rectConverter         = new RectConverter();
            _gridLengthConverter   = new GridLengthConverter();
        }
예제 #21
0
 /// <summary>${WP_REST_RectConverter_method_WriteJson_D}</summary>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     Rect rect = (Rect)value;
     PointConverter ponitConverter = new PointConverter();
     writer.WriteStartObject();
     writer.WritePropertyName("rightBottom");
     writer.WriteRawValue(JsonConvert.SerializeObject(new Point(rect.Right,rect.Bottom), ponitConverter));
     writer.WritePropertyName("leftTop");
     writer.WriteRawValue(JsonConvert.SerializeObject(new Point(rect.Left, rect.Top), ponitConverter));
     writer.WriteEndObject();
 }
        public void ConvertTo()
        {
            PointConverter r = new PointConverter();

            Point rect = new Point(1, 2);

            object o = r.ConvertTo(rect, typeof(string));

            Assert.AreEqual(typeof(string), o.GetType());
            Assert.AreEqual("1,2", (string)o);
        }
예제 #23
0
        // <SnippetPointConverterExample_csharp>
        private Point pointConverterExample()
        {
            PointConverter pConverter  = new PointConverter();
            Point          pointResult = new Point();
            string         string1     = "10,20";

            // pointResult is equal to (10, 20)
            pointResult = (Point)pConverter.ConvertFromString(string1);

            return(pointResult);
        }
예제 #24
0
        public void ConvertTo()
        {
            PointConverter r = new PointConverter();

            Point rect = new Point(1, 2);

            object o = r.ConvertTo(null, CultureInfo.InvariantCulture, rect, typeof(string));

            Assert.AreEqual(typeof(string), o.GetType());
            Assert.AreEqual("1,2", (string)o);
        }
예제 #25
0
        public override void Execute()
        {
            CardinalDirections direction = Direction.GetCardinalDirection(this.Unit.GetPosition(), this.Target);
            Vector3            point     = PointConverter.ToVector(Direction.GetDirection(direction));

            //// Logcat.I(this, $"Shooting with direction {direction} vector {point}");
            this.transform.localPosition += point;
            GausCannon gausCannon = MonoBehaviour.Instantiate(this.bullet, this.transform.position, RotationHelper.GetRotation(direction));

            gausCannon.SetUp(this.UnitsMap, this.BoardController, this.Unit.GetPosition(), this.Knockback, this.damage);
            this.transform.localPosition -= point;
        }
예제 #26
0
        private void FlipUnit(Unit unit, Vector3 initialPosition, Vector3 finalPosition)
        {
            Point initial = PointConverter.ToPoint(initialPosition);
            Point final   = PointConverter.ToPoint(finalPosition);

            initial.y = 0;
            final.y   = 0;
            CardinalDirections direction = Direction.GetCardinalDirection(initial, final);

            //// Logcat.I($"Lerp - Flipping Unit. Unit type {unit.GetUnitType()} to {direction}. Initial position {initial}, final position {final}");
            unit.FlipUnit(direction);
        }
예제 #27
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(LEFTCLICK))
        {
            Vector3 vp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            (int x, int y)point = PointConverter.VectorConverter(vp);
            Debug.Log(point.x);
            Debug.Log(point.y);
        }
        // var currentBoxCoordinates = GetCurrentPoint();
        // bool success = false;
        // var boxSpriteRenderer = this.gameObject.GetComponent<SpriteRenderer>();
        // if (Input.GetMouseButtonDown(LEFTCLICK))
        // {
        //   Vector3 vp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //   var point = PointConverter.VectorConverter(vp);
        //   BoxCollider2D col = this.gameObject.GetComponent<BoxCollider2D>();
        //   if (col.OverlapPoint(vp))
        //   {

        //     if (GameState.BoxAvailableForAttack(currentBoxCoordinates))
        //     {
        //       success = GameState.AttackTile(point, spriteArray[GameState.currentPlayer]);
        //     }
        //     else if (boxSpriteRenderer.sprite == spriteArray[GameState.currentPlayer])
        //     {
        //       Debug.Log("asdads" + (boxSpriteRenderer.sprite == spriteArray[GameState.currentPlayer]).ToString());
        //       success = GameState.FortifyTile(point);
        //     }
        //   }
        // }
        // else if (Input.GetMouseButtonDown(RIGHTCLICK))
        // {
        //   Vector3 vp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //   var point = PointConverter.VectorConverter(vp);
        //   BoxCollider2D col = this.gameObject.GetComponent<BoxCollider2D>();
        //   if (col.OverlapPoint(vp))
        //   {
        //     if (boxSpriteRenderer.sprite == AvailableMoveBox)
        //     {
        //       success = GameState.BlockTile(point);
        //       if (success)
        //         boxSpriteRenderer.sprite = BlockedBox;
        //     }
        //   }
        // }
        // if (success)
        // {
        //   GameState.switchTurn(EmptyTileBox);
        // }
        // UpdateBoxState(currentBoxCoordinates, boxSpriteRenderer);
    }
예제 #28
0
        /// <summary>${WP_REST_RectConverter_method_ReadJson_D}</summary>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return new Rect();
            }
            PointConverter ponitConverter = new PointConverter();
            JObject obj = JObject.Load(reader);
            Point rightBottom = JsonConvert.DeserializeObject<Point>(obj["rightBottom"].ToString());
            Point leftTop = JsonConvert.DeserializeObject<Point>(obj["leftTop"].ToString());

            return new Rect(rightBottom, leftTop);
        }
        public void ConvertFrom()
        {
            PointConverter r = new PointConverter();

            object or = r.ConvertFrom("3, 4");

            Assert.AreEqual(typeof(Point), or.GetType());
            Assert.AreEqual(new Point(3, 4), or);

            or = r.ConvertFrom("-1, -4");
            Assert.AreEqual(typeof(Point), or.GetType());
            Assert.AreEqual(new Point(-1, -4), or);
        }
예제 #30
0
        public void WriteXml(XmlWriter writer)
        {
            var pointConverter = new PointConverter();
            var sizeConverter  = new SizeConverter();

            writer.WriteStartElement("WindowSettings");
            writer.WriteElementString("WindowState", WindowState.ToString());
            writer.WriteElementString("Location", pointConverter.ConvertToString(Location));
            writer.WriteElementString("Size", sizeConverter.ConvertToString(Size));
            writer.WriteElementString("Zoom", Zoom.ToString());
            writer.WriteElementString("PositionInText", PositionInText.ToString());
            writer.WriteEndElement();
        }
예제 #31
0
        public void ReadXml(XmlReader reader)
        {
            var pointConverter = new PointConverter();
            var sizeConverter  = new SizeConverter();

            reader.Read(); // To skip the starting 'WindowSettings' element
            WindowState    = (FormWindowState)Enum.Parse(typeof(FormWindowState), reader.ReadElementContentAsString());
            Location       = (Point)pointConverter.ConvertFromString(reader.ReadElementContentAsString());
            Size           = (Size)sizeConverter.ConvertFromString(reader.ReadElementContentAsString());
            Zoom           = reader.ReadElementContentAsInt();
            PositionInText = reader.ReadElementContentAsInt();
            reader.Read(); // To skip the ending 'WindowSettings' element
        }
예제 #32
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm mainForm = new MainForm();
            object   location = null;

            if (args.Length > 0)
            {
                if (args[0].StartsWith("prev_instance:"))
                {
                    // User clicked "New". Get location of previous
                    // instance and open new form slightly lower
                    // and to the right of previous form, unless
                    // previous form's Window State is maximized.
                    Point prevLoc = new Point();
                    try
                    {
                        PointConverter pc = new PointConverter();
                        prevLoc = (Point)(pc.ConvertFromString(args[0].Substring(14)));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    //
                    if (prevLoc.X > 0)
                    {
                        // Open new form slightly lower and
                        // to the right of previous form.
                        location = new Point(prevLoc.X + 35, prevLoc.Y + 35);
                        mainForm.StartPosition = FormStartPosition.Manual;
                        // mainForm.GetSettings(new Point(prevLoc.X + 35, prevLoc.Y + 35));
                    }
                }
                else
                {
                    mainForm.GetSettings(null);
                    // Windows Explorer selected this application
                    // to open a file. The first argument should
                    // be the path of the file to open.
                    mainForm.OpenFile(args[0]);
                }
            }
            mainForm.GetSettings(location);
            Application.Run(mainForm);
        }