Skip to content

Commit

Permalink
- Add some exceptions to item indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
agilbert1412 committed Apr 28, 2024
1 parent e9d11dc commit 2401fea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class IslandNorthInjections : IParrotReplacer
{
private const string AP_BRIDGE_PARROT = "Dig Site Bridge";
private const string AP_TRADER_PARROT = "Island Trader";
private const string AP_PROF_SNAIL_CAVE = "Open Professor Snail Cave";
public const string AP_PROF_SNAIL_CAVE = "Open Professor Snail Cave";

private static IMonitor _monitor;
private static IModHelper _modHelper;
Expand Down
35 changes: 30 additions & 5 deletions StardewArchipelago/Locations/LocationNameMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using StardewArchipelago.Locations.Festival;
using StardewArchipelago.Locations.GingerIsland.Parrots;

namespace StardewArchipelago.Locations
{
public class LocationNameMatcher
{
private Dictionary<string, string[]> _wordFilterCache;

private static readonly Dictionary<string, string[]> _exceptions = new()
{
{ "Snail", new[] { IslandNorthInjections.AP_PROF_SNAIL_CAVE } },
{
"Stone",
new[]
{
FestivalLocationNames.STRENGTH_GAME, "Lemon Stone",
"Ocean Stone", "Fairy Stone", "Swirl Stone"
}
},
{ "Trash", new[] { "Trash Can Upgrade" } },
{ "Hardwood", new[] { "Hardwood Display" } },
};

public LocationNameMatcher()
{
_wordFilterCache = new Dictionary<string, string[]>();
Expand All @@ -30,12 +47,20 @@ public string[] GetAllLocationsContainingWord(IEnumerable<string> allLocations,
return _wordFilterCache[wordFilter];
}

var filteredLocations = FilterForWord(GetAllLocationsMatching(allLocations, wordFilter), wordFilter).ToArray();

var filteredLocations = FilterForWord(GetAllLocationsMatching(allLocations, wordFilter), wordFilter);

if (_exceptions.ContainsKey(wordFilter))
{
foreach (var exceptionName in _exceptions[wordFilter])
{
filteredLocations = filteredLocations.Where(x =>
!x.Contains(exceptionName, StringComparison.InvariantCultureIgnoreCase));
}
}


_wordFilterCache.Add(wordFilter, filteredLocations);
return filteredLocations;
var filteredArray = filteredLocations.ToArray();
_wordFilterCache.Add(wordFilter, filteredArray);
return filteredArray;
}

public bool IsAnyLocationMatching(IEnumerable<string> allLocations, string filter)
Expand Down
2 changes: 1 addition & 1 deletion StardewArchipelagoTests/LocationNameMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void GetAllLocationsContainingWordTruePositivesTest(string itemName, stri

[TestCase("Snail", new[] { "Open Professor Snail Cave" }, TestName = "Professor Snail Cave")]
[TestCase("Stone", new[] { "Shipsanity: Swirl Stone", "Smashing Stone" }, TestName = "Swirl Stone")]
[TestCase("Hardwood", new[] { "Shipsanity: Hardwood Display: Amphibian Fossil", "Shipsanity: Wooden Display: Dinosaur Egg", "Craft Hardwood Preservation Chamber", "Craft Hardwood Display", "Shipsanity: Hardwood Fence" }, TestName = "Hardwood Displays")]
[TestCase("Hardwood", new[] { "Shipsanity: Hardwood Display: Amphibian Fossil" }, TestName = "Hardwood Displays")]
public void GetAllLocationsContainingWordFalsePositivesTest(string itemName, string[] locationsNotMatching)
{
// Arrange
Expand Down

0 comments on commit 2401fea

Please sign in to comment.