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 ismaster
parent
1187ba30e7
commit
b4560bc9e1
|
@ -4,6 +4,7 @@
|
||||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
*.dll
|
*.dll
|
||||||
|
stardew-access/assets/custom-tiles.json
|
||||||
|
|
||||||
.vscode/*
|
.vscode/*
|
||||||
.git-old/
|
.git-old/
|
||||||
|
|
|
@ -5,26 +5,55 @@ namespace stardew_access.Features
|
||||||
{
|
{
|
||||||
public class StaticTiles
|
public class StaticTiles
|
||||||
{
|
{
|
||||||
private JObject? data = null;
|
private JObject? staticTilesData = null;
|
||||||
|
private JObject? customTilesData = null;
|
||||||
|
|
||||||
public StaticTiles()
|
public StaticTiles()
|
||||||
{
|
{
|
||||||
if (MainClass.ModHelper == null)
|
if (MainClass.ModHelper == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
using (StreamReader file = new StreamReader(Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "static-tiles.json")))
|
using (StreamReader file = new StreamReader(Path.Combine(MainClass.ModHelper.DirectoryPath, "assets", "static-tiles.json")))
|
||||||
{
|
{
|
||||||
string json = file.ReadToEnd();
|
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)
|
public bool isAvailable(string locationName)
|
||||||
{
|
{
|
||||||
if (data == null)
|
List<JObject> allData = new List<JObject>();
|
||||||
return false;
|
|
||||||
|
|
||||||
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)
|
if (location.Key.Contains("||") && MainClass.ModHelper != null)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +67,7 @@ namespace stardew_access.Features
|
||||||
else if (locationName.ToLower().Equals(location.Key.ToLower()))
|
else if (locationName.ToLower().Equals(location.Key.ToLower()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -49,10 +79,14 @@ namespace stardew_access.Features
|
||||||
|
|
||||||
public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y)
|
public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y)
|
||||||
{
|
{
|
||||||
if (data == null)
|
List<JObject> allData = new List<JObject>();
|
||||||
return (null, CATEGORY.Others);
|
|
||||||
|
|
||||||
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)
|
if (location.Key.Contains("||") && MainClass.ModHelper != null)
|
||||||
{
|
{
|
||||||
|
@ -136,7 +170,7 @@ namespace stardew_access.Features
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (null, CATEGORY.Others);
|
return (null, CATEGORY.Others);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue