예제 #1
0
        //! Load an inventory.
        public utils.Tuple<InventoryItem, InventoryItemRef> load(string Name)
        {
            // Not loaded yet
            if (!items.ContainsKey(Name))
            {
                XmlReader xml = XmlReader.Create(new StringReader(((TextAsset)Resources.Load(wrkPath + "/" + Name, typeof(TextAsset))).text));
                // Parse file
                xml.Read();
                // Root node
                xml.MoveToContent();
                // Get all attributes
                byte inventory_class_int = (byte)Convert.ToUInt16(xml.GetAttribute("inventory_class"));
                var inventory_class = (InventoryItemClass)(inventory_class_int == 0 ? 0 : 1 << inventory_class_int);
                sbyte size = (sbyte)Convert.ToUInt16(xml.GetAttribute("size"));
                uint weight = Convert.ToUInt32(xml.GetAttribute("weight"));
                string name = xml.GetAttribute("name");
                // Get the reference to item object
                xml.ReadToDescendant("ref");
                var item_ref = new InventoryItemRef(xml.GetAttribute("type"), xml.GetAttribute("src"));
                // Add new item
                items[Name] = new utils.Tuple<InventoryItem, InventoryItemRef>(new InventoryItem(inventory_class, size, weight, name), item_ref);
            }

            return items[Name];
        }
예제 #2
0
        //! Load an inventory.
        public utils.Tuple <InventoryItem, InventoryItemRef> load(string Name)
        {
            // Not loaded yet
            if (!items.ContainsKey(Name))
            {
                XmlReader xml = XmlReader.Create(new StringReader(((TextAsset)Resources.Load(wrkPath + "/" + Name, typeof(TextAsset))).text));
                // Parse file
                xml.Read();
                // Root node
                xml.MoveToContent();
                // Get all attributes
                byte   inventory_class_int = (byte)Convert.ToUInt16(xml.GetAttribute("inventory_class"));
                var    inventory_class     = (InventoryItemClass)(inventory_class_int == 0 ? 0 : 1 << inventory_class_int);
                sbyte  size   = (sbyte)Convert.ToUInt16(xml.GetAttribute("size"));
                uint   weight = Convert.ToUInt32(xml.GetAttribute("weight"));
                string name   = xml.GetAttribute("name");
                // Get the reference to item object
                xml.ReadToDescendant("ref");
                var item_ref = new InventoryItemRef(xml.GetAttribute("type"), xml.GetAttribute("src"));
                // Add new item
                items[Name] = new utils.Tuple <InventoryItem, InventoryItemRef>(new InventoryItem(inventory_class, size, weight, name), item_ref);
            }

            return(items[Name]);
        }