Exemple #1
0
        /**/

        static bool AnyOffCurveSelected(Data.Segment segment)
        {
            return(Enumerable.Any(segment.OffCurves, point => point.IsSelected));
        }

        static void BreakPathsSelection(Data.Layer layer)
        {
            var outPaths = new List <Data.Path>();

            foreach (var path in Selection.FilterSelection(layer.Paths, invert: true))
            {
                var segmentsList = new List <Data.Segment>(path.Segments);
                IEnumerable <Data.Segment> iter;
                if (!(path.IsOpen ||
                      AnyOffCurveSelected(segmentsList.First())
                      ))
                {
                    int index;
                    for (index = segmentsList.Count - 1; index >= 0; --index)
                    {
                        if (AnyOffCurveSelected(segmentsList[index]))
                        {
                            break;
                        }
                    }
                    if (index <= 0)
                    {
                        // None selected, bring on the original path
                        outPaths.Add(path);
                        continue;
                    }
                    else
                    {
                        iter = Sequence.IterAt(segmentsList, index);
                    }
                }
                else
                {
                    iter = segmentsList;
                }

                Data.Path outPath = null;
                foreach (var segment in iter)
                {
                    if (AnyOffCurveSelected(segment) || segment.OnCurve.Type == PointType.Move)
                    {
                        if (outPath != null)
                        {
                            outPaths.Add(outPath);
                        }
                        outPath = new Data.Path();

                        var point = segment.OnCurve.Clone();
                        point.IsSmooth = false;
                        point.Type     = PointType.Move;
                        outPath.Points.Add(point);
                    }
                    else
                    {
                        outPath.Points.AddRange(segment.Points
                                                .Select(p => p.Clone())
                                                .ToList());
                    }
                }
                outPaths.Add(outPath);
            }

            layer.Paths.Clear();
            layer.Paths.AddRange(outPaths);
        }

        static void DeletePathsSelection(Data.Layer layer)
        {
            if (!TryMergeCurves(layer))
            {
                var outPaths = new List <Data.Path>();
                foreach (var path in layer.Paths)
                {
                    var segments = path.Segments.ToList();

                    var forwardMove = false;
                    for (int ix = segments.Count - 1; ix >= 0; --ix)
                    {
                        var segment = segments[ix];
                        var onCurve = segment.OnCurve;
                        if (onCurve.IsSelected)
                        {
                            forwardMove = ix == 0 && onCurve.Type == PointType.Move;

                            segment.Remove(nodeBias: true);
                        }
                        else if (AnyOffCurveSelected(segment))
                        {
                            segment.ConvertTo(PointType.Line);
                        }
                    }

                    if (path.Points.Count > 0)
                    {
                        if (forwardMove)
                        {
                            segments[0].ConvertTo(PointType.Move);
                        }
                        outPaths.Add(path);
                    }
                }

                layer.Paths.Clear();
                layer.Paths.AddRange(outPaths);
            }
        }

        static Vector2 SamplePoints(List <Vector2> samples, IList <Vector2> points, bool atStart)
        {
            var n     = 20; // TODO: adaptive sample count
            var start = atStart ? 0 : 1;

            if (points.Count == 4)
            {
                for (int i = start; i < n; ++i)
                {
                    samples.Add(BezierMath.Q(points, (float)i / (n - 1)));
                }
            }
            else
            {
                Debug.Assert(points.Count == 2);

                if (atStart)
                {
                    samples.Add(points[0]);
                }
                samples.Add(points[1]);
            }

            return(Vector2.Normalize(atStart ? points[1] - points[0] : points[points.Count - 2] - points[points.Count - 1]));
        }

        static bool TryMergeCurves(Data.Layer layer)
        {
            var selection = layer.Selection;

            if (selection.Count == 1 &&
                layer.Selection.First() is Data.Point point)
            {
                var          path          = point.Parent;
                var          segments      = path.Segments.ToList();
                Data.Segment firstSegment  = default;
                Data.Segment secondSegment = default;

                var segment = segments.Last();
                foreach (var next in segments)
                {
                    var onCurve = segment.OnCurve;
                    if (onCurve.IsSelected)
                    {
                        if (!(path.IsOpen && path.Points.Last() == onCurve) &&
                            onCurve.Type == PointType.Curve || next.OnCurve.Type == PointType.Curve)
                        {
                            firstSegment  = segment;
                            secondSegment = next;
                        }
                    }

                    segment = next;
                }

                if (!Equals(firstSegment, secondSegment))
                {
                    var samples = new List <Vector2>();

                    var leftTangent = SamplePoints(samples, firstSegment.PointsInclusive
                                                   .Select(p => p.ToVector2())
                                                   .ToArray(), true);
                    var rightTangent = SamplePoints(samples, secondSegment.PointsInclusive
                                                    .Select(p => p.ToVector2())
                                                    .ToArray(), false);
                    var fitPoints = BezierMath.FitCubic(samples, leftTangent, rightTangent, .01f);

                    layer.ClearSelection();
                    var curveSegment = firstSegment;
                    var otherSegment = secondSegment;
                    if (curveSegment.OnCurve.Type != PointType.Curve)
                    {
                        (curveSegment, otherSegment) = (otherSegment, curveSegment);
                    }
                    var offCurves = curveSegment.OffCurves;
                    offCurves[0].X = RoundToGrid(fitPoints[1].X);
                    offCurves[0].Y = RoundToGrid(fitPoints[1].Y);
                    offCurves[1].X = RoundToGrid(fitPoints[2].X);
                    offCurves[1].Y = RoundToGrid(fitPoints[2].Y);
                    var onCurve = firstSegment.OnCurve;
                    onCurve.X = secondSegment.OnCurve.X;
                    onCurve.Y = secondSegment.OnCurve.Y;
                    curveSegment.OnCurve.IsSmooth = otherSegment.OnCurve.IsSmooth;
                    otherSegment.Remove();
                    return(true);
                }
            }
            return(false);
        }

        /**/

        static void ConstrainSmoothPoint(Data.Point p1, Data.Point p2, Data.Point p3, bool handleMovement)
        {
            if (p2.IsSelected)
            {
                if (p1.Type == PointType.None)
                {
                    (p1, p3) = (p3, p1);
                }
                if (p1.Type != PointType.None)
                {
                    VectorRotation(p3, p1.ToVector2(), p2.ToVector2());
                }
            }
            else if (p1.IsSelected != p3.IsSelected)
            {
                if (p1.IsSelected)
                {
                    (p1, p3) = (p3, p1);
                }
                if (p1.Type != PointType.None)
                {
                    VectorProjection(p3, p1.ToVector2(), p2.ToVector2());
                }
                else if (handleMovement)
                {
                    VectorRotation(p1, p3.ToVector2(), p2.ToVector2());
                }
            }
        }
