Beispiel #1
0
        private void loadPacks()
        {
            int countPacks   = 0;
            int countObjects = 0;

            string[] files = parseDir(Path.Combine(Helper.DirectoryPath, "Furniture"), "*.json");

            countPacks = files.Length;

            foreach (string file in files)
            {
                CustomFurniturePack pack = Helper.ReadJsonFile <CustomFurniturePack>(file);
                string author            = pack.author == "none" ? "" : " by " + pack.author;
                Monitor.Log(pack.name + " " + pack.version + author, LogLevel.Info);
                foreach (CustomFurnitureData data in pack.furniture)
                {
                    countObjects++;
                    data.folderName = Path.GetDirectoryName(file);
                    string pileID   = new DirectoryInfo(data.folderName).Name + "." + new FileInfo(file).Name + "." + data.id;
                    string objectID = pileID;
                    CustomFurnitureMod.log("Load:" + objectID);
                    CustomFurniture f = new CustomFurniture(data, objectID, Vector2.Zero);
                    furniturePile.Add(pileID, f);
                    furniture.Add(objectID, f);
                }
            }

            Monitor.Log(countPacks + " Content Packs with " + countObjects + " Objects found.");
        }
        public void rebuild(Dictionary <string, string> additionalSaveData, object replacement)
        {
            if (replacement is Furniture f)
            {
                string id = additionalSaveData["id"];
                CustomFurnitureMod.log("Rebuild:" + id);
                if (!CustomFurnitureMod.furniture.ContainsKey(id))
                {
                    id = new List <string>(CustomFurnitureMod.furniture.Keys).Find(k => id.Contains(Path.Combine("Furniture", k)));
                }
                if (id == null || !CustomFurnitureMod.furniture.ContainsKey(id))
                {
                    id = CustomFurnitureMod.furniture.Keys.First <string>();
                }

                build(CustomFurnitureMod.furniture[id].data, id, f.TileLocation);

                rotations.Value       = additionalSaveData.ContainsKey("rotations") ? int.Parse(additionalSaveData["rotations"]) : (replacement as Furniture).rotations.Value;
                currentRotation.Value = additionalSaveData.ContainsKey("rotation") ? int.Parse(additionalSaveData["rotation"]) : (replacement as Furniture).currentRotation.Value;
                fRotation             = (FurnitureRotation)currentRotation.Value;
                tileLocation.Value    = (replacement as Furniture).TileLocation;

                rotate();
                rotate();
                rotate();
                rotate();

                if (f.heldObject.Value != null)
                {
                    this.heldObject.Value = f.heldObject.Value;
                }
            }
        }
        private void loadPacks()
        {
            int countPacks   = 0;
            int countObjects = 0;

            var contentPacks = Helper.ContentPacks.GetOwned();

            foreach (IContentPack cpack in contentPacks)
            {
                string[] cfiles = parseDir(cpack.DirectoryPath, "*.json");

                countPacks += (cfiles.Length - 1);

                foreach (string file in cfiles)
                {
                    if (file.ToLower().Contains("manifest.json"))
                    {
                        continue;
                    }

                    CustomFurniturePack pack = cpack.ReadJsonFile <CustomFurniturePack>(Path.GetFileName(file));

                    pack.author  = cpack.Manifest.Author;
                    pack.version = cpack.Manifest.Version.ToString();
                    string author = pack.author == "none" ? "" : " by " + pack.author;
                    Monitor.Log(pack.name + " " + pack.version + author, LogLevel.Info);
                    foreach (CustomFurnitureData data in pack.furniture)
                    {
                        countObjects++;
                        data.folderName = pack.useid == "none" ? cpack.Manifest.UniqueID : pack.useid;
                        string pileID   = data.folderName + "." + Path.GetFileName(file) + "." + data.id;
                        string objectID = pileID;
                        CustomFurnitureMod.log("Load:" + objectID);
                        string tkey = $"{data.folderName}/{ data.texture}";
                        if (!CustomFurniture.Textures.ContainsKey(tkey))
                        {
                            CustomFurniture.Textures.Add(tkey, cpack.LoadAsset <Texture2D>(data.texture));
                        }
                        CustomFurniture f = new CustomFurniture(data, objectID, Vector2.Zero);
                        furniturePile.Add(pileID, f);
                        furniture.Add(objectID, f);
                    }
                }
            }

            Monitor.Log(countPacks + " Content Packs with " + countObjects + " Objects found.", LogLevel.Trace);
        }
        private void loadPacks()
        {
            int countPacks   = 0;
            int countObjects = 0;

            var contentPacks = Helper.ContentPacks.GetOwned();

            foreach (IContentPack cpack in contentPacks)
            {
                string[] cfiles = parseDir(cpack.DirectoryPath, "*.json");

                countPacks += (cfiles.Length - 1);

                foreach (string file in cfiles)
                {
                    if (file.ToLower().Contains("manifest.json") || file.ToLower().EndsWith("pytk.json"))
                    {
                        continue;
                    }

                    CustomFurniturePack pack = cpack.ReadJsonFile <CustomFurniturePack>(Path.GetFileName(file));

                    pack.author  = cpack.Manifest.Author;
                    pack.version = cpack.Manifest.Version.ToString();
                    string author = pack.author == "none" ? "" : " by " + pack.author;
                    Monitor.Log(pack.name + " " + pack.version + author, LogLevel.Info);
                    if (!furnitureByContentPack.ContainsKey(cpack.Manifest))
                    {
                        furnitureByContentPack.Add(cpack.Manifest, new List <string>());
                    }
                    foreach (CustomFurnitureData data in pack.furniture)
                    {
                        countObjects++;
                        data.folderName = pack.useid == "none" ? cpack.Manifest.UniqueID : pack.useid;
                        string pileID   = data.folderName + "." + Path.GetFileName(file) + "." + data.id;
                        string objectID = pileID;
                        CustomFurnitureMod.log("Load:" + objectID);
                        string tkey = $"{data.folderName}/{ data.texture}";
                        if (data.textureOverlay != null)
                        {
                            string tkey2 = $"{data.folderName}/{ data.textureOverlay}";
                            if (!CustomFurniture.Textures.ContainsKey(tkey2))
                            {
                                CustomFurniture.Textures.Add(tkey2, data.fromContent ? data.textureOverlay : cpack.GetActualAssetKey(data.textureOverlay));
                            }
                        }

                        if (data.textureUnderlay != null)
                        {
                            string tkey3 = $"{data.folderName}/{ data.textureUnderlay}";
                            if (!CustomFurniture.Textures.ContainsKey(tkey3))
                            {
                                CustomFurniture.Textures.Add(tkey3, data.fromContent ? data.textureUnderlay : cpack.GetActualAssetKey(data.textureUnderlay));
                            }
                        }

                        if (!CustomFurniture.Textures.ContainsKey(tkey))
                        {
                            CustomFurniture.Textures.Add(tkey, data.fromContent ? data.texture : cpack.GetActualAssetKey(data.texture));
                        }
                        CustomFurniture f = new CustomFurniture(data, objectID, Vector2.Zero);
                        furniturePile.AddOrReplace(pileID, f);
                        furniture.AddOrReplace(objectID, f);
                        furnitureByContentPack[cpack.Manifest].Add(f.name);
                    }
                }
            }

            Monitor.Log(countPacks + " Content Packs with " + countObjects + " Objects found.", LogLevel.Trace);
        }
        private void loadPacks()
        {
            int countPacks   = 0;
            int countObjects = 0;

            var contentPacks = Helper.GetContentPacks();
            var usedids      = new List <string>();

            foreach (IContentPack cpack in contentPacks)
            {
                string[] cfiles = parseDir(cpack.DirectoryPath, "*.json");

                countPacks += (cfiles.Length - 1);

                foreach (string file in cfiles)
                {
                    if (file.ToLower().Contains("manifest.json"))
                    {
                        continue;
                    }

                    CustomFurniturePack pack = cpack.ReadJsonFile <CustomFurniturePack>(new FileInfo(file).Name);

                    if (pack.useid != "none")
                    {
                        usedids.AddOrReplace(pack.useid);
                    }

                    pack.author  = cpack.Manifest.Author;
                    pack.version = cpack.Manifest.Version.ToString();
                    string author = pack.author == "none" ? "" : " by " + pack.author;
                    Monitor.Log(pack.name + " " + pack.version + author, LogLevel.Info);
                    foreach (CustomFurnitureData data in pack.furniture)
                    {
                        countObjects++;
                        data.folderName = pack.useid == "none" ? cpack.Manifest.UniqueID : pack.useid;
                        string pileID   = data.folderName + "." + new FileInfo(file).Name + "." + data.id;
                        string objectID = pileID;
                        CustomFurnitureMod.log("Load:" + objectID);
                        string tkey = $"{data.folderName}/{ data.texture}";
                        if (!CustomFurniture.Textures.ContainsKey(tkey))
                        {
                            CustomFurniture.Textures.Add(tkey, cpack.LoadAsset <Texture2D>(data.texture));
                        }
                        CustomFurniture f = new CustomFurniture(data, objectID, Vector2.Zero);
                        furniturePile.Add(pileID, f);
                        furniture.Add(objectID, f);
                    }
                }
            }

            string[] files = parseDir(Path.Combine(Helper.DirectoryPath, "Furniture"), "*.json");

            countPacks += files.Length;

            foreach (string file in files)
            {
                CustomFurniturePack pack = Helper.ReadJsonFile <CustomFurniturePack>(file);

                string packid = new DirectoryInfo(Path.GetDirectoryName(file)).Name;

                if (usedids.Contains(packid))
                {
                    continue;
                }

                countPacks++;

                string author = pack.author == "none" ? "" : " by " + pack.author;
                Monitor.Log(pack.name + " " + pack.version + author, LogLevel.Info);
                foreach (CustomFurnitureData data in pack.furniture)
                {
                    countObjects++;
                    data.folderName = Path.GetDirectoryName(file);
                    string pileID   = new DirectoryInfo(data.folderName).Name + "." + new FileInfo(file).Name + "." + data.id;
                    string objectID = pileID;
                    CustomFurnitureMod.log("Load:" + objectID);
                    string tkey = $"{new DirectoryInfo(data.folderName).Name}/{ data.texture}";
                    if (!CustomFurniture.Textures.ContainsKey(tkey))
                    {
                        CustomFurniture.Textures.Add(tkey, Helper.Content.Load <Texture2D>($"Furniture/{new DirectoryInfo(data.folderName).Name}/{data.texture}"));
                    }
                    CustomFurniture f = new CustomFurniture(data, objectID, Vector2.Zero);
                    furniturePile.Add(pileID, f);
                    furniture.Add(objectID, f);
                }
            }



            Monitor.Log(countPacks + " Content Packs with " + countObjects + " Objects found.");
        }