public override void Start(ICoreAPI api) { base.Start(api); api.RegisterItemClass("ProgCard", typeof(ItemProgCard)); api.RegisterItemClass("ItemDeployBot", typeof(ItemDeployBot)); api.RegisterEntityBehaviorClass("program", typeof(EntityBehaviorProgram)); api.RegisterEntity("EntityReprogLocust", typeof(EntityReprogLocust)); AiTaskRegistry.Register <AiTaskHarvest>("harvest"); AiTaskRegistry.Register <AiTaskSeekItem>("seekitem"); AiTaskRegistry.Register <AiTaskToChest>("tochest"); AiTaskRegistry.Register <AiTaskFromChest>("fromchest"); AiTaskRegistry.Register <AiTaskPlant>("plant"); AiTaskRegistry.Register <AiTaskSqueezeHoney>("squeezehoney"); AiTaskRegistry.Register <AiTaskMilk>("milk"); AiTaskRegistry.Register <AiTaskToBarrel>("tobarrel"); AiTaskRegistry.Register <AiTaskGetSeed>("getseed"); AiTaskRegistry.Register <AiTaskSeekItemAny>("seekanyitem"); AiTaskRegistry.Register <AiTaskGetFuel>("getfuel"); AiTaskRegistry.Register <AiTaskRefuel>("refuel"); AiTaskRegistry.Register <AiTaskRepair>("repair"); AiTaskRegistry.Register <AiTaskProgSeekEntity>("progseekentity"); AiTaskRegistry.Register <AiTaskProgMeleeAttack>("progmeleeattack"); AiTaskRegistry.Register <AiTaskQuarry>("quarry"); AiTaskRegistry.Register <AiTaskStayCloseToOwner>("stayclosetoowner"); AiTaskRegistry.Register <AiTaskPathBuilder>("pathbuilder"); AiTaskRegistry.Register <AiTaskToAltChest>("toaltchest"); AiTaskRegistry.Register <AiTaskProgRangedAttack>("prograngedattack"); AiTaskRegistry.Register <AiTaskForm>("form"); AiTaskRegistry.Register <AiTaskToPoint>("topoint"); AiTaskRegistry.Register <AiTaskGetItem>("getitem"); AiTaskRegistry.Register <AiTaskAnyFromChest>("anyfromchest"); AiTaskRegistry.Register <AiTaskGetTool>("gettool"); try { TemporalHackerConfig FromDisk; if ((FromDisk = api.LoadModConfig <TemporalHackerConfig>("TemporalHackerConfig.json")) == null) { api.StoreModConfig <TemporalHackerConfig>(TemporalHackerConfig.Loaded, "TemporalHackerConfig.json"); } else { TemporalHackerConfig.Loaded = FromDisk; } } catch { api.StoreModConfig <TemporalHackerConfig>(TemporalHackerConfig.Loaded, "TemporalHackerConfig.json"); } }
public static TModConfig LoadOrCreateConfig <TModConfig>(this ICoreAPI api, string filename, bool required) where TModConfig : ModConfigBase, new() { var modCode = filename.Split('.').First(); try { var loadedConfig = api.LoadModConfig <TModConfig>(filename); if (loadedConfig != null) { return(loadedConfig); } } catch (Exception e) { api.World.Logger.Error($"{modCode}: Failed loading modconfig file at 'ModConfig/{filename}', with an error of '{e}'! Stopping..."); return(null); } var message = $"{modCode}: non-existant modconfig at 'ModConfig/{filename}', creating default" + (required ? " and disabling mod..." : "..."); api.World.Logger.Notification(message); var newConfig = new TModConfig(); api.StoreModConfig(newConfig, filename); return(required ? null : newConfig); }
public static void SaveConfig <TModConfig>(this ICoreAPI api, TModConfig config) where TModConfig : ModConfigBase { var filename = config.ModCode; if (string.IsNullOrEmpty(filename)) { filename = ModConfigBase.GetModCode(config); } if (!filename.EndsWith(".json")) { filename += ".json"; } api.World.Logger.Notification($"Saving modconfig at 'ModConfig/{filename}'..."); api.StoreModConfig(config, filename); }
public void Save(ICoreAPI api, string filename = default) { if (string.IsNullOrEmpty(filename)) { filename = this.ModCode; } if (string.IsNullOrEmpty(filename)) { filename = ModConfigBase.GetModCode(this); } if (!filename.EndsWith(".json")) { filename += ".json"; } api.World.Logger.Notification($"Saving modconfig at 'ModConfig/{filename}'..."); api.StoreModConfig(this, filename); }
public static T LoadOrCreateConf <T>(this ICoreAPI serverApi, string filename) where T : new() { try { var loadedConf = serverApi.LoadModConfig <T>(filename); if (loadedConf != null) { return(loadedConf); } } catch (Exception e) { serverApi.Logger.Error($"Failed to loading config {filename} with error {e}. Initialize new..."); } var newConf = new T(); serverApi.StoreModConfig(newConf, filename); serverApi.Logger.Warning($"Created new {filename} config."); return(newConf); }
public override void Start(ICoreAPI api) { base.Start(api); this.api = api; api.Logger.StoryEvent("[Tailor] Hello world!"); // register network channel and message types api.Network.RegisterChannel("tailor") .RegisterMessageType(typeof(NetworkApiTailorRequest)) .RegisterMessageType(typeof(NetworkApiTailorResponse)) ; // load config file or write it with defaults config = api.LoadModConfig <ModConfig>("TailorConfig.json"); if (config == null) { config = new ModConfig(); api.StoreModConfig(config, "TailorConfig.json"); } api.RegisterItemClass("boneneedle", typeof(BoneNeedleItem)); }
public static TConfig LoadOrCreateConfig <TConfig>(this ICoreAPI api, string file, TConfig defaultConfig = null) where TConfig : class, new() { TConfig config = null; try { config = api.LoadModConfig <TConfig>(file); } catch (Exception e) { string format = "Failed loading config file ({0}), error {1}. Will initialize default config"; Core.ModLogger.Error(string.Format(format), file, e); } if (config == null) { Core.ModLogger.Notification("Will initialize default config"); config = defaultConfig ?? new TConfig(); } api.StoreModConfig(config, file); return(config); }
public static void Save(ICoreAPI api, ModConfig config) { api.StoreModConfig(config, filename); }
public override void Dispose() { api.StoreModConfig <Config>(Config.Current, ConstantsCore.ModId + ".json"); }
private void GenerateConfig(ICoreAPI api, MeteoricExpansionConfig previousConfig) { api.StoreModConfig <MeteoricExpansionConfig>(new MeteoricExpansionConfig(previousConfig), "MeteoricExpansionConfig.json"); }
private void GenerateConfig(ICoreAPI api) { api.StoreModConfig <MeteoricExpansionConfig>(new MeteoricExpansionConfig(), "MeteoricExpansionConfig.json"); }
private static void Save(ICoreAPI api, ModConfig config) { api.StoreModConfig(config, Filename); }