Exemple #2
0
        static void InterpolateCurve(Data.Point on1, Data.Point off1, Data.Point off2, Data.Point on2, float dx, float dy)
        {
            if (on2.IsSelected != on1.IsSelected)
            {
                var sign   = on1.IsSelected ? -1 : 1;
                var sdelta = new Vector2(sign * dx, sign * dy);

                var ondelta = on2.ToVector2() - on1.ToVector2();
                var factor  = ondelta - sdelta;
                if (factor.X != 0 && factor.Y != 0)
                {
                    factor = ondelta / factor;
                }

                if (!off1.IsSelected)
                {
                    off1.X = RoundToGrid(on1.X + factor.X * (off1.X - on1.X));
                    off1.Y = RoundToGrid(on1.Y + factor.Y * (off1.Y - on1.Y));
                }
                if (!off2.IsSelected)
                {
                    off2.X = RoundToGrid(on1.X + factor.X * (off2.X - on1.X - sdelta.X));
                    off2.Y = RoundToGrid(on1.Y + factor.Y * (off2.Y - on1.Y - sdelta.Y));
                }
            }
        }
Exemple #3
0
        static bool IsFlatAngle(Data.Point p0, Data.Point p1, Data.Point p2, float tol = 0.05f)
        {
            var p01 = p1.ToVector2() - p0.ToVector2();
            var p12 = p2.ToVector2() - p1.ToVector2();

            return(Math.Abs(Ops.AngleBetween(p01, p12)) <= tol);
        }
    /// <summary>
    /// Find the tiles that the players can see
    /// </summary>
    public void SpfaEye(Tile t, PlayerMove p)
    {
        int[,] dis      = new int[Data.MapLen + 1, Data.MapWid + 1];    // the minimum moving distance between Tile t and Tile (i, j)
        bool[,] visited = new bool[Data.MapLen + 10, Data.MapWid + 10]; // if Tile (i, j) is in Queue q
        Queue <Data.Point> q = new Queue <Data.Point>();                // the queue used for Spfa algorithm

        for (int i = 1; i <= Data.MapLen; i++)
        {
            for (int j = 1; j <= Data.MapWid; j++)
            {
                dis[i, j]     = Data.INF; // initialize distance to INFINITY at first
                visited[i, j] = false;    // not in queue
            }
        }
        q.Clear();                                                                            // initialize queue

        dis[t.x, t.y] = 0;                                                                    // t is the starting tile, distance = 0
        q.Enqueue(new Data.Point(t.x, t.y));                                                  // push the tile t into the queue for checking the tiles beside it
        visited[t.x, t.y] = true;                                                             // tile t is in the queue

        while (q.Count > 0)                                                                   // queue not empty, updating required
        {
            Data.Point u = q.Dequeue();                                                       // get top of the queue
            visited[u.x, u.y] = false;                                                        // point u no longer in queue

            for (int i = 0; i < 4; i++)                                                       // going thru the four tiles around point u
            {
                Data.Point v = new Data.Point(u.x + dirx[i], u.y + diry[i]);                  // calculate the row and column of the point
                if (ValidTileForMoving(u, v))                                                 // point is valid
                {
                    if (dis[u.x, u.y] + Data.eyecost[Data.MapType[v.x, v.y]] < dis[v.x, v.y]) // relaxation operation
                    {
                        dis[v.x, v.y] = dis[u.x, u.y] + Data.eyecost[Data.MapType[v.x, v.y]]; // refresh minimum distance
                        if (!visited[v.x, v.y] && dis[v.x, v.y] <= p.maxEyeOfPlayer)          // point v not in queue
                        {
                            Data.Point ppush = new Data.Point(v.x, v.y);                      // v in point form
                            q.Enqueue(ppush);                                                 // add v into queue
                            visited[v.x, v.y] = true;                                         // record enqueue operation
                        }
                    }
                }
            }
        }

        for (int i = 1; i <= Data.MapLen; i++)
        {
            for (int j = 1; j <= Data.MapWid; j++)
            {
                Init.PointToTile(new Data.Point(i, j)).eyedis = dis[i, j];
                if (dis[i, j] <= p.maxEyeOfPlayer)
                {
                    GameObject tile = Init.PointToTile(new Data.Point(i, j)).gameObject;
                    eyelist.Add(tile.GetComponent <Tile>());
                    tile.GetComponent <Tile>().insight = true;
                    tile.GetComponent <Tile>().eyedis  = dis[i, j];
                }
            }
        }
    }
