Ejemplo n.º 1
0
        public ItemStorage(string itemFile)
        {
            string[] parts = Path.GetFileNameWithoutExtension(itemFile).Split('_');

            guid = parts[parts.Length - 1];
            string itemId       = string.Join("_", parts.Take(parts.Length - 1));
            string templateFile = Path.Combine(BepInExPlugin.templatesPath, itemId + ".json");

            BepInExPlugin.Dbgl($"Loading item storage {itemId} {guid}");

            if (File.Exists(templateFile))
            {
                BepInExPlugin.Dbgl("Loading template data");
                meta = JsonUtility.FromJson <ItemStorageMeta>(File.ReadAllText(templateFile));
            }
            else
            {
                throw new Exception("Template not found");
            }

            inventory = new Inventory(meta.itemName, null, meta.width, meta.height);

            if (File.Exists(itemFile))
            {
                string   input = File.ReadAllText(itemFile);
                ZPackage pkg   = new ZPackage(input);
                inventory.Load(pkg);
                BepInExPlugin.Dbgl($"Loaded existing inventory with {inventory.NrOfItems()} items");
            }
        }
Ejemplo n.º 2
0
 public ItemStorage(ItemDrop.ItemData item, string oldGuid)
 {
     guid = oldGuid;
     meta = new ItemStorageMeta()
     {
         itemId   = item.m_dropPrefab.name,
         itemName = Localization.instance.Localize(item.m_shared.m_name)
     };
     inventory = new Inventory(meta.itemName, null, meta.width, meta.height);
     BepInExPlugin.Dbgl($"Created new item storage {meta.itemId} {oldGuid}");
 }
Ejemplo n.º 3
0
        private static void LoadDataFromDisk()
        {
            Dbgl("Loading item inventories");

            if (!Directory.Exists(templatesPath))
            {
                Directory.CreateDirectory(templatesPath);
            }
            if (!Directory.Exists(Path.Combine(itemsPath)))
            {
                Directory.CreateDirectory(itemsPath);
            }
            foreach (string itemFile in Directory.GetFiles(itemsPath))
            {
                try
                {
                    ItemStorage itemStorage = new ItemStorage(itemFile);
                    itemStorageDict[itemStorage.guid] = itemStorage;
                }
                catch (Exception ex)
                {
                    Dbgl($"Item file {itemFile} corrupt!\n{ex}");
                }
            }
            foreach (string templateFile in Directory.GetFiles(templatesPath))
            {
                try
                {
                    ItemStorageMeta meta = JsonUtility.FromJson <ItemStorageMeta>(File.ReadAllText(templateFile));
                    itemStorageMetaDict[Path.GetFileNameWithoutExtension(templateFile)] = meta;
                }
                catch (Exception ex)
                {
                    Dbgl($"Template file {templateFile} corrupt!\n{ex}");
                }
            }
        }