mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Added Support for Systems
This commit is contained in:
parent
202eb808aa
commit
6722ff7ad4
@ -50,9 +50,14 @@ namespace NewHorizons
|
||||
UnityEvent<string> GetBodyLoadedEvent();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an object in the `extras` object of a config, returns null if the key doesn't exist
|
||||
/// Gets an object in the `extras` object of a body config, returns null if the key doesn't exist
|
||||
/// </summary>
|
||||
object GetExtraModule(Type moduleType, string extrasModuleName, string planetName);
|
||||
object GetExtraModuleForBody(Type moduleType, string extrasModuleName, string planetName);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an object in the `extras` object of a system config, returns null if the key doesn't exist
|
||||
/// </summary>
|
||||
object GetExtraModuleForSystem(Type moduleType, string extrasModuleName, string systemName);
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to overwrite the default system. This is where the player is respawned after dying.
|
||||
|
||||
@ -127,7 +127,7 @@ namespace NewHorizons
|
||||
|
||||
BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
|
||||
BodyDict["EyeOfTheUniverse"] = new List<NewHorizonsBody>(); // Keep this empty tho fr
|
||||
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(), Instance)
|
||||
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(), "", Instance)
|
||||
{
|
||||
Config =
|
||||
{
|
||||
@ -143,7 +143,7 @@ namespace NewHorizons
|
||||
}
|
||||
}
|
||||
};
|
||||
SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig(), Instance)
|
||||
SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig(), "", Instance)
|
||||
{
|
||||
Config =
|
||||
{
|
||||
@ -517,7 +517,7 @@ namespace NewHorizons
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, mod);
|
||||
SystemDict[name] = new NewHorizonsSystem(name, starSystemConfig, relativePath, mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -618,7 +618,7 @@ namespace NewHorizons
|
||||
starSystemConfig.Migrate();
|
||||
starSystemConfig.FixCoordinates();
|
||||
|
||||
var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, mod);
|
||||
var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, "", mod);
|
||||
|
||||
SystemDict.Add(config.starSystem, system);
|
||||
|
||||
|
||||
@ -101,23 +101,42 @@ namespace NewHorizons
|
||||
}
|
||||
}
|
||||
|
||||
public object GetExtraModule(Type moduleType, string extraModuleKey, string planetName)
|
||||
private object GetExtraModule(Type moduleType, string key, string path)
|
||||
{
|
||||
var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == planetName);
|
||||
if (planet == null)
|
||||
if (path == "") return null;
|
||||
try
|
||||
{
|
||||
// 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})");
|
||||
var jsonText = File.ReadAllText(path);
|
||||
var jsonData = JObject.Parse(jsonText);
|
||||
var possibleExtras = jsonData.Property("extras")?.Value;
|
||||
if (possibleExtras is JObject extras)
|
||||
{
|
||||
return extras.Property(key)?.Value.ToObject(moduleType);
|
||||
}
|
||||
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)
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
return extras.Property(extraModuleKey)?.Value.ToObject(moduleType);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetExtraModuleForBody(Type moduleType, string extraModuleKey, string planetName)
|
||||
{
|
||||
var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == planetName);
|
||||
return planet == null
|
||||
? null
|
||||
: GetExtraModule(moduleType, extraModuleKey,
|
||||
planet.Mod.ModHelper.Manifest.ModFolderPath + planet.RelativePath);
|
||||
}
|
||||
|
||||
public object GetExtraModuleForSystem(Type moduleType, string extraModuleKey, string systemName)
|
||||
{
|
||||
var system = Main.SystemDict[Main.Instance.CurrentStarSystem];
|
||||
return system == null
|
||||
? null
|
||||
: GetExtraModule(moduleType, extraModuleKey,
|
||||
system.Mod.ModHelper.Manifest.ModFolderPath + system.RelativePath);
|
||||
}
|
||||
|
||||
public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,
|
||||
|
||||
@ -11,15 +11,17 @@ namespace NewHorizons.Utility
|
||||
public class NewHorizonsSystem
|
||||
{
|
||||
public string UniqueID;
|
||||
public string RelativePath;
|
||||
public SpawnModule Spawn = null;
|
||||
public SpawnPoint SpawnPoint = null;
|
||||
public StarSystemConfig Config;
|
||||
public IModBehaviour Mod;
|
||||
|
||||
public NewHorizonsSystem(string uniqueID, StarSystemConfig config, IModBehaviour mod)
|
||||
public NewHorizonsSystem(string uniqueID, StarSystemConfig config, string relativePath, IModBehaviour mod)
|
||||
{
|
||||
UniqueID = uniqueID;
|
||||
Config = config;
|
||||
RelativePath = relativePath;
|
||||
Mod = mod;
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,23 +78,28 @@ public static class SchemaExporter
|
||||
{"description", _description}
|
||||
});
|
||||
|
||||
if (_title == "Celestial Body Schema")
|
||||
switch (_title)
|
||||
{
|
||||
schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f;
|
||||
schema.Properties.Add("extras", new JsonSchemaProperty {
|
||||
Type = JsonObjectType.Object,
|
||||
Description = "Extra data that may be used by extension mods"
|
||||
});
|
||||
case "Celestial Body Schema":
|
||||
schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f;
|
||||
break;
|
||||
case "Star System Schema":
|
||||
schema.Definitions["NomaiCoordinates"].Properties["x"].UniqueItems = true;
|
||||
schema.Definitions["NomaiCoordinates"].Properties["y"].UniqueItems = true;
|
||||
schema.Definitions["NomaiCoordinates"].Properties["z"].UniqueItems = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (_title == "Star System Schema")
|
||||
if (_title is "Star System Schema" or "Celestial Body Schema")
|
||||
{
|
||||
schema.Definitions["NomaiCoordinates"].Properties["x"].UniqueItems = true;
|
||||
schema.Definitions["NomaiCoordinates"].Properties["y"].UniqueItems = true;
|
||||
schema.Definitions["NomaiCoordinates"].Properties["z"].UniqueItems = true;
|
||||
schema.Properties.Add("extras", new JsonSchemaProperty {
|
||||
Type = JsonObjectType.Object,
|
||||
Description = "Extra data that may be used by extension mods"
|
||||
Description = "Extra data that may be used by extension mods",
|
||||
AllowAdditionalProperties = true,
|
||||
AdditionalPropertiesSchema = new JsonSchema
|
||||
{
|
||||
Type = JsonObjectType.Object
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user