Exemple #5
0
    private void Update()
    {
        if (data == null || !data.IsReady)
        {
            return;
        }
        if (data.HasReadToEnd)
        {
            Debug.Log("Replay finished");
            data = null;
            if (MousePointerSurrogate != null)
            {
                Destroy(MousePointerSurrogate);
                MousePointerSurrogate = null;
            }
            return;
        }
        if (timer.ElapsedMilliseconds > nextPoint.dt)
        {
            timer.Restart();
            previousPoint = nextPoint;
            currentPoint  = previousPoint;
            nextPoint     = data.Next();
        }
        else
        {
            currentPoint.MouseChange = false;
        }

        float posInterpolation = (float)timer.ElapsedMilliseconds / (float)nextPoint.dt;

        currentPoint.x = nextPoint.x * posInterpolation + previousPoint.x * (1.0f - posInterpolation);
        currentPoint.y = nextPoint.y * posInterpolation + previousPoint.y * (1.0f - posInterpolation);

        FakeTouch();

        //Debug.Log(currentPoint.dt.ToString()+","+currentPoint.MouseDown.ToString()+",("+currentPoint.x.ToString("0.0")+","+currentPoint.y.ToString("0.0") +")");
        //Debug.Log(currentPoint.dt.ToString()+","+currentPoint.MouseDown.ToString()+",("+currentPoint.x.ToString()+","+currentPoint.y.ToString()+")");
        //Debug.Log(Input.mousePosition.ToString());

        if (MousePointerSurrogate == null)
        {
            MousePointerSurrogate = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            MousePointerSurrogate.transform.localScale = Vector3.one * 0.5f;
        }
        GameObject go = null;
        //if(currentPoint.MouseChange)
        //    go = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Vector2 tpos = Camera.main.ScreenToWorldPoint(new Vector3(Experiment.Input.mousePosition.x, Experiment.Input.mousePosition.y, Camera.main.nearClipPlane));
        Vector2 rpos = Camera.main.ScreenToWorldPoint(new Vector3(currentPoint.x, currentPoint.y, Camera.main.nearClipPlane));

        MousePointerSurrogate.transform.position = tpos;
        if (go != null)
        {
            go.transform.position   = rpos;
            go.transform.localScale = Vector3.one * 0.4f;
        }
    }
    /// <summary>
    /// Find the tiles that the players can see and the tiles that the players can move to.
    /// </summary>
    public void FindPath(PlayerMove p)
    {
        GetCurrentTile(p.gameObject);
        currentPoint = new Data.Point(currentTile.x, currentTile.y);

        SpfaEye(currentTile, p);
        SpfaMove(currentTile, p);

        p.pathChecked = true;
    }
