Added custom-tiles.json support

- users can add their own tiles in this file just asin static-tiles.json
- the file needs to be placed just where the static-tiles.json is
master
Mohammad Shoaib Khan 2022-10-27 20:05:12 +05:30
parent 1187ba30e7
commit b4560bc9e1
No known key found for this signature in database
GPG Key ID: 3EE32C9DFF520699
2 changed files with 123 additions and 88 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
*.dll
stardew-access/assets/custom-tiles.json
.vscode/*
.git-old/

View File

@ -5,26 +5,55 @@ namespace stardew_access.Features
{
public class StaticTiles
{
private JObject? data = null;
private JObject? staticTilesData = null;
private JObject? customTilesData = null;
public StaticTiles()
{
if (MainClass.ModHelper == null)
return;
try
{
using (StreamReader file = new StreamReader(Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "static-tiles.json")))
{
string json = file.ReadToEnd();
data = JObject.Parse(json);
staticTilesData = JObject.Parse(json);
}
MainClass.InfoLog($"Loaded static-tile.json");
}
catch (System.Exception)
{
MainClass.ErrorLog($"static-tiles.json file not found or an error occured while initializing static-tiles.json\nThe path of the file should be:\n\t{Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "static-tiles.json")}");
}
try
{
using (StreamReader file = new StreamReader(Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "custom-tiles.json")))
{
string json = file.ReadToEnd();
customTilesData = JObject.Parse(json);
}
MainClass.InfoLog($"Loaded custom-tile.json");
}
catch (System.Exception)
{
MainClass.ErrorLog($"custom-tiles.json file not found or an error occured while initializing custom-tiles.json\nThe path of the file should be:\n\t{Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "custom-tiles.json")}");
}
}
public bool isAvailable(string locationName)
{
if (data == null)
return false;
List<JObject> allData = new List<JObject>();
foreach (var location in data)
if (staticTilesData != null) allData.Add(staticTilesData);
if (customTilesData != null) allData.Add(customTilesData);
foreach (JObject data in allData)
{
foreach (KeyValuePair<string, JToken?> location in data)
{
if (location.Key.Contains("||") && MainClass.ModHelper != null)
{
@ -38,6 +67,7 @@ namespace stardew_access.Features
else if (locationName.ToLower().Equals(location.Key.ToLower()))
return true;
}
}
return false;
}
@ -49,10 +79,14 @@ namespace stardew_access.Features
public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y)
{
if (data == null)
return (null, CATEGORY.Others);
List<JObject> allData = new List<JObject>();
foreach (var location in data)
if (staticTilesData != null) allData.Add(staticTilesData);
if (customTilesData != null) allData.Add(customTilesData);
foreach (JObject data in allData)
{
foreach (KeyValuePair<string, JToken?> location in data)
{
if (location.Key.Contains("||") && MainClass.ModHelper != null)
{
@ -136,7 +170,7 @@ namespace stardew_access.Features
}
}
}
}
return (null, CATEGORY.Others);
}
}