Пример #1
0
        internal static PingType AddPingType(string name, Sprite sprite)
        {
            var cache = cacheManager.RequestCacheForTypeName(name) ?? new EnumTypeCache()
            {
                Name  = name,
                Index = cacheManager.GetNextAvailableIndex()
            };

            if (cacheManager.IsIndexAvailable(cache.Index))
            {
                cache.Index = cacheManager.GetNextAvailableIndex();
            }

            var pingType = (PingType)cache.Index;

            cacheManager.Add(pingType, cache.Index, cache.Name);
            EnumPatcher.ClearCache(typeof(PingType));
            ModSprite.Add(SpriteManager.Group.Pings, pingType.ToString(), sprite);

            if (PingManager.sCachedPingTypeStrings.valueToString.ContainsKey(pingType) == false)
            {
                PingManager.sCachedPingTypeStrings.valueToString.Add(pingType, name);
            }

            if (PingManager.sCachedPingTypeTranslationStrings.valueToString.ContainsKey(pingType) == false)
            {
                PingManager.sCachedPingTypeTranslationStrings.valueToString.Add(pingType, name);
            }

            Logger.Log($"Successfully added PingType: '{name}' to Index: '{cache.Index}'", LogLevel.Debug);
            return(pingType);
        }
        internal static ModCraftTreeRoot CreateCustomCraftTreeAndType(string name, out CraftTree.Type craftTreeType)
        {
            EnumTypeCache cache = cacheManager.RequestCacheForTypeName(name);

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

            if (cacheManager.IsIndexAvailable(cache.Index))
            {
                cache.Index = cacheManager.GetNextAvailableIndex();
            }

            craftTreeType = (CraftTree.Type)cache.Index;

            cacheManager.Add(craftTreeType, cache.Index, cache.Name);
            EnumPatcher.ClearCache(typeof(CraftTree.Type));

            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);
        }
Пример #3
0
        internal static TechType AddTechType(string name)
        {
            EnumTypeCache cache = cacheManager.RequestCacheForTypeName(name);

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

            if (cacheManager.IsIndexAvailable(cache.Index))
            {
                cache.Index = cacheManager.GetNextAvailableIndex();
            }

            var techType = (TechType)cache.Index;

            cacheManager.Add(techType, cache.Index, cache.Name);
            EnumPatcher.ClearCache(typeof(TechType));

            // 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;

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