Ejemplo n.º 1
0
        public static void Load()
        {
            var assembly = Assembly.GetExecutingAssembly();

            HarmonyInstance.Create($"MrPurple6411_{assembly.GetName().Name}").PatchAll(assembly);

            CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, "Posters", "Posters", SpriteManager.Get(TechType.PosterKitty));
            CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, "Landscape", "Landscape", SpriteManager.Get(TechType.PosterAurora), "Posters");
            CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, "Portrait", "Portrait", SpriteManager.Get(TechType.PosterExoSuit1), "Posters");
            foreach (string directory in Directory.GetDirectories(PosterFolder.FullName))
            {
                string info    = Path.Combine(directory, "info.json");
                string icon    = Path.Combine(directory, "icon.png");
                string texture = Path.Combine(directory, "texture.png");
                if (File.Exists(info) && File.Exists(icon) && File.Exists(texture))
                {
                    try
                    {
                        PosterInfo poster;
                        using (var reader = new StreamReader(info))
                        {
                            var serializer = new JsonSerializer();
                            poster = serializer.Deserialize(reader, typeof(PosterInfo)) as PosterInfo;
                        }

                        Texture2D icontexture   = ImageUtils.LoadTextureFromFile(icon);
                        Texture2D posterTexture = ImageUtils.LoadTextureFromFile(texture);

                        if (poster != null && icontexture != null && posterTexture != null)
                        {
                            var prefab = new BasicPostersPrefab(poster.InternalName, poster.DisplayName, poster.Description, poster.Orientation, icontexture, posterTexture);
                            prefab.Patch();
                            CraftDataHandler.SetQuickSlotType(prefab.TechType, QuickSlotType.Selectable);
                        }
                        else
                        {
                            Console.WriteLine($"[{ModName}] Unable to load Custom Poster from {Path.GetDirectoryName(directory)}!");
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine($"[{ModName}] Unable to load Custom Poster from {Path.GetDirectoryName(directory)}!");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static void CreateTabsAndLoadFiles()
        {
            CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, "Posters", "Posters", SpriteManager.Get(TechType.PosterKitty));
            CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, "Landscape", "Landscape", SpriteManager.Get(TechType.PosterAurora), "Posters");
            CraftTreeHandler.AddTabNode(CraftTree.Type.Fabricator, "Portrait", "Portrait", SpriteManager.Get(TechType.PosterExoSuit1), "Posters");

            foreach (var directory in Directory.GetDirectories(PosterFolder.FullName))
            {
                var info    = Path.Combine(directory, "info.json");
                var icon    = Path.Combine(directory, "icon.png");
                var texture = Path.Combine(directory, "texture.png");
                if (File.Exists(info) && File.Exists(icon) && File.Exists(texture))
                {
                    try
                    {
                        PosterInfo poster;
                        using (var reader = new StreamReader(info))
                        {
                            var serializer = new JsonSerializer();
                            poster = serializer.Deserialize(reader, typeof(PosterInfo)) as PosterInfo;
                        }

                        var iconTexture   = ImageUtils.LoadTextureFromFile(icon);
                        var posterTexture = ImageUtils.LoadTextureFromFile(texture);

                        if (poster != null && iconTexture != null && posterTexture != null)
                        {
                            var prefab = new BasicPostersPrefab(poster.InternalName, poster.DisplayName, poster.Description, poster.Orientation, iconTexture, posterTexture);
                            prefab.Patch();
                        }
                        else
                        {
                            Console.WriteLine($"[{ModName}] Unable to load Custom Poster from {Path.GetDirectoryName(directory)}!");
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine($"[{ModName}] Unable to load Custom Poster from {Path.GetDirectoryName(directory)}!");
                    }
                }
            }
        }