From b7d6414f65773db52d610d9370ccd6f9dede4106 Mon Sep 17 00:00:00 2001 From: Chase Warrington Date: Sat, 29 Oct 2022 20:52:59 -0400 Subject: [PATCH] Fixes --- CustomNPCFixes/Mod.cs | 17 ++++++++++++++++- CustomNPCFixes/manifest.json | 2 +- GenericModConfigMenu/Mod.cs | 17 ++++++++++++++--- GenericModConfigMenu/manifest.json | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CustomNPCFixes/Mod.cs b/CustomNPCFixes/Mod.cs index 6eaddc3fe..db94c4a6f 100644 --- a/CustomNPCFixes/Mod.cs +++ b/CustomNPCFixes/Mod.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -46,13 +47,27 @@ public void DoNpcFixes(object sender, EventArgs args) this.FixSchedules(); } + class NpcEqualityChecker : IEqualityComparer + { + public bool Equals(NPC x, NPC y) + { + return x.Name == y.Name; + } + + public int GetHashCode([DisallowNull] NPC obj) + { + return obj.Name.GetHashCode(); + } + } + private void SpawnNpcs() { List allCharacters = Utility.getPooledList(); try { Utility.getAllCharacters(allCharacters); - var chars = allCharacters.Where(c => c.isVillager()).ToDictionary((a) => a.Name, a => a); + + var chars = allCharacters.Where(c => c.isVillager()).Distinct( new NpcEqualityChecker() ).ToDictionary((a) => a.Name, a => a); var dispos = Game1.content.Load>("Data\\NPCDispositions"); foreach (var (name, dispo) in dispos) diff --git a/CustomNPCFixes/manifest.json b/CustomNPCFixes/manifest.json index 03587765d..5892c9db6 100644 --- a/CustomNPCFixes/manifest.json +++ b/CustomNPCFixes/manifest.json @@ -1,7 +1,7 @@ { "Name": "Custom NPC Fixes", "Author": "spacechase0", - "Version": "1.2.5", + "Version": "1.2.6", "MinimumApiVersion": "3.13.0", "Description": "Fixes NPC spawning in custom locations, pathing to custom locations, and schedules for new NPCs.", "UniqueID": "spacechase0.CustomNPCFixes", diff --git a/GenericModConfigMenu/Mod.cs b/GenericModConfigMenu/Mod.cs index b2c06f5f8..7a9f2c267 100644 --- a/GenericModConfigMenu/Mod.cs +++ b/GenericModConfigMenu/Mod.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using GenericModConfigMenu.Framework; using Microsoft.Xna.Framework; @@ -82,13 +83,22 @@ public override void Entry(IModHelper helper) /// public override object GetApi(IModInfo mod) { - return new Api(mod.Manifest, this.ConfigManager, mod => this.OpenModMenu(mod, page: null, listScrollRow: null), Log.Info); + return new Api(mod.Manifest, this.ConfigManager, mod => this.OpenModMenu(mod, page: null, listScrollRow: null), (s) => LogDeprecated( mod.Manifest.UniqueID, s)); } /********* ** Private methods *********/ + private static HashSet DidDeprecationWarningsFor = new(); + private void LogDeprecated(string modid, string str) + { + if (DidDeprecationWarningsFor.Contains(modid)) + return; + DidDeprecationWarningsFor.Add(modid); + Log.Info(str); + } + /// Open the menu which shows a list of configurable mods. /// The initial scroll position, represented by the row index at the top of the visible area. private void OpenListMenu(int? scrollRow = null) @@ -161,7 +171,7 @@ private void OnGameLaunched(object sender, GameLaunchedEventArgs e) // the texture. this.Helper.Events.GameLoop.UpdateTicking += this.FiveTicksAfterGameLaunched; - Api configMenu = new Api(ModManifest, this.ConfigManager, mod => this.OpenModMenu(mod, page: null, listScrollRow: null), Log.Info); + Api configMenu = new Api(ModManifest, this.ConfigManager, mod => this.OpenModMenu(mod, page: null, listScrollRow: null), (s) => LogDeprecated( ModManifest.UniqueID, s)); configMenu.Register( mod: this.ModManifest, @@ -213,7 +223,8 @@ private void OnUpdateTicking(object sender, UpdateTickingEventArgs e) /// The event arguments. private void OnWindowResized(object sender, WindowResizedEventArgs e) { - this.ConfigButton.LocalPosition = new Vector2(this.ConfigButton.Position.X, Game1.viewport.Height - 100); + if ( this.ConfigButton != null ) + this.ConfigButton.LocalPosition = new Vector2(this.ConfigButton.Position.X, Game1.viewport.Height - 100); } /// diff --git a/GenericModConfigMenu/manifest.json b/GenericModConfigMenu/manifest.json index 53860675e..121e74230 100644 --- a/GenericModConfigMenu/manifest.json +++ b/GenericModConfigMenu/manifest.json @@ -1,7 +1,7 @@ { "Name": "Generic Mod Config Menu", "Author": "spacechase0", - "Version": "1.9.4", + "Version": "1.9.6", "MinimumApiVersion": "3.17.0", "Description": "Adds an in-game UI to edit other mods' config options (for mods which support it).", "UniqueID": "spacechase0.GenericModConfigMenu",