コード例 #1
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
        public void RemoveExitFromRoom(string targetRoom, string exitToPath)
        {
            if (targetRoom == "" || exitToPath == "")
            {
                return;
            }
            string    targetFunction = "SetExits";
            RoomModel room           = RoomNameMap[targetRoom];

            //first order of business is to see if we even have any exits defined
            if (room.FunctionCalls.CallList.ContainsKey(targetFunction))
            {
                //function is defined. now, is the exit present?
                string mapping = room.FunctionCalls.CallList[targetFunction];
                if (mapping.Contains(exitToPath))
                {
                    //ok, we know the exit is here. Now we just need to find and remove it.
                    //Note, there can be more than one.
                    try
                    {
                        Dictionary <string, string> map     = ParserTools.StringIntoMap(mapping, targetFunction);
                        Dictionary <string, string> rebuild = new Dictionary <string, string>();

                        foreach (string key in map.Keys)
                        {
                            //if(map[key] != exitToPath)
                            //    {
                            //    //only add entries that aren't to be removed
                            //    rebuild.Add(key,map[key]);
                            //    }
                            //J.C. -2/16/2010 - changed to remove entry based on exit direction rather than
                            //                  exit destination. That way we don't remove multiple entries
                            //                  when the user indented only one.
                            if (key != "\"" + exitToPath + "\"")
                            {
                                rebuild.Add(key, map[key]);
                            }
                        }

                        room.EditorState.ExitsList = rebuild;
                        room.FunctionCalls.CallList[targetFunction] = ParserTools.MapIntoString(rebuild);
                    }
                    catch (ParserException e)
                    {
                        System.Windows.Forms.MessageBox.Show(e.Message, ParserErrorTitle);
                        return;
                    }
                }
            }
        }
コード例 #2
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
        public void RemoveEnterFromRoom(string targetRoom, string exitToPath)
        {
            if (targetRoom == "" || exitToPath == "")
            {
                return;
            }
            string    targetFunction = "SetEnters";
            RoomModel room           = RoomNameMap[targetRoom];

            //first order of business is to see if we even have any exits defined
            if (room.FunctionCalls.CallList.ContainsKey(targetFunction))
            {
                //function is defined. now, is the exit present?
                string mapping = room.FunctionCalls.CallList[targetFunction];
                if (mapping.Contains(exitToPath))
                {
                    //ok, we know the exit is here. Now we just need to find and remove it
                    //Note, there can be more than one.
                    try
                    {
                        Dictionary <string, string> map     = ParserTools.StringIntoMap(mapping, targetFunction);
                        Dictionary <string, string> rebuild = new Dictionary <string, string>();

                        foreach (string key in map.Keys)
                        {
                            if (map[key] != exitToPath)
                            {
                                //only add entries that aren't to be removed
                                rebuild.Add(key, map[key]);
                            }
                        }

                        room.EditorState.EntersList = rebuild;
                        room.FunctionCalls.CallList[targetFunction] = ParserTools.MapIntoString(rebuild);
                    }
                    catch (ParserException e)
                    {
                        System.Windows.Forms.MessageBox.Show(e.Message, ParserErrorTitle);
                        return;
                    }
                }
            }
        }
コード例 #3
0
 private string ControlIntoMap()
 {
     return(ParserTools.MapIntoString(Mapping));
 }
コード例 #4
0
ファイル: DomainModel.cs プロジェクト: jamClark/Stellarmap
        public void AddEnterToRoom(string targetRoom, string exitToPath, string direction)
        {
            if (targetRoom == "" || exitToPath == "" || direction == "")
            {
                return;
            }
            if (targetRoom == exitToPath)
            {
                System.Windows.Forms.MessageBox.Show("You cannot have " + targetRoom + " enter into itself.");
                return;
            }
            string    targetFunction = "SetEnters";
            RoomModel room           = RoomNameMap[targetRoom];

            //first order of business is to make sure we even have the
            //function call for an exit, otherwise we need to create it
            if (room.FunctionCalls.CallList.ContainsKey(targetFunction))
            {
                //function call exists. Do we already have an entry for this direction?
                try
                {
                    Dictionary <string, string> map = ParserTools.StringIntoMap(room.FunctionCalls.CallList[targetFunction], targetFunction);
                    if (map.ContainsKey(direction))
                    {
                        //we have to edit a pre-existing entry
                        foreach (string key in map.Keys)
                        {
                            if (key == direction)
                            {
                                map[key] = exitToPath;
                                room.EditorState.EntersList = map;
                                room.FunctionCalls.CallList[targetFunction] = ParserTools.MapIntoString(map);
                                return;
                            }
                        }
                    }
                    else
                    {
                        //entry does not exist, create it now
                        map.Add(direction, exitToPath);
                        room.EditorState.EntersList = map;
                        room.FunctionCalls.CallList[targetFunction] = ParserTools.MapIntoString(map);
                        return;
                    }
                }
                catch (ParserException e)
                {
                    System.Windows.Forms.MessageBox.Show(e.Message, ParserErrorTitle);
                }
            }
            else
            {
                //we are storing this function call for the first time
                //TODO: Implement this
                //throw new Exception("Function doesn not exist in this control. TODO: Implement Model.AddExitToRoom()");
                Dictionary <string, string> map = new Dictionary <string, string>();
                map.Add(direction, exitToPath);
                room.EditorState.EntersList = map;
                room.FunctionCalls.CallList.Add(targetFunction, ParserTools.MapIntoString(map));
            }
        }