Static tiles uses HashSet to lookup entries. More nullchecks changed to use `is`.

master
Katie Durden 2023-03-01 17:20:44 -08:00
parent a88172c0cf
commit 541fd42133
1 changed files with 106 additions and 95 deletions

View File

@ -7,6 +7,8 @@ namespace stardew_access.Features
{
private JObject? staticTilesData = null;
private JObject? customTilesData = null;
HashSet<KeyValuePair<string, JToken?>>? staticTilesDataSet = null;
HashSet<KeyValuePair<string, JToken?>>? customTilesDataSet = null;
public StaticTiles()
{
@ -20,6 +22,10 @@ namespace stardew_access.Features
string json = file.ReadToEnd();
staticTilesData = JObject.Parse(json);
}
if (staticTilesData is not null)
{
staticTilesDataSet = new HashSet<KeyValuePair<string, JToken>>(staticTilesData);
}
MainClass.InfoLog($"Loaded static-tile.json");
}
@ -35,6 +41,10 @@ namespace stardew_access.Features
string json = file.ReadToEnd();
customTilesData = JObject.Parse(json);
}
if (customTilesData is not null)
{
customTilesDataSet = new HashSet<KeyValuePair<string, JToken>>(customTilesData);
}
MainClass.InfoLog($"Loaded custom-tile.json");
}
@ -77,13 +87,7 @@ namespace stardew_access.Features
return getStaticTileInfoAtWithCategory(x, y).name;
}
public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y) {
List<JObject> allData = new List<JObject>();
if (customTilesData != null) allData.Add(customTilesData);
if (staticTilesData != null) allData.Add(staticTilesData);
foreach (JObject data in allData) {
public (string? name, CATEGORY category) GetTileFromSet(int x, int y, HashSet<KeyValuePair<string, JToken>> data) {
foreach (KeyValuePair<string, JToken?> location in data)
{
string locationName = location.Key;
@ -184,7 +188,14 @@ namespace stardew_access.Features
}
}
}
return (null, CATEGORY.Others);
}
public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y) {
if (customTilesDataSet != null) return GetTileFromSet(x, y, customTilesDataSet);
if (staticTilesDataSet != null) return GetTileFromSet(x, y, staticTilesDataSet);
return (null, CATEGORY.Others);
}