Exemple #7
0
        public static bool AtOpenBoundary(Data.Point point)
        {
            var path = point.Parent;

            if (path.IsOpen)
            {
                return(path.Points[0] == point || path.Points[path.Points.Count - 1] == point);
            }
            return(false);
        }
Exemple #8
0
 public static bool TryJoinPath(Data.Layer layer, Data.Point point)
 {
     if (Is.AtOpenBoundary(point) && layer.Paths
         .SelectMany(path => path.Points)
         .Where(p => p != point && p.X == point.X && p.Y == point.Y)
         .LastOrDefault() is Data.Point otherPoint)
     {
         return(TryJoinPath(layer, point, otherPoint));
     }
     return(false);
 }
Exemple #9
0
    public void Init(string replayFile)
    {
        data  = new Data();
        timer = new System.Diagnostics.Stopwatch();
        data.Load(replayFile);

        previousPoint = data.Next();
        currentPoint  = previousPoint;
        nextPoint     = data.Next();

        timer.Start();
    }
Exemple #10
0
        public void AddLine(Vector2 to)
        {
            var point = new Data.Point(
                Outline.RoundToGrid(to.X),
                Outline.RoundToGrid(to.Y),
                Data.PointType.Line);
            var last = Path.Points.Last();

            if (!(point.X == last.X && point.Y == last.Y))
            {
                Path.Points.Add(point);
            }
        }
Exemple #11
0
 public static bool TryJoinPath(Data.Layer layer, Data.Point point, Data.Point otherPoint)
 {
     if (Is.AtOpenBoundary(point) && Is.AtOpenBoundary(otherPoint))
     {
         JoinPaths(point.Parent,
                   point.Parent.Points.IndexOf(point) == 0,
                   otherPoint.Parent,
                   otherPoint.Parent.Points.IndexOf(otherPoint) == 0,
                   true);
         return(true);
     }
     return(false);
 }
Exemple #12
0
 public Data.Point ToData()
 {
     Data.Point point = new Data.Point()
     {
         X           = this.X,
         Y           = this.Y,
         Width       = this.Width,
         Height      = this.Height,
         PointId     = this.Id,
         PointListId = this.PointListId,
         Argb        = this.Argb
     };
     return(point);
 }
