Exemple #1
0
        public static void InitBlocks()
        {
            foreach (string letter in letters)
            {
                JSONNode colornode = ConfigManager.GetConfigNode(Entry.ModName, letter + ".colours");
                if (colornode != null && colornode.ChildCount != 0)
                {
                    foreach (var item in colornode.LoopArray())
                    {
                        string colour = item.GetAs <string>();

                        #region Unlit

                        BaseItem baseItem = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.Base, false);
                        ItemTypesServer.QueueItemTypePatch(baseItem.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItem.Register(), 1000000);

                        BaseItem baseItemxminus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.XMinus, false);
                        ItemTypesServer.QueueItemTypePatch(baseItemxminus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemxminus.Register(), 1000000);

                        BaseItem baseItemxplus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.XPlus, false);
                        ItemTypesServer.QueueItemTypePatch(baseItemxplus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemxplus.Register(), 1000000);

                        BaseItem baseItemzminus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.ZMinus, false);
                        ItemTypesServer.QueueItemTypePatch(baseItemzminus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemzminus.Register(), 1000000);

                        BaseItem baseItemzplus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.ZPlus, false);
                        ItemTypesServer.QueueItemTypePatch(baseItemzplus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemzplus.Register(), 1000000);

                        #endregion Unlit

                        #region lit

                        BaseItem baseItemLit = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.Base, true);
                        ItemTypesServer.QueueItemTypePatch(baseItemLit.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemLit.Register(), 1000000);

                        BaseItem baseItemLitxminus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.XMinus, true);
                        ItemTypesServer.QueueItemTypePatch(baseItemLitxminus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemLitxminus.Register(), 1000000);

                        BaseItem baseItemLitxplus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.XPlus, true);
                        ItemTypesServer.QueueItemTypePatch(baseItemLitxplus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemLitxplus.Register(), 1000000);

                        BaseItem baseItemLitzminus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.ZMinus, true);
                        ItemTypesServer.QueueItemTypePatch(baseItemLitzminus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemLitzminus.Register(), 1000000);

                        BaseItem baseItemLitzplus = new BaseItem(letter + colour, letter, colour, BaseItem.Rotation.ZPlus, true);
                        ItemTypesServer.QueueItemTypePatch(baseItemLitzplus.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, baseItemLitzplus.Register(), 1000000);

                        #endregion lit
                    }
                }
            }
        }
Exemple #2
0
#pragma warning disable IDE0060 // Remove unused parameter
        internal static void AutoDiscoverType(Dictionary <string, ItemTypesServer.ItemTypeRaw> dict)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            int typecount = 0;

            foreach (string modname in Mods.ModManager.GetMods().Keys)
            {
                Mods.Mod mod      = Mods.ModManager.GetMod(modname);
                Assembly assembly = Mods.ModManager.GetAssembly(mod.ModName);
                var      typelist = assembly.GetTypes()
                                    .Where(t => (t.IsClass && t.IsDefined(typeof(NCAPIType), true)));

                foreach (var type in typelist)
                {
                    try
                    {
                        BaseType @base    = ((BaseType)Activator.CreateInstance(type));
                        JSONNode typenode = @base.Register();
                        if (@base.OverrideReplace)
                        {
                            ItemTypesServer.QueueItemTypePatch(@base.TypeName, ItemTypesServer.EItemTypePatchType.OverrideTypeProperties, typenode, typecount);
                        }
                        else
                        {
                            ItemTypesServer.QueueItemTypePatch(@base.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, typenode, typecount);
                        }
                        typecount++;
                    }
                    catch (MissingFieldException mfe)
                    {
                        Helpers.Logging.WriteLog(mod.ModName, type.Name + " cannot be instantiated.  This probably is not an error. " + mfe.Message + " |||| " + mfe.StackTrace, Helpers.Logging.LogType.Issue, true);
                    }
                    catch (InvalidCastException ice)
                    {
                        Helpers.Logging.WriteLog(mod.ModName, type.Name + " does not properly implement our Type System. This probably is not an error. " + ice.Message + " |||| " + ice.StackTrace, Helpers.Logging.LogType.Issue, true);
                    }
                    catch (Exception e)
                    {
                        Helpers.Logging.WriteLog(mod.ModName, type.Name + " Type Error: " + e.Message + "\n" + e.StackTrace + "\n\n" + e.InnerException.Message + "\n" + e.InnerException.StackTrace, Helpers.Logging.LogType.Issue, true);
                    }
                }

                string[] directories = Directory.GetDirectories(mod.ModFolder, "*", SearchOption.AllDirectories);
                foreach (string dir in directories)
                {
                    if (dir.EndsWith("typesadd"))
                    {
                        string[] files = Directory.GetFiles(dir, "*.json", SearchOption.AllDirectories);
                        foreach (string file in files)
                        {
                            ItemTypesServer.QueueItemTypePatches(file, ItemTypesServer.EItemTypePatchType.AddNewTypes, 1);
                        }
                    }
                    if (dir.EndsWith("typesreplace"))
                    {
                        string[] files = Directory.GetFiles(dir, "*.json", SearchOption.AllDirectories);
                        foreach (string file in files)
                        {
                            ItemTypesServer.QueueItemTypePatches(file, ItemTypesServer.EItemTypePatchType.OverrideTypeProperties, 1);
                        }
                    }
                }

                if (Power.PowerManager.IsEnabled())
                {
                    var powerlist = assembly.GetTypes()
                                    .Where(t => (t.IsClass && t.IsDefined(typeof(Power.PowerManager.NCAPIPowerType), true)));
                    foreach (var power in powerlist)
                    {
                        try
                        {
                            BaseType baseType = ((BaseType)Activator.CreateInstance(power));
                            JSONNode typenode = baseType.Register();
                            if (baseType.OverrideReplace)
                            {
                                ItemTypesServer.QueueItemTypePatch(baseType.TypeName, ItemTypesServer.EItemTypePatchType.OverrideTypeProperties, typenode, typecount);
                            }
                            else
                            {
                                ItemTypesServer.QueueItemTypePatch(baseType.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, typenode, typecount);
                            }
                        }
                        catch (MissingFieldException mfe)
                        {
                            Helpers.Logging.WriteLog(mod.ModName, power.Name + " cannot be instantiated.  This probably is not an error. " + mfe.Message + " |||| " + mfe.StackTrace, Helpers.Logging.LogType.Issue, true);
                        }
                        catch (InvalidCastException ice)
                        {
                            Helpers.Logging.WriteLog(mod.ModName, power.Name + " does not properly implement our Power Type System. This probably is not an error. " + ice.Message + " |||| " + ice.StackTrace, Helpers.Logging.LogType.Issue, true);
                        }
                        catch (Exception e)
                        {
                            Helpers.Logging.WriteLog(mod.ModName, power.Name + "Power Type Error: " + e.Message + "\n" + e.StackTrace + "\n\n" + e.InnerException.Message + "\n" + e.InnerException.StackTrace, Helpers.Logging.LogType.Issue, true);
                        }
                    }
                }
            }
            Helpers.Logging.WriteLog(NewColonyAPIEntry.ModName, string.Format("Autoloaded {0} blocks/types", typecount), Helpers.Logging.LogType.Loading);
        }