public static void Load(string directory) { NoData = new ConfigNPC { InternalName = "{Unknown NPC}", DisplayName = "{Unknown NPC}", IsFemale = false, Enabled = false, HomeSpots = false, BathSpots = false, OtherSpots = false }; var filepath = Path.Combine(directory, "assets", "npcs.json"); if (!File.Exists(filepath)) { Modworks.Log.Error($"NPCConfig file not found at {filepath}"); return; } try { var fileContents = File.ReadAllText(filepath); Data = JsonConvert.DeserializeObject <Dictionary <string, ConfigNPC> >(fileContents); Ready = true; Modworks.Log.Debug($"Loaded config from {filepath}, data has {Data.Count} NPCs"); } catch (Exception e) { Modworks.Log.Error("Failed to read config file: " + e.Message); } //set internal names foreach (var(key, configNpc) in Data) { configNpc.InternalName = key; //child safety - if any configured NPCs are children, we'll disable them here var n = Game1.getCharacterFromName(configNpc.InternalName); if (n == null) { continue; //if we can't read it, we'll let it pass. } if (IsChild(n)) { configNpc.Enabled = false; } } foreach (var cnpc in Data.Values) { if (cnpc.Enabled) { Modworks.Log.Trace("Personal Effects enabled for NPC " + cnpc.DisplayName); } } }
public static void Load(string directory) { NoData = new ConfigNPC { InternalName = "{Unknown NPC}", DisplayName = "{Unknown NPC}", IsFemale = false, Enabled = false, HomeSpots = false, BathSpots = false, OtherSpots = false }; string filepath = directory + "config.json"; if (File.Exists(filepath)) { try { string filecontents = File.ReadAllText(filepath); Data = JsonConvert.DeserializeObject <Dictionary <string, ConfigNPC> >(filecontents); ready = true; } catch (Exception e) { Modworks.Log.Error("Failed to read config file: " + e.Message); } //set internal names foreach (var kvp in Data) { kvp.Value.InternalName = kvp.Key; //child safety - if any configured NPCs are children, we'll disable them here var n = StardewValley.Game1.getCharacterFromName(kvp.Value.InternalName); if (n == null) { continue; //if we can't read it, we'll let it pass. } if (Modworks.NPCs.IsChild(n)) { kvp.Value.Enabled = false; } } foreach (ConfigNPC cnpc in Data.Values) { if (cnpc.Enabled) { Modworks.Log.Trace("Personal Effects enabled for NPC " + cnpc.DisplayName); } } } }