Exemple #13
0
        static void VectorRotation(Data.Point point, Vector2 a, Vector2 b)
        {
            var ab     = b - a;
            var ab_len = ab.Length();

            if (ab_len != 0)
            {
                var p      = point.ToVector2();
                var pb_len = (b - p).Length();
                var t      = (ab_len + pb_len) / ab_len;

                point.X = RoundToGrid(a.X + t * ab.X);
                point.Y = RoundToGrid(a.Y + t * ab.Y);
            }
        }
Exemple #14
0
 static void ConstrainStaticHandles(Data.Point p1, Data.Point p2, Data.Point p3, float dx, float dy)
 {
     if (p2.IsSelected && p2.Type != PointType.Move)
     {
         if (p1.IsSelected || p3.IsSelected)
         {
             if (p1.IsSelected)
             {
                 (p1, p3) = (p3, p1);
             }
             if (!p1.IsSelected && p3.Type == PointType.None)
             {
                 VectorRotation(p3, p1.ToVector2(), p2.ToVector2());
             }
         }
         else
         {
             if (p2.IsSmooth)
             {
                 VectorProjection(p2, p1.ToVector2(), p3.ToVector2());
             }
         }
     }
     else if (p1.IsSelected != p3.IsSelected)
     {
         if (p1.IsSelected)
         {
             (p1, p3) = (p3, p1);
         }
         if (p3.Type == PointType.None)
         {
             if (p2.IsSmooth && p2.Type != PointType.Move)
             {
                 VectorProjection(p3, p1.ToVector2(), p2.ToVector2());
             }
             else
             {
                 // XXX: now that we're rounding, this doesn't work so well anymore
                 var rvec = new Vector2(p3.X - dx, p3.Y - dy);
                 VectorProjection(p3, p2.ToVector2(), rvec);
             }
         }
     }
 }
