Exemplo n.º 1
0
        //inventory
        public void AddDoor(string door, ItemSaveType type)
        {
            if (door == null || door.Length < 1)
            {
                return;
            }

            if (!DomainFileReferences[THIS_DOMAIN].Doors.ContainsKey(door))
            {
                FileReferenceModel mod = new FileReferenceModel(door, type, Include, this.Name);
                DomainFileReferences[THIS_DOMAIN].Doors.Add(door, mod);
            }
        }
Exemplo n.º 2
0
        public bool AddInventory(string inventory, ItemSaveType type)
        {
            if (inventory == null || inventory.Length < 1)
            {
                return(false);
            }

            //hack alert - gotta infer the item type from the directory.
            //This was added to make the 'import item' functionality work
            if (type == ItemSaveType.Unknown)
            {
                string[] path = inventory.Split('\\');
                type = Include.DetermineSaveType(path[path.Length - 2]);
                if (type == ItemSaveType.Unknown)
                {
                    return(false);
                }

                string inventoryName = path[path.Length - 1].Split('.')[0];
                if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(inventoryName))
                {
                    FileReferenceModel mod = new FileReferenceModel(inventoryName, type, Include, this.Name);
                    DomainFileReferences[THIS_DOMAIN].Inventory.Add(inventoryName, mod);
                }
            }
            else
            {
                if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(inventory))
                {
                    FileReferenceModel mod = new FileReferenceModel(inventory, type, Include, this.Name);
                    DomainFileReferences[THIS_DOMAIN].Inventory.Add(inventory, mod);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        private bool Deserialize(VirtualDomain vd)
        {
            //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 = this.RootDirectory + "\\" + this.Name + ".xml";

            if (!System.IO.File.Exists(masterFile))
            {
                throw new DomainModelException("No domain master file found. Cannot load domain.");
            }

            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
                        //look for the 'room' directory tag
                        #region room tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "room")
                        {
                            //we now have the room directory, start loading room files
                            foreach (Sluggy.Utility.Tag roomTag in tag.Children)
                            {
                                string roomName, iconName;
                                int    xPos, yPos;

                                if (roomTag.Attributes.ContainsKey("name"))
                                {
                                    roomName = roomTag.Attributes["name"];
                                }
                                else
                                {
                                    throw new DomainModelException("Missing room name in domain master file. Canceling domain laoding. Please manually edit the master xml file to reflect all room files.");
                                }
                                if (roomTag.Attributes.ContainsKey("x"))
                                {
                                    xPos = System.Convert.ToInt32(roomTag.Attributes["x"]);
                                }
                                else
                                {
                                    xPos = 0;
                                }
                                if (roomTag.Attributes.ContainsKey("y"))
                                {
                                    yPos = System.Convert.ToInt32(roomTag.Attributes["y"]);
                                }
                                else
                                {
                                    yPos = 0;
                                }
                                if (roomTag.Attributes.ContainsKey("icon"))
                                {
                                    iconName = roomTag.Attributes["icon"];
                                }
                                else
                                {
                                    iconName = Globals.ImageBoxProperties.DefaultIconDesc;
                                }


                                //failure to load a room does not necesitate failure to load the domain
                                try{ this.LoadRoom(roomName); }
                                catch (Sluggy.Utility.XMLParserException exception)
                                {
                                    //throw new DomainModelException("Invalid master XML file. Could not load domain.",exception);
                                    System.Windows.Forms.MessageBox.Show("Failure loading room file '" + roomName + "' due to parsing error.\n\n" + exception.Message);
                                }
                                catch (DomainModelException exception)
                                {
                                    System.Windows.Forms.MessageBox.Show(exception.Message);
                                }

                                vd.AddImage(new System.Drawing.Point(xPos, yPos),
                                            Globals.ImageBoxProperties.DefaultImage,
                                            this.DomainFileReferences[THIS_DOMAIN].ConvertRoomNameToFullPath(roomName),
                                            iconName);
                                //the room object still needs it's iocn bitmap to be set
                                //however, the bitmaps loaded from the config file are only
                                //available to the DomainViewForm so it will have to deal with this
                            }
                            //break;
                        }
                        #endregion

                        #region door tag parsing
                        if (tag.Name == "directory" && tag.Attributes["name"] == "doors")
                        {
                            foreach (Sluggy.Utility.Tag doorTag in tag.Children)
                            {
                                if (doorTag.Attributes.ContainsKey("name") && doorTag.Attributes.ContainsKey("class"))
                                {
                                    string name      = doorTag.Attributes["name"];
                                    string doorClass = doorTag.Attributes["class"];

                                    if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(name))
                                    {
                                        FileReferenceModel mod = new FileReferenceModel(name, Include.DetermineSaveType(doorClass), Include, this.Name);
                                        DomainFileReferences[THIS_DOMAIN].Doors.Add(name, mod);
                                    }
                                }
                            }
                        }
                        #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"];

                                    if (!DomainFileReferences[THIS_DOMAIN].Inventory.ContainsKey(name))
                                    {
                                        FileReferenceModel mod = new FileReferenceModel(name, Include.DetermineSaveType(itemClass), Include, this.Name);
                                        DomainFileReferences[THIS_DOMAIN].Inventory.Add(name, mod);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region domain references
                        if (tag.Name == "directory" && tag.Attributes["name"] == "references")
                        {
                            foreach (Sluggy.Utility.Tag itemTag in tag.Children)
                            {
                                if (itemTag.Attributes.ContainsKey("name"))
                                {
                                    string name = itemTag.Attributes["name"];
                                    if (name != this.Name && name != "domain")
                                    {
                                        this.AddDomainReference(name);
                                    }
                                }
                            }
                        }
                        #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(true);
        }