Exemplo n.º 1
0
            private static void DrawDoorLine(DoorLineGrid2D doorLine, Grid grid, Color color, string label = null)
            {
                var line      = new OrthogonalLineGrid2D(doorLine.From.ToCustomIntVector2(), doorLine.To.ToCustomIntVector2());
                var fromSolid = line.From;
                var toSolid   = line.From;

                if (line.Length > 0)
                {
                    toSolid += (doorLine.Length - 1) * line.GetDirectionVector();
                }

                var toDotted = line.To;

                var doorsCount = line.Length - doorLine.Length + 2;

                if (doorsCount > 0)
                {
                    var finalLabel = $"{doorsCount} door{(doorsCount != 1 ? "s" : "")}\nSize {doorLine.Length}";

                    if (label != null)
                    {
                        finalLabel += $"\n{label}";
                    }

                    DrawRectangleOutline(grid, fromSolid.ToUnityIntVector3(), toSolid.ToUnityIntVector3(),
                                         color, new Vector2(0.2f, 0.2f));
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Reverses a given events list in a way that the line has the opposite direction.
        /// </summary>
        /// <param name="events"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        protected List <Tuple <Vector2Int, bool> > ReverseEvents(List <Tuple <Vector2Int, bool> > events, OrthogonalLineGrid2D line)
        {
            var eventsCopy = new List <Tuple <Vector2Int, bool> >(events);

            if (events.Count == 0)
            {
                return(events);
            }

            eventsCopy.Reverse();
            var newEvents = new List <Tuple <Vector2Int, bool> >();

            if (events.Last().Item2)
            {
                newEvents.Add(Tuple.Create(line.To, true));
            }

            foreach (var @event in eventsCopy)
            {
                if (!(@event.Item1 == line.From && @event.Item2 == true))
                {
                    newEvents.Add(Tuple.Create(@event.Item1 - line.GetDirectionVector(), [email protected]));
                }
            }

            return(newEvents);
        }
Exemplo n.º 3
0
        private SimpleDoorModeSettingsGrid2D GetSettings(OrthogonalLineGrid2D line)
        {
            if (Mode == SettingsMode.Basic)
            {
                var data = this;

                return(new SimpleDoorModeSettingsGrid2D()
                {
                    Length = data.DoorLength,
                    Margin1 = data.DistanceFromCorners,
                    Margin2 = data.DistanceFromCorners,
                });
            }

            return(line.GetDirectionVector().X != 0 ? HorizontalDoors : VerticalDoors);
        }
Exemplo n.º 4
0
        public static DoorLineGrid2D TransformDoorLine(DoorLineGrid2D doorLine, TransformationGrid2D transformation)
        {
            var doorPosition = doorLine.Line;

            if (doorPosition.GetDirection() == OrthogonalLineGrid2D.Direction.Undefined)
            {
                throw new InvalidOperationException("Cannot fix door direction when original direction is undefined");
            }

            switch (transformation)
            {
            case TransformationGrid2D.Identity:
                return(doorLine);

            case TransformationGrid2D.Rotate90:
                return(new DoorLineGrid2D(doorPosition.Rotate(90), doorLine.Length, doorLine.DoorSocket));

            case TransformationGrid2D.Rotate180:
                return(new DoorLineGrid2D(doorPosition.Rotate(180), doorLine.Length, doorLine.DoorSocket));

            case TransformationGrid2D.Rotate270:
                return(new DoorLineGrid2D(doorPosition.Rotate(270), doorLine.Length, doorLine.DoorSocket));
            }

            // Other transformations need to switch door directions
            var firstStartPoint      = doorPosition.From.Transform(transformation);
            var lastStartPoint       = doorPosition.To.Transform(transformation);
            var length               = doorLine.Length;
            var transformedDirection = TransformDirection(doorPosition.GetDirection(), transformation);
            var transformedLine      = new OrthogonalLineGrid2D(firstStartPoint, lastStartPoint, transformedDirection);

            var lastEndPoint = lastStartPoint + length * transformedLine.GetDirectionVector();

            var newDirection    = OrthogonalLineGrid2D.GetOppositeDirection(transformedDirection);
            var newDoorPosition = new OrthogonalLineGrid2D(lastEndPoint, lastEndPoint + transformedLine.Length * transformedLine.SwitchOrientation().GetDirectionVector(), newDirection);

            if (newDoorPosition.Length != doorPosition.Length)
            {
                throw new InvalidOperationException();
            }

            return(new DoorLineGrid2D(newDoorPosition, doorLine.Length, doorLine.DoorSocket));
        }