Exemple #15
0
        static void VectorProjection(Data.Point point, Vector2 a, Vector2 b)
        {
            var ab = b - a;
            var l2 = ab.LengthSquared();

            if (l2 != 0)
            {
                var ap = point.ToVector2() - a;
                var t  = Vector2.Dot(ap, ab) / l2;

                point.X = RoundToGrid(a.X + t * ab.X);
                point.Y = RoundToGrid(a.Y + t * ab.Y);
            }
            else
            {
                point.X = RoundToGrid(a.X);
                point.Y = RoundToGrid(a.Y);
            }
        }
    /// <summary>
    /// Some initiating sequences when a player selects the targetted tile
    /// </summary>
    /// <param name="p"></param>
    /// <param name="t"></param>
    public void MoveToTile(PlayerMove p, Tile t)                                                                                 // current player; target
    {
        p.moving               = true;                                                                                           // player is moving
        t.selected             = true;                                                                                           // mark the selected tile
        halfHeight             = p.gameObject.transform.Find("Character").gameObject.GetComponent <Collider>().bounds.extents.y; // obtain halfheight
        p.currentMoveOfPlayer -= t.movedis;                                                                                      // reduce the moving point of the player
        Text text = GameObject.Find("Canvas").transform.Find("RequiredMovePointNumber").gameObject.GetComponent <Text>();

        text.text = "0  ";

        // Finding the path from player's current position to the target position
        targetPoint = new Data.Point(t.x, t.y);
        pathPoint.Push(targetPoint);
        path.Push(Init.PointToTile(targetPoint));
        Data.Point now = targetPoint;
        while (now != currentPoint)
        {
            Data.Point tmp = now;
            now = prev[tmp.x, tmp.y];
            Init.PointToTile(tmp).parent = Init.PointToTile(now);
            pathPoint.Push(now);
            path.Push(Init.PointToTile(now));
        }
    }
    /// <summary>
    /// Find the tiles that the players can move to.
    /// </summary>
    public void SpfaMove(Tile t, PlayerMove p)
    {
        int[,] dis      = new int[Data.MapLen + 10, Data.MapWid + 10];
        bool[,] visited = new bool[Data.MapLen + 1, Data.MapWid + 1];
        Queue <Data.Point> q = new Queue <Data.Point>();

        for (int i = 1; i <= Data.MapLen; i++)
        {
            for (int j = 1; j <= Data.MapWid; j++)
            {
                dis[i, j]     = Data.INF;
                visited[i, j] = false;
                prev[i, j]    = new Data.Point(0, 0);
            }
        }
        q.Clear();

        dis[t.x, t.y] = 0;
        Data.Point push = new Data.Point(t.x, t.y);
        q.Enqueue(push);
        visited[t.x, t.y] = true;

        while (q.Count > 0)
        {
            Data.Point u = q.Dequeue();
            visited[u.x, u.y] = false;

            for (int i = 0; i < 4; i++)
            {
                Data.Point v = new Data.Point(u.x + dirx[i], u.y + diry[i]);
                if (ValidTileForMoving(u, v))
                {
                    if (dis[u.x, u.y] + Data.movecost[Data.MapType[v.x, v.y]] < dis[v.x, v.y])
                    {
                        dis[v.x, v.y]  = dis[u.x, u.y] + Data.movecost[Data.MapType[v.x, v.y]];
                        prev[v.x, v.y] = new Data.Point(u.x, u.y); // Record path
                        if (!visited[v.x, v.y] && dis[v.x, v.y] <= p.currentMoveOfPlayer)
                        {
                            Data.Point ppush = new Data.Point(v.x, v.y);
                            q.Enqueue(ppush);
                            visited[v.x, v.y] = true;
                        }
                    }
                }
            }
        }

        for (int i = 1; i <= Data.MapLen; i++)
        {
            for (int j = 1; j <= Data.MapWid; j++)
            {
                GameObject.Find("Row" + i.ToString()).transform.Find("Tile" + j.ToString()).gameObject.GetComponent <Tile>().movedis = dis[i, j];
                if (dis[i, j] <= p.currentMoveOfPlayer && Init.PointToTile(new Data.Point(i, j)).insight)
                {
                    GameObject row  = GameObject.Find("Row" + i.ToString());
                    GameObject tile = row.transform.Find("Tile" + j.ToString()).gameObject;
                    movelist.Add(tile.GetComponent <Tile>());
                    tile.GetComponent <Tile>().selectable = true;
                    tile.GetComponent <Tile>().movedis    = dis[i, j];
                }
            }
        }
    }
 /// <summary>
 /// Check if point q exists in map and the height difference of tile p and tile q is smaller than 2.
 /// </summary>
 public bool ValidTileForMoving(Data.Point p, Data.Point q)
 {
     return(q.x > 0 && q.x <= Data.MapLen && q.y > 0 && q.y <= Data.MapWid &&
            Mathf.Abs(Init.PointToTile(p).gameObject.transform.position.y - Init.PointToTile(q).gameObject.transform.position.y) <= 2);
 }
Exemple #19
0
        public static bool TryTogglePointSmoothness(Data.Point point)
        {
            var path = point.Parent;

            return(TryTogglePointSmoothness(path, path.Points.IndexOf(point)));
        }
Exemple #20
0
 /// <summary>
 /// Check if a point exist in the map.
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static bool ValidPoint(Data.Point p)
 {
     return(p.x > 0 && p.x <= Data.MapLen && p.y > 0 && p.y <= Data.MapWid);
 }
