コード例 #1
0
        Room IAutomapCanvas.CreateRoom(Room existing, AutomapDirection directionFromExisting, string name)
        {
            if (!Project.Current.Elements.Contains(existing))
            {
                // avoid issues if the user has just deleted the existing room
                return(null);
            }

            var room = new Room(Project.Current);

            room.Name = name;

            Vector delta;

            PositionRelativeTo(room, existing, CompassPointHelper.GetCompassDirection(directionFromExisting), out delta);

            if (AnyRoomsIntersect(room))
            {
                ShiftMap(room.InnerBounds, delta);
                Debug.WriteLine("Shift map.");
            }

            Project.Current.Elements.Add(room);

            return(room);
        }
コード例 #2
0
        void IAutomapCanvas.RemoveExitStub(Room room, AutomapDirection direction)
        {
            if (!Project.Current.Elements.Contains(room))
            {
                // avoid issues if the user has just deleted one of these rooms
                return;
            }

            var compassPoint = CompassPointHelper.GetCompassDirection(direction);

            foreach (var connection in room.GetConnections(compassPoint))
            {
                CompassPoint sourceCompassPoint, targetCompassPoint;
                var          source = connection.GetSourceRoom(out sourceCompassPoint);
                var          target = connection.GetTargetRoom(out targetCompassPoint);
                if (source == room && target == room && sourceCompassPoint == compassPoint && targetCompassPoint == compassPoint)
                {
                    Project.Current.Elements.Remove(connection);
                }
            }
        }
コード例 #3
0
        void IAutomapCanvas.AddExitStub(Room room, AutomapDirection direction)
        {
            if (!Project.Current.Elements.Contains(room))
            {
                // avoid issues if the user has just deleted one of these rooms
                return;
            }

            var sourceCompassPoint = CompassPointHelper.GetCompassDirection(direction);
            var connection         = addConnection(room, sourceCompassPoint, room, sourceCompassPoint);

            switch (direction)
            {
            case AutomapDirection.Up:
                connection.StartText = Connection.Up;
                break;

            case AutomapDirection.Down:
                connection.StartText = Connection.Down;
                break;
            }
        }
コード例 #4
0
        void IAutomapCanvas.Connect(Room source, AutomapDirection directionFromSource, Room target)
        {
            if (!Project.Current.Elements.Contains(source) || !Project.Current.Elements.Contains(target))
            {
                // avoid issues if the user has just deleted one of these rooms
                return;
            }

            // work out the correct compass point to use for the given direction

            // look for existing connections:
            // if the given direction is up/down/in/out, any existing connection will suffice;
            // otherwise, only match an existing connection if it's pretty close to the one we want.
            var          sourceCompassPoint = CompassPointHelper.GetCompassDirection(directionFromSource);
            CompassPoint?acceptableSourceCompassPoint;

            switch (directionFromSource)
            {
            case AutomapDirection.Up:
            case AutomapDirection.Down:
            case AutomapDirection.In:
            case AutomapDirection.Out:
                acceptableSourceCompassPoint = null;     // any existing connection will do
                break;

            default:
                acceptableSourceCompassPoint = sourceCompassPoint;
                break;
            }
            bool wrongWay;
            var  connection = FindConnection(source, target, acceptableSourceCompassPoint, out wrongWay);

            if (connection == null)
            {
                // there is no suitable connection between these rooms:
                var targetCompassPoint = CompassPointHelper.GetAutomapOpposite(sourceCompassPoint);

                // check whether we can move one of the rooms to make the connection tidier;
                // we won't need this very often, but it can be useful especially if the user teleports into a room
                // and then steps out into an existing one (this can appear to happen if the user moves into a
                // dark room, turns on the light, then leaves).
                TryMoveRoomsForTidyConnection(source, sourceCompassPoint, target, targetCompassPoint);

                // add a new connection
                connection       = addConnection(source, sourceCompassPoint, target, targetCompassPoint);
                connection.Style = ConnectionStyle.Solid;
                connection.Flow  = ConnectionFlow.OneWay;
            }
            else if (wrongWay)
            {
                // there is a suitable connection between these rooms, but it goes the wrong way;
                // make it bidirectional since we can now go both ways.
                connection.Flow = ConnectionFlow.TwoWay;
            }

            // if this is an up/down/in/out connection, mark it as such;
            // but don't override any existing text.
            switch (directionFromSource)
            {
            case AutomapDirection.Up:
            case AutomapDirection.Down:
            case AutomapDirection.In:
            case AutomapDirection.Out:
                if (string.IsNullOrEmpty(connection.StartText) && string.IsNullOrEmpty(connection.EndText))
                {
                    switch (directionFromSource)
                    {
                    case AutomapDirection.Up:
                        connection.SetText(wrongWay ? ConnectionLabel.Down : ConnectionLabel.Up);
                        break;

                    case AutomapDirection.Down:
                        connection.SetText(wrongWay ? ConnectionLabel.Up : ConnectionLabel.Down);
                        break;

                    case AutomapDirection.In:
                        connection.SetText(wrongWay ? ConnectionLabel.Out : ConnectionLabel.In);
                        break;

                    case AutomapDirection.Out:
                        connection.SetText(wrongWay ? ConnectionLabel.In : ConnectionLabel.Out);
                        break;
                    }
                }
                break;
            }
        }