Fix documentation error and add log for future debuging

This commit is contained in:
Magnus 2024-08-04 13:32:15 -07:00
parent 446157acf4
commit a8c4641743
2 changed files with 6 additions and 4 deletions

View File

@ -143,9 +143,11 @@ namespace NewHorizons
public object QueryBody(Type outType, string bodyName, string jsonPath)
{
var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == bodyName);
return planet == null
? null
: QueryJson(outType, Path.Combine(planet.Mod.ModHelper.Manifest.ModFolderPath, planet.RelativePath), jsonPath);
if (planet == null){
NHLogger.LogError($"Could not find planet with body name {bodyName}.")
return null;
}
return QueryJson(outType, Path.Combine(planet.Mod.ModHelper.Manifest.ModFolderPath, planet.RelativePath), jsonPath);
}
public T QueryBody<T>(string bodyName, string jsonPath)

View File

@ -49,7 +49,7 @@ Then, use the `QueryBody` method:
var api = ModHelper.Interactions.TryGetModApi<INewHorizons>("xen.NewHorizons");
api.GetBodyLoadedEvent().AddListener((name) => {
ModHelper.Console.WriteLine($"Body: {name} Loaded!");
var data = api.QueryBody<MyCoolExtensionData>("$.extras.myCoolExtensionData", name);
var data = api.QueryBody<MyCoolExtensionData>(name, "$.extras.myCoolExtensionData");
// Makes sure the module is not null
if (data != null) {
ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!");