Exemple #21
0
        public override void OnPointerPressed(DesignCanvas canvas, PointerRoutedEventArgs args)
        {
            base.OnPointerPressed(canvas, args);

            var ptPoint = args.GetCurrentPoint(canvas);

            if (ptPoint.Properties.IsLeftButtonPressed && canvas.Layer is Data.Layer layer)
            {
                var pos = canvas.FromClientPosition(ptPoint.Position);
                // TODO: should we ignore Anchor/Component etc. here?
                var tappedItem = canvas.HitTest(pos, testSegments: true);
                var selPoint   = GetSelectedPoint(layer);

                _screenOrigin = ptPoint.Position;
                _undoGroup    = layer.CreateUndoGroup();
                if (tappedItem is Data.Point tappedPoint && tappedPoint.Type != Data.PointType.None)
                {
                    var tappedPath = tappedPoint.Parent;

                    if (Is.AtOpenBoundary(tappedPoint))
                    {
                        // If we click a boundary from another boundary, join the paths
                        if (selPoint != null && Is.AtOpenBoundary(selPoint) && AreVisiblyDistinct(canvas, selPoint, tappedPoint))
                        {
                            var selPath   = selPoint.Parent;
                            var selPoints = selPath.Points;
                            if (selPoint.Type == Data.PointType.None)
                            {
                                selPoint.IsSelected = false;
                                selPoints.Pop();
                                var lastOn = selPoints.Last();
                                _stashedOffCurve = (selPoint, lastOn.IsSmooth);
                                lastOn.IsSmooth  = false;
                            }
                            Outline.JoinPaths(selPath, selPoints[0] == selPoint,
                                              tappedPath, tappedPath.Points[0] == tappedPoint);
                            // Drag a control point, except if we're joining a different path (as we're not at boundary
                            // of the resulting path)
                            if (selPath == tappedPath)
                            {
                                _path = selPath;
                            }
                        }
                        // Otherwise reverse the path if needed and we'll drag the boundary point
                        else
                        {
                            if (tappedPoint == tappedPath.Points.First())
                            {
                                tappedPath.Reverse();
                            }

                            _path = tappedPath;
                        }
                    }
                    // If we clicked on an inside point, just break its path open.
                    else
                    {
                        TryRemoveTrailingOffCurve(layer);
                        layer.ClearSelection();

                        Outline.BreakPath(tappedPath, tappedPath.Points.IndexOf(tappedPoint));
                    }

                    if (selPoint != null)
                    {
                        selPoint.IsSelected = false;
                    }
                    tappedPoint.IsSelected = true;
                }
                else if (tappedItem is Data.Segment segment)
                {
                    var result = segment.ProjectPoint(pos.ToVector2());

                    if (result.HasValue)
                    {
                        var t = result.Value.Item2;

                        if (!args.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift))
                        {
                            layer.ClearSelection();
                        }
                        var otherSegment = segment.SplitAt(t);

                        foreach (var point in Enumerable.Concat(segment.Points, otherSegment.OffCurves))
                        {
                            point.X = Outline.RoundToGrid(point.X);
                            point.Y = Outline.RoundToGrid(point.Y);
                        }

                        _point            = segment.OnCurve;
                        _point.IsSelected = true;

                        _undoGroup.Dispose();
                        _undoGroup = layer.CreateUndoGroup();
                    }
                }
                else
                {
                    ObserverList <Data.Point> points;
                    Data.PointType            type;
                    // Add a point to the current path, if any
                    if (selPoint != null && Is.AtOpenBoundary(selPoint))
                    {
                        _path  = selPoint.Parent;
                        points = _path.Points;
                        var lastPoint = points.Last();
                        lastPoint.IsSelected = false;
                        if (lastPoint.Type == Data.PointType.None)
                        {
                            points.Pop();
                            var lastOn = points.Last();
                            _stashedOffCurve = (lastPoint, lastOn.IsSmooth);
                            lastOn.IsSmooth  = false;
                            // For shift origin, always use an onCurve
                            lastPoint = lastOn;
                        }
                        if (args.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift))
                        {
                            pos = ClampToOrigin(pos, new Point(lastPoint.X, lastPoint.Y));
                        }
                        type = Data.PointType.Line;
                    }
                    // Else just create a new one
                    else
                    {
                        _path  = new Data.Path();
                        points = _path.Points;
                        layer.Paths.Add(_path);
                        type = Data.PointType.Move;
                    }

                    // In any case, unselect all points (*click*) and enable new point
                    layer.ClearSelection();
                    var x = Outline.RoundToGrid((float)pos.X);
                    var y = Outline.RoundToGrid((float)pos.Y);
                    points.Add(new Data.Point(x, y, type)
                    {
                        IsSelected = true
                    });
                }

                ((App)Application.Current).InvalidateData();
            }
Exemple #22
0
 public SplitIterator(Data.Point splitPoint)
 {
     _splitPoint = splitPoint;
 }
