Beispiel #1
0
        private void NewDomain(string rootDir)
        {
            //obtain the name of the domain from the final directory
            List <string> sub = new List <string>(rootDir.Split('\\'));

            Name          = sub[sub.Count - 1];
            RootDirectory = rootDir;

            //there is always at least one DomainReference, this domain!
            DomainReference localRef = new DomainReference("domain");

            Include            = new IncludeFile(Name);
            localRef.Doors     = new Dictionary <string, FileReferenceModel>();
            localRef.Inventory = new Dictionary <string, FileReferenceModel>();

            DomainFileReferences = new List <DomainReference>();
            DomainFileReferences.Add(localRef);

            //Directories = new DirectoryStructure(RootDirectory);
            Rooms       = new LinkedList <RoomModel>();
            RoomNameMap = new Dictionary <string, RoomModel>();

            //load all sub directories and files
            DomainInitialized = true;
        }
Beispiel #2
0
        private DomainReference ParseXmlFileReferences(string domainFileName)
        {
            DomainReference domRef = new DomainReference(domainFileName);

            //the workspace was already reset so the root directory should be good to go
            //find the master XML file and begin disecting the directory layout and file locations
            string masterFile = Globals.Dirs.DomainReferences + "\\" + domainFileName + ".xml";

            if (!System.IO.File.Exists(masterFile))
            {
                throw new DomainModelException("External domain reference " + domainFileName + " is missing.");
            }

            Sluggy.Utility.XmlParser xml;
            try{
                bool validFile = false;
                xml = new Sluggy.Utility.XmlParser(masterFile);
                if (xml.Contents.Children[0].Name == "domain")
                {
                    validFile = true;
                    Sluggy.Utility.Tag domainTag = xml.Contents.Children[0];
                    foreach (Sluggy.Utility.Tag tag in domainTag.Children)
                    {
                        //HACK ALERT - might as well just hardcode a giant ugly-ass switch while I'm at it

                        //remember, this is for a domain reference file. We aren't loading an files, just getting their
                        //names and importing them into the workspace.

                        #region room tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "room")
                        {
                            foreach (Sluggy.Utility.Tag roomTag in tag.Children)
                            {
                                string roomName;

                                if (roomTag.Attributes.ContainsKey("name"))
                                {
                                    roomName = roomTag.Attributes["name"];
                                }
                                else
                                {
                                    throw new DomainModelException("Missing room name in external domain " + domainFileName + ".");
                                }

                                domRef.Rooms.Add(domRef.ConvertRoomNameToFullPath(roomName), new FileReferenceModel(roomName, ItemSaveType.Room, Include, domainFileName));
                            }
                            //break;
                        }

                        #endregion

                        #region item tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "inventory")
                        {
                            foreach (Sluggy.Utility.Tag itemTag in tag.Children)
                            {
                                if (itemTag.Attributes.ContainsKey("name") && itemTag.Attributes.ContainsKey("class"))
                                {
                                    string name      = itemTag.Attributes["name"];
                                    string itemClass = itemTag.Attributes["class"];

                                    domRef.Inventory.Add(domRef.ConvertRoomNameToFullPath(name), new FileReferenceModel(name, Include.DetermineSaveType(itemClass), Include, domainFileName));
                                }
                            }
                        }
                        #endregion
                        //break;
                    }
                }
                if (!validFile)
                {
                    throw new DomainModelException("Invalid master XML file. Could not load domain.");
                }
            }
            catch (Sluggy.Utility.XMLParserException exception)
            {
                throw new DomainModelException("Failed to parse domain master XML file.\n\n" + exception.Message);
            }
            catch (System.IndexOutOfRangeException exception)
            {
                throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception);
            }
            catch (System.ArgumentOutOfRangeException exception)
            {
                throw new DomainModelException("Corrupted master XML file. Could not load domain.", exception);
            }
            return(domRef);
        }