Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spacechase0 committed Oct 30, 2022
1 parent 8c8199f commit b7d6414
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
17 changes: 16 additions & 1 deletion CustomNPCFixes/Mod.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -46,13 +47,27 @@ public void DoNpcFixes(object sender, EventArgs args)
this.FixSchedules();
}

class NpcEqualityChecker : IEqualityComparer<NPC>
{
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<NPC> 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<Dictionary<string, string>>("Data\\NPCDispositions");

foreach (var (name, dispo) in dispos)
Expand Down
2 changes: 1 addition & 1 deletion CustomNPCFixes/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 14 additions & 3 deletions GenericModConfigMenu/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using GenericModConfigMenu.Framework;

using Microsoft.Xna.Framework;
Expand Down Expand Up @@ -82,13 +83,22 @@ public override void Entry(IModHelper helper)
/// <inheritdoc />
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<string> DidDeprecationWarningsFor = new();
private void LogDeprecated(string modid, string str)
{
if (DidDeprecationWarningsFor.Contains(modid))
return;
DidDeprecationWarningsFor.Add(modid);
Log.Info(str);
}

/// <summary>Open the menu which shows a list of configurable mods.</summary>
/// <param name="scrollRow">The initial scroll position, represented by the row index at the top of the visible area.</param>
private void OpenListMenu(int? scrollRow = null)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -213,7 +223,8 @@ private void OnUpdateTicking(object sender, UpdateTickingEventArgs e)
/// <param name="e">The event arguments.</param>
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);
}

/// <inheritdoc cref="IDisplayEvents.Rendered"/>
Expand Down
2 changes: 1 addition & 1 deletion GenericModConfigMenu/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit b7d6414

Please sign in to comment.