Exemple #23
0
        // Use this for initialization
        private void Start()
        {
            var gen = GameObject.Find("WallCreator").GetComponent <GenerateGenerateWall>();

            _destroy = new List <GameObject>(); //This initializes the food object destroy list

            var activeGoals    = E.Get().CurrTrial.trialData.ActiveGoals;
            var inactiveGoals  = E.Get().CurrTrial.trialData.InactiveGoals;
            var invisibleGoals = E.Get().CurrTrial.trialData.InvisibleGoals;
            var inactiveSet    = new HashSet <int>(inactiveGoals);
            var invisibleSet   = new HashSet <int>(invisibleGoals);
            var activeSet      = new HashSet <int>(activeGoals);

            var merged = new List <int>();

            merged.AddRange(activeGoals);
            merged.AddRange(inactiveGoals);
            merged.AddRange(invisibleGoals);

            Data.Point p = new Data.Point {
                X = 0, Y = 0, Z = 0
            };
            foreach (var val in merged)
            {
                var goalItem = DS.GetData().Goals[Mathf.Abs(val) - 1];
                UnityEngine.Debug.Log(goalItem);

                // Position is not set in the config file
                if (goalItem.Position.Count == 0)
                {
                    p = ReadFromExternal(goalItem.PythonFile);
                }
                else
                {
                    try
                    {
                        p = new Data.Point {
                            X = goalItem.PositionVector.x, Y = goalItem.PositionVector.y, Z = goalItem.PositionVector.z
                        };
                    }
                    catch (Exception _)
                    {
                        p = new Data.Point {
                            X = goalItem.PositionVector.x, Y = 0.5f, Z = goalItem.PositionVector.z
                        };
                    }
                }

                GameObject prefab;
                GameObject obj;
                var        spriteName = "";

                if (goalItem.Type.ToLower().Equals("3d"))
                {
                    prefab = (GameObject)Resources.Load("3D_Objects/" + goalItem.Object, typeof(GameObject));
                    obj    = Instantiate(prefab);
                    obj.AddComponent <RotateBlock>();
                }
                else
                {
                    // Load the "2D" prefab here, so we have the required components
                    prefab     = (GameObject)Resources.Load("3D_Objects/" + goalItem.Type.ToUpper(), typeof(GameObject));
                    obj        = Instantiate(prefab);
                    spriteName = goalItem.Object;
                }

                obj.transform.Rotate(goalItem.RotationVector);
                obj.transform.localScale = goalItem.ScaleVector;
                obj.transform.position   = new Vector3(p.X, p.Y, p.Z);

                obj.AddComponent <PickupSound>();
                obj.GetComponent <PickupSound>().Sound = Resources.Load <AudioClip>("Sounds/" + goalItem.Sound);

                if (!string.IsNullOrEmpty(spriteName))
                {
                    var pic = Img2Sprite.LoadNewSprite(DataSingleton.GetData().SpritesPath + spriteName);
                    obj.GetComponent <SpriteRenderer>().sprite = pic;
                }

                var color = Data.GetColour(goalItem.Color);

                try
                {
                    obj.GetComponent <Renderer>().material.color = color;
                    obj.GetComponent <Renderer>().enabled        = !invisibleSet.Contains(val);
                    obj.GetComponent <Collider>().enabled        = !inactiveSet.Contains(val);

                    if (activeSet.Contains(val) || invisibleSet.Contains(val))
                    {
                        obj.tag = "Pickup";
                        obj.GetComponent <Collider>().isTrigger = true;
                    }
                }
                catch (Exception _)
                {
                    print("Visibility not working");
                }

                _destroy.Add(obj);
            }

            GameObject.Find("Participant").GetComponent <PlayerController>().ExternalStart(p.X, p.Z);
        }
Exemple #24
0
 /// <summary>
 /// Transforms a Point-formed tile to a Tile-formed tile.
 /// </summary>
 /// <param name="p"></param>
 public static Tile PointToTile(Data.Point p)
 {
     return(GameObject.Find("Map").transform.Find("Row" + p.x.ToString()).transform.Find("Tile" + p.y.ToString()).gameObject.GetComponent <Tile>());
 }