mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add Support For Extra Modules
This commit is contained in:
parent
2ed111b5a0
commit
135aae9974
@ -248,6 +248,7 @@ namespace NewHorizons.Handlers
|
||||
}
|
||||
}
|
||||
}
|
||||
Main.Instance.OnPlanetLoaded?.Invoke(body.Config.name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,17 @@ namespace NewHorizons
|
||||
/// </summary>
|
||||
UnityEvent<string> GetStarSystemLoadedEvent();
|
||||
|
||||
/// <summary>
|
||||
/// An event invoked when NH has finished a planet for a star system.
|
||||
/// Gives the name of the planet that was just loaded.
|
||||
/// </summary>
|
||||
UnityEvent<string> GetBodyLoadedEvent();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an object in the `extras` object of a config, returns null if the key doesn't exist
|
||||
/// </summary>
|
||||
object GetExtraModule(Type moduleType, string extrasModuleName, string planetName);
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to overwrite the default system. This is where the player is respawned after dying.
|
||||
/// </summary>
|
||||
|
||||
@ -68,6 +68,7 @@ namespace NewHorizons
|
||||
public class StarSystemEvent : UnityEvent<string> { }
|
||||
public StarSystemEvent OnChangeStarSystem;
|
||||
public StarSystemEvent OnStarSystemLoaded;
|
||||
public StarSystemEvent OnPlanetLoaded;
|
||||
|
||||
// For warping to the eye system
|
||||
private GameObject _ship;
|
||||
@ -170,6 +171,7 @@ namespace NewHorizons
|
||||
|
||||
OnChangeStarSystem = new StarSystemEvent();
|
||||
OnStarSystemLoaded = new StarSystemEvent();
|
||||
OnPlanetLoaded = new StarSystemEvent();
|
||||
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
|
||||
@ -5,14 +5,17 @@ using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
|
||||
namespace NewHorizons
|
||||
{
|
||||
|
||||
public class NewHorizonsApi : INewHorizons
|
||||
{
|
||||
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
|
||||
@ -64,20 +67,10 @@ namespace NewHorizons
|
||||
return Main.BodyDict.Values.SelectMany(x => x)?.ToList()?.FirstOrDefault(x => x.Config.name == name)?.Object;
|
||||
}
|
||||
|
||||
public string GetCurrentStarSystem()
|
||||
{
|
||||
return Main.Instance.CurrentStarSystem;
|
||||
}
|
||||
|
||||
public UnityEvent<string> GetChangeStarSystemEvent()
|
||||
{
|
||||
return Main.Instance.OnChangeStarSystem;
|
||||
}
|
||||
|
||||
public UnityEvent<string> GetStarSystemLoadedEvent()
|
||||
{
|
||||
return Main.Instance.OnStarSystemLoaded;
|
||||
}
|
||||
public string GetCurrentStarSystem() => Main.Instance.CurrentStarSystem;
|
||||
public UnityEvent<string> GetChangeStarSystemEvent() => Main.Instance.OnChangeStarSystem;
|
||||
public UnityEvent<string> GetStarSystemLoadedEvent() => Main.Instance.OnStarSystemLoaded;
|
||||
public UnityEvent<string> GetBodyLoadedEvent() => Main.Instance.OnPlanetLoaded;
|
||||
|
||||
public bool SetDefaultSystem(string name)
|
||||
{
|
||||
@ -108,6 +101,25 @@ namespace NewHorizons
|
||||
}
|
||||
}
|
||||
|
||||
public object GetExtraModule(Type moduleType, string extraModuleKey, string planetName)
|
||||
{
|
||||
var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == planetName);
|
||||
if (planet == null)
|
||||
{
|
||||
// Uh idk if we need this but ye it do be here etc.
|
||||
Logger.LogVerbose($"Attempting To Get Extras On Planet That Doesn't Exist! ({planetName})");
|
||||
return null;
|
||||
}
|
||||
var jsonText = File.ReadAllText(planet.Mod.ModHelper.Manifest.ModFolderPath + planet.RelativePath);
|
||||
var jsonData = JObject.Parse(jsonText);
|
||||
var possibleExtras = jsonData.Property("extras")?.Value;
|
||||
if (possibleExtras is JObject extras)
|
||||
{
|
||||
return extras.Property(extraModuleKey)?.Value.ToObject(moduleType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
|
||||
float scale, bool alignWithNormal)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user