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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,17 @@ namespace NewHorizons
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
UnityEvent<string> GetStarSystemLoadedEvent();
|
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>
|
/// <summary>
|
||||||
/// Allows you to overwrite the default system. This is where the player is respawned after dying.
|
/// Allows you to overwrite the default system. This is where the player is respawned after dying.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -68,6 +68,7 @@ namespace NewHorizons
|
|||||||
public class StarSystemEvent : UnityEvent<string> { }
|
public class StarSystemEvent : UnityEvent<string> { }
|
||||||
public StarSystemEvent OnChangeStarSystem;
|
public StarSystemEvent OnChangeStarSystem;
|
||||||
public StarSystemEvent OnStarSystemLoaded;
|
public StarSystemEvent OnStarSystemLoaded;
|
||||||
|
public StarSystemEvent OnPlanetLoaded;
|
||||||
|
|
||||||
// For warping to the eye system
|
// For warping to the eye system
|
||||||
private GameObject _ship;
|
private GameObject _ship;
|
||||||
@ -170,6 +171,7 @@ namespace NewHorizons
|
|||||||
|
|
||||||
OnChangeStarSystem = new StarSystemEvent();
|
OnChangeStarSystem = new StarSystemEvent();
|
||||||
OnStarSystemLoaded = new StarSystemEvent();
|
OnStarSystemLoaded = new StarSystemEvent();
|
||||||
|
OnPlanetLoaded = new StarSystemEvent();
|
||||||
|
|
||||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||||
|
|||||||
@ -5,14 +5,17 @@ using OWML.Common;
|
|||||||
using OWML.Utils;
|
using OWML.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
|
|
||||||
namespace NewHorizons
|
namespace NewHorizons
|
||||||
{
|
{
|
||||||
|
|
||||||
public class NewHorizonsApi : INewHorizons
|
public class NewHorizonsApi : INewHorizons
|
||||||
{
|
{
|
||||||
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
|
[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;
|
return Main.BodyDict.Values.SelectMany(x => x)?.ToList()?.FirstOrDefault(x => x.Config.name == name)?.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCurrentStarSystem()
|
public string GetCurrentStarSystem() => Main.Instance.CurrentStarSystem;
|
||||||
{
|
public UnityEvent<string> GetChangeStarSystemEvent() => Main.Instance.OnChangeStarSystem;
|
||||||
return Main.Instance.CurrentStarSystem;
|
public UnityEvent<string> GetStarSystemLoadedEvent() => Main.Instance.OnStarSystemLoaded;
|
||||||
}
|
public UnityEvent<string> GetBodyLoadedEvent() => Main.Instance.OnPlanetLoaded;
|
||||||
|
|
||||||
public UnityEvent<string> GetChangeStarSystemEvent()
|
|
||||||
{
|
|
||||||
return Main.Instance.OnChangeStarSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UnityEvent<string> GetStarSystemLoadedEvent()
|
|
||||||
{
|
|
||||||
return Main.Instance.OnStarSystemLoaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SetDefaultSystem(string name)
|
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,
|
public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
|
||||||
float scale, bool alignWithNormal)
|
float scale, bool alignWithNormal)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user