Example #1
0
        Room IAutomapCanvas.FindRoom(string roomName, string roomDescription, string line, RoomMatcher matcher)
        {
            var list = new List <Room>();

            foreach (var element in Project.Current.Elements)
            {
                var room1 = element as Room;
                if (room1 != null)
                {
                    var room    = room1;
                    var matches = matcher(roomName, roomDescription, room);
                    if (matches.HasValue && matches.Value)
                    {
                        // it's definitely this room
                        return(room);
                    }
                    if (!matches.HasValue)
                    {
                        // it's ambiguous
                        list.Add(room);
                    }
                }
            }

            if (list.Count == 0)
            {
                return(null);
            }
            if (mDontAskAboutAmbiguities)
            {
                // the user has long given up on this process;
                // use the first ambiguous room in the list.
                return(list[0]);
            }
            if ((string.IsNullOrEmpty(roomDescription) || !list[0].HasDescription) && list.Count == 1)
            {
                // technically it's ambiguous, but we don't two descriptions for the user to compare;
                // there's only one option, so use it. They probably didn't have VERBOSE on for the whole transcript.
                return(list[0]);
            }

            using (var dialog = new DisambiguateRoomsDialog())
            {
                dialog.SetTranscriptContext(roomName, roomDescription, line);
                dialog.AddAmbiguousRooms(list);
                dialog.ShowDialog();
                if (dialog.UserDoesntCareAnyMore)
                {
                    // The user has given up on this process! Can't say I blame them.
                    // Use the first ambiguous room on the list, as above.
                    mDontAskAboutAmbiguities = true;
                    return(list[0]);
                }

                // Either the user picked a room, or they said "New Room" in which case we don't match, returning null.
                return(dialog.Disambiguation);
            }
        }
Example #2
0
        Room IAutomapCanvas.FindRoom(string roomName, string roomDescription, string line, RoomMatcher matcher)
        {
            var list = new List <Room>();

            foreach (var element in Project.Current.Elements)
            {
                if (element is Room room1)
                {
                    var room    = room1;
                    var matches = matcher(roomName, roomDescription, room);
                    if (matches.HasValue && matches.Value)
                    {
                        return(room);
                    }
                    if (!matches.HasValue)
                    {
                        list.Add(room);
                    }
                }
            }

            if (list.Count == 0)
            {
                return(null);
            }
            if (mDontAskAboutAmbiguities)
            {
                return(list[0]);
            }
            if ((string.IsNullOrEmpty(roomDescription) || !list[0].HasDescription) && list.Count == 1)
            {
                return(list[0]);
            }

            using (var dialog = new DisambiguateRoomsDialog()) {
                dialog.SetTranscriptContext(roomName, roomDescription, line);
                dialog.AddAmbiguousRooms(list);
                dialog.ShowDialog();
                if (dialog.UserDoesntCareAnyMore)
                {
                    // The user has given up on this process! Can't say I blame them.
                    // Use the first ambiguous room on the list, as above.
                    mDontAskAboutAmbiguities = true;
                    return(list[0]);
                }

                // Either the user picked a room, or they said "New Room" in which case we don't match, returning null.
                return(dialog.Disambiguation);
            }
        }