internal static ModCraftTreeRoot CreateCustomCraftTreeAndType(string name, out CraftTree.Type craftTreeType)
        {
            EnumTypeCache cache = cacheManager.GetCacheForTypeName(name);

            if (cache == null)
            {
                cache = new EnumTypeCache()
                {
                    Name  = name,
                    Index = cacheManager.GetNextFreeIndex()
                };
            }

            if (cacheManager.IsIndexValid(cache.Index))
            {
                cache.Index = cacheManager.GetNextFreeIndex();
            }

            craftTreeType = (CraftTree.Type)cache.Index;

            cacheManager.Add(craftTreeType, cache);

            cacheManager.SaveCache();

            Logger.Log($"Successfully added CraftTree Type: '{name}' to Index: '{cache.Index}'", LogLevel.Debug);

            var customTreeRoot = new ModCraftTreeRoot(craftTreeType, name);

            CraftTreePatcher.CustomTrees[craftTreeType] = customTreeRoot;

            return(customTreeRoot);
        }
Example #2
0
        internal static TechType AddTechType(string name)
        {
            EnumTypeCache cache = cacheManager.GetCacheForTypeName(name);

            if (cache == null)
            {
                cache = new EnumTypeCache()
                {
                    Name  = name,
                    Index = cacheManager.GetNextFreeIndex()
                };
            }

            if (cacheManager.IsIndexValid(cache.Index))
            {
                cache.Index = cacheManager.GetNextFreeIndex();
            }

            var techType = (TechType)cache.Index;

            cacheManager.Add(techType, cache);

            // Direct access to private fields made possible by https://github.com/CabbageCrow/AssemblyPublicizer/
            // See README.md for details.
            TechTypeExtensions.stringsNormal[techType]    = name;
            TechTypeExtensions.stringsLowercase[techType] = name.ToLowerInvariant();
            TechTypeExtensions.techTypesNormal[name]      = techType;
            TechTypeExtensions.techTypesIgnoreCase[name]  = techType;

            string intKey = cache.Index.ToString();

            TechTypeExtensions.techTypeKeys[techType] = intKey;
            TechTypeExtensions.keyTechTypes[intKey]   = techType;

            cacheManager.SaveCache();

            Logger.Log($"Successfully added Tech Type: '{name}' to Index: '{cache.Index}'", LogLevel.Debug);
            return(techType);
        }