From bca0e2ffed9c251275d69d8a827214bccddd442d Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 27 Aug 2022 21:30:07 -0400 Subject: [PATCH 01/37] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 38fd21ab..5696ae38 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, clay, MegaPiggy, John, Hawkbar, Trifid, Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.5.0", + "version": "1.5.1", "owmlVersion": "2.6.0", "dependencies": [ "JohnCorby.VanillaFix" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_Randomizer" ], From e92c6b6404bbbdd1a16935f2795854c6e6cc91f1 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 27 Aug 2022 21:26:38 -0700 Subject: [PATCH 02/37] next update?????? --- NewHorizons/Builder/Body/BrambleDimensionBuilder.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index 65fa1fcf..18927c1f 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -192,8 +192,12 @@ namespace NewHorizons.Builder.Body cloak.GetComponent().enabled = true; // Cull stuff - var cullController = go.AddComponent(); - cullController.SetSector(sector); + // Do next update so other nodes can be built first + Delay.FireOnNextUpdate(() => + { + var cullController = go.AddComponent(); + cullController.SetSector(sector); + }); // finalize atmo.SetActive(true); From 313267427b96da3ac3c69d0c9b219ce603421521 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 28 Aug 2022 15:03:35 -0400 Subject: [PATCH 03/37] Better backup --- NewHorizons/Utility/DebugMenu/DebugMenu.cs | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/NewHorizons/Utility/DebugMenu/DebugMenu.cs b/NewHorizons/Utility/DebugMenu/DebugMenu.cs index 0d25ebfe..aa58001d 100644 --- a/NewHorizons/Utility/DebugMenu/DebugMenu.cs +++ b/NewHorizons/Utility/DebugMenu/DebugMenu.cs @@ -227,6 +227,24 @@ namespace NewHorizons.Utility.DebugMenu var json = loadedConfigFiles[filePath].ToSerializedJson(); + try + { + var path = loadedMod.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath; + Logger.LogVerbose($"Backing up... {relativePath} to {path}"); + var oldPath = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath; + var directoryName = Path.GetDirectoryName(path); + Directory.CreateDirectory(directoryName); + + if (File.Exists(oldPath)) + File.WriteAllBytes(path, File.ReadAllBytes(oldPath)); + else + File.WriteAllText(path, json); + } + catch (Exception e) + { + Logger.LogError($"Failed to save backup file {backupFolderName}{relativePath}:\n{e}"); + } + try { Logger.Log($"Saving... {relativePath} to {filePath}"); @@ -240,19 +258,6 @@ namespace NewHorizons.Utility.DebugMenu { Logger.LogError($"Failed to save file {relativePath}:\n{e}"); } - - try - { - var path = Main.Instance.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath; - var directoryName = Path.GetDirectoryName(path); - Directory.CreateDirectory(directoryName); - - File.WriteAllText(path, json); - } - catch (Exception e) - { - Logger.LogError($"Failed to save backup file {backupFolderName}{relativePath}:\n{e}"); - } } } From 57c145c048dd1d3e696ac86a7212e1a16571972a Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 28 Aug 2022 15:35:05 -0400 Subject: [PATCH 04/37] Only autosave if save button is unlocked --- NewHorizons/Utility/DebugMenu/DebugMenu.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Utility/DebugMenu/DebugMenu.cs b/NewHorizons/Utility/DebugMenu/DebugMenu.cs index aa58001d..be19c867 100644 --- a/NewHorizons/Utility/DebugMenu/DebugMenu.cs +++ b/NewHorizons/Utility/DebugMenu/DebugMenu.cs @@ -69,7 +69,13 @@ namespace NewHorizons.Utility.DebugMenu PauseMenuInitHook(); - Main.Instance.OnChangeStarSystem.AddListener((string s) => SaveLoadedConfigsForRecentSystem()); + Main.Instance.OnChangeStarSystem.AddListener((string s) => { + if (saveButtonUnlocked) + { + SaveLoadedConfigsForRecentSystem(); + saveButtonUnlocked = false; + } + }); } else { From 135aae99744784408a2e23da19cefafad8d1a73d Mon Sep 17 00:00:00 2001 From: Ben C Date: Sun, 28 Aug 2022 21:02:34 -0400 Subject: [PATCH 05/37] Add Support For Extra Modules --- NewHorizons/Handlers/PlanetCreationHandler.cs | 1 + NewHorizons/INewHorizons.cs | 11 +++++ NewHorizons/Main.cs | 2 + NewHorizons/NewHorizonsApi.cs | 40 ++++++++++++------- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 73df7daa..fcb82a02 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -248,6 +248,7 @@ namespace NewHorizons.Handlers } } } + Main.Instance.OnPlanetLoaded?.Invoke(body.Config.name); return true; } diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index 7c647003..7b9936ba 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -43,6 +43,17 @@ namespace NewHorizons /// UnityEvent GetStarSystemLoadedEvent(); + /// + /// An event invoked when NH has finished a planet for a star system. + /// Gives the name of the planet that was just loaded. + /// + UnityEvent GetBodyLoadedEvent(); + + /// + /// Gets an object in the `extras` object of a config, returns null if the key doesn't exist + /// + object GetExtraModule(Type moduleType, string extrasModuleName, string planetName); + /// /// Allows you to overwrite the default system. This is where the player is respawned after dying. /// diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index cb64f092..000eb46b 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -68,6 +68,7 @@ namespace NewHorizons public class StarSystemEvent : UnityEvent { } 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; diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 0ddb9f14..13a0fae1 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -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 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 GetChangeStarSystemEvent() - { - return Main.Instance.OnChangeStarSystem; - } - - public UnityEvent GetStarSystemLoadedEvent() - { - return Main.Instance.OnStarSystemLoaded; - } + public string GetCurrentStarSystem() => Main.Instance.CurrentStarSystem; + public UnityEvent GetChangeStarSystemEvent() => Main.Instance.OnChangeStarSystem; + public UnityEvent GetStarSystemLoadedEvent() => Main.Instance.OnStarSystemLoaded; + public UnityEvent 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) { From ffc12dde6d0714582c257dd329200f9d908486d2 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 29 Aug 2022 01:12:08 -0400 Subject: [PATCH 06/37] Resize volume layers --- NewHorizons/Patches/ShapePatches.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 NewHorizons/Patches/ShapePatches.cs diff --git a/NewHorizons/Patches/ShapePatches.cs b/NewHorizons/Patches/ShapePatches.cs new file mode 100644 index 00000000..cf4d19d0 --- /dev/null +++ b/NewHorizons/Patches/ShapePatches.cs @@ -0,0 +1,29 @@ +using HarmonyLib; +using System.Collections.Generic; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public class ShapePatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(ShapeManager), nameof(ShapeManager.Initialize))] + public static bool ShapeManager_Initialize() + { + ShapeManager._exists = true; + + ShapeManager._detectors = new ShapeManager.Layer(256); + for (int index = 0; index < 256; ++index) + ShapeManager._detectors[index].contacts = new List(64); + + ShapeManager._volumes = new ShapeManager.Layer[4]; + for (int index = 0; index < 4; ++index) + ShapeManager._volumes[index] = new ShapeManager.Layer(2048); + + ShapeManager._locked = false; + ShapeManager._frameFlag = false; + + return false; + } + } +} From 60d26822298f5fcb4bdd90af8828f937ac0f988e Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 08:04:09 -0400 Subject: [PATCH 07/37] Add To Body Schema --- SchemaExporter/SchemaExporter.cs | 191 ++++++++++++++++--------------- 1 file changed, 96 insertions(+), 95 deletions(-) diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index f0c802f5..450d6833 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -1,96 +1,97 @@ -using System; -using System.Collections.Generic; -using System.IO; -using NewHorizons.External.Configs; -using NJsonSchema; -using NJsonSchema.Generation; - -namespace SchemaExporter; - -public static class SchemaExporter -{ - public static void Main(string[] args) - { - const string folderName = "NewHorizons/Schemas"; - - Directory.CreateDirectory(folderName); - Console.WriteLine("Schema Generator: We're winning!"); - var settings = new JsonSchemaGeneratorSettings - { - IgnoreObsoleteProperties = true, - DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull, - FlattenInheritanceHierarchy = true, - AllowReferencesWithProperties = true - }; - var bodySchema = new Schema("Celestial Body Schema", "Schema for a celestial body in New Horizons", $"{folderName}/body_schema", settings); - bodySchema.Output(); - var systemSchema = - new Schema("Star System Schema", "Schema for a star system in New Horizons", $"{folderName}/star_system_schema", settings); - systemSchema.Output(); - var addonSchema = new Schema("Addon Manifest Schema", - "Schema for an addon manifest in New Horizons", $"{folderName}/addon_manifest_schema", settings); - addonSchema.Output(); - var translationSchema = - new Schema("Translation Schema", "Schema for a translation file in New Horizons", $"{folderName}/translation_schema", settings); - translationSchema.Output(); - Console.WriteLine("Done!"); - } - - private readonly struct Schema - { - private readonly JsonSchemaGeneratorSettings _generatorSettings; - private readonly string _title, _description; - private readonly string _outFileName; - - public Schema(string schemaTitle, string schemaDescription, string fileName, JsonSchemaGeneratorSettings settings) - { - _title = schemaTitle; - _description = schemaDescription; - _outFileName = fileName; - _generatorSettings = settings; - } - - public void Output() - { - Console.WriteLine($"Outputting {_title}"); - File.WriteAllText($"{_outFileName}.json", ToString()); - } - - public override string ToString() - { - return GetJsonSchema().ToJson(); - } - - private JsonSchema GetJsonSchema() - { - var schema = JsonSchema.FromType(_generatorSettings); - schema.Title = _title; - var schemaLinkProp = new JsonSchemaProperty - { - Type = JsonObjectType.String, - Description = "The schema to validate with" - }; - schema.Properties.Add("$schema", schemaLinkProp); - schema.ExtensionData ??= new Dictionary(); - schema.ExtensionData.Add("$docs", new Dictionary - { - {"title", _title}, - {"description", _description} - }); - - if (_title == "Celestial Body Schema") - { - schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; - } - - if (_title == "Star System Schema") - { - schema.Definitions["NomaiCoordinates"].Properties["x"].UniqueItems = true; - schema.Definitions["NomaiCoordinates"].Properties["y"].UniqueItems = true; - schema.Definitions["NomaiCoordinates"].Properties["z"].UniqueItems = true; - } - - return schema; - } - } +using System; +using System.Collections.Generic; +using System.IO; +using NewHorizons.External.Configs; +using NJsonSchema; +using NJsonSchema.Generation; + +namespace SchemaExporter; + +public static class SchemaExporter +{ + public static void Main(string[] args) + { + const string folderName = "NewHorizons/Schemas"; + + Directory.CreateDirectory(folderName); + Console.WriteLine("Schema Generator: We're winning!"); + var settings = new JsonSchemaGeneratorSettings + { + IgnoreObsoleteProperties = true, + DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull, + FlattenInheritanceHierarchy = true, + AllowReferencesWithProperties = true + }; + var bodySchema = new Schema("Celestial Body Schema", "Schema for a celestial body in New Horizons", $"{folderName}/body_schema", settings); + bodySchema.Output(); + var systemSchema = + new Schema("Star System Schema", "Schema for a star system in New Horizons", $"{folderName}/star_system_schema", settings); + systemSchema.Output(); + var addonSchema = new Schema("Addon Manifest Schema", + "Schema for an addon manifest in New Horizons", $"{folderName}/addon_manifest_schema", settings); + addonSchema.Output(); + var translationSchema = + new Schema("Translation Schema", "Schema for a translation file in New Horizons", $"{folderName}/translation_schema", settings); + translationSchema.Output(); + Console.WriteLine("Done!"); + } + + private readonly struct Schema + { + private readonly JsonSchemaGeneratorSettings _generatorSettings; + private readonly string _title, _description; + private readonly string _outFileName; + + public Schema(string schemaTitle, string schemaDescription, string fileName, JsonSchemaGeneratorSettings settings) + { + _title = schemaTitle; + _description = schemaDescription; + _outFileName = fileName; + _generatorSettings = settings; + } + + public void Output() + { + Console.WriteLine($"Outputting {_title}"); + File.WriteAllText($"{_outFileName}.json", ToString()); + } + + public override string ToString() + { + return GetJsonSchema().ToJson(); + } + + private JsonSchema GetJsonSchema() + { + var schema = JsonSchema.FromType(_generatorSettings); + schema.Title = _title; + var schemaLinkProp = new JsonSchemaProperty + { + Type = JsonObjectType.String, + Description = "The schema to validate with" + }; + schema.Properties.Add("$schema", schemaLinkProp); + schema.ExtensionData ??= new Dictionary(); + schema.ExtensionData.Add("$docs", new Dictionary + { + {"title", _title}, + {"description", _description} + }); + + if (_title == "Celestial Body Schema") + { + schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; + schema.Properties.Add("extras", new Dictionary()); + } + + if (_title == "Star System Schema") + { + schema.Definitions["NomaiCoordinates"].Properties["x"].UniqueItems = true; + schema.Definitions["NomaiCoordinates"].Properties["y"].UniqueItems = true; + schema.Definitions["NomaiCoordinates"].Properties["z"].UniqueItems = true; + } + + return schema; + } + } } \ No newline at end of file From 549bea956713a5dfa49932e924ac941d91bb0bd8 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 08:08:36 -0400 Subject: [PATCH 08/37] Ok try again --- SchemaExporter/SchemaExporter.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 450d6833..2dba6386 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -81,7 +81,10 @@ public static class SchemaExporter if (_title == "Celestial Body Schema") { schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; - schema.Properties.Add("extras", new Dictionary()); + schema.Properties.Add("extras", new JsonSchemaProperty { + Type = JsonObjectType.Object, + Description = "Extra data that may be used by extension mods" + }); } if (_title == "Star System Schema") @@ -89,6 +92,10 @@ public static class SchemaExporter 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" + }); } return schema; From a8ca79896b519a82036b2b195d15477f40545fb4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 29 Aug 2022 12:13:22 +0000 Subject: [PATCH 09/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 4 ++++ NewHorizons/Schemas/star_system_schema.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index bc88b9f7..c4fe13eb 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -131,6 +131,10 @@ "$schema": { "type": "string", "description": "The schema to validate with" + }, + "extras": { + "type": "object", + "description": "Extra data that may be used by extension mods" } }, "definitions": { diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index b1f5e2cc..54770b00 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -74,6 +74,10 @@ "$schema": { "type": "string", "description": "The schema to validate with" + }, + "extras": { + "type": "object", + "description": "Extra data that may be used by extension mods" } }, "definitions": { From 21dc7fc8dd5769221855de124e1afffa2bf1957a Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 08:33:20 -0400 Subject: [PATCH 10/37] Updated Docs --- docs/content/pages/tutorials/api.md | 95 ++++++++++++++++++++--- docs/content/pages/tutorials/extending.md | 65 ++++++++++++++++ 2 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 docs/content/pages/tutorials/extending.md diff --git a/docs/content/pages/tutorials/api.md b/docs/content/pages/tutorials/api.md index 8689943c..114cbe68 100644 --- a/docs/content/pages/tutorials/api.md +++ b/docs/content/pages/tutorials/api.md @@ -9,21 +9,94 @@ First create the following interface in your mod: ```cs public interface INewHorizons -{ - void LoadConfigs(IModBehaviour mod); + { + [Obsolete("Create(Dictionary config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")] + void Create(Dictionary config); - GameObject GetPlanet(string name); - - string GetCurrentStarSystem(); + [Obsolete("Create(Dictionary config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")] + void Create(Dictionary config, IModBehaviour mod); - UnityEvent GetChangeStarSystemEvent(); + /// + /// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod. + /// The NH addon config template is just a single call to this API method. + /// + void LoadConfigs(IModBehaviour mod); - UnityEvent GetStarSystemLoadedEvent(); - - GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignWithNormal); + /// + /// Retrieve the root GameObject of a custom planet made by creating configs. + /// Will only work if the planet has been created (see GetStarSystemLoadedEvent) + /// + GameObject GetPlanet(string name); - string[] GetInstalledAddons(); -} + /// + /// The name of the current star system loaded. + /// + string GetCurrentStarSystem(); + + /// + /// An event invoked when the player begins loading the new star system, before the scene starts to load. + /// Gives the name of the star system being switched to. + /// + UnityEvent GetChangeStarSystemEvent(); + + /// + /// An event invoked when NH has finished generating all planets for a new star system. + /// Gives the name of the star system that was just loaded. + /// + UnityEvent GetStarSystemLoadedEvent(); + + /// + /// An event invoked when NH has finished a planet for a star system. + /// Gives the name of the planet that was just loaded. + /// + UnityEvent GetBodyLoadedEvent(); + + /// + /// Gets an object in the `extras` object of a config, returns null if the key doesn't exist + /// + object GetExtraModule(Type moduleType, string extrasModuleName, string planetName); + + /// + /// Allows you to overwrite the default system. This is where the player is respawned after dying. + /// + bool SetDefaultSystem(string name); + + /// + /// Allows you to instantly begin a warp to a new star system. + /// Will return false if that system does not exist (cannot be warped to). + /// + bool ChangeCurrentStarSystem(string name); + + /// + /// Returns the uniqueIDs of each installed NH addon. + /// + string[] GetInstalledAddons(); + + /// + /// Allows you to spawn a copy of a prop by specifying its path. + /// This is the same as using Props->details in a config, but also returns the spawned gameObject to you. + /// + GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, + float scale, bool alignWithNormal); + + /// + /// Allows you to spawn an AudioSignal on a planet. + /// This is the same as using Props->signals in a config, but also returns the spawned AudioSignal to you. + /// This method will not set its position. You will have to do that with the returned object. + /// + AudioSignal SpawnSignal(IModBehaviour mod, GameObject root, string audio, string name, string frequency, + float sourceRadius = 1f, float detectionRadius = 20f, float identificationRadius = 10f, bool insideCloak = false, + bool onlyAudibleToScope = true, string reveals = ""); + + /// + /// Allows you to spawn character dialogue on a planet. Also returns the RemoteDialogueTrigger if remoteTriggerRadius is specified. + /// This is the same as using Props->dialogue in a config, but also returns the spawned game objects to you. + /// This method will not set the position of the dialogue or remote trigger. You will have to do that with the returned objects. + /// + (CharacterDialogueTree, RemoteDialogueTrigger) SpawnDialogue(IModBehaviour mod, GameObject root, string xmlFile, float radius = 1f, + float range = 1f, string blockAfterPersistentCondition = null, float lookAtRadius = 1f, string pathToAnimController = null, + float remoteTriggerRadius = 0f); + } ``` In your main `ModBehaviour` class you can get the NewHorizons API like so: diff --git a/docs/content/pages/tutorials/extending.md b/docs/content/pages/tutorials/extending.md new file mode 100644 index 00000000..649c2473 --- /dev/null +++ b/docs/content/pages/tutorials/extending.md @@ -0,0 +1,65 @@ +--- +Title: Extending Configs +Description: A guide on extending config files with the New Horizons API +Sort_Priority: 5 +--- + + + +# Extending Configs + +This guide will explain how to use the API to add new features to New Horizons. + +## How Extending Works + +Addon developers will add a key to the `extras` object in the root of the config + +```json +{ + "name": "Wetrock", + "extras": { + "myCoolExtensionData": { + "myCoolExtensionProperty": 2 + } + } +} +``` + +Your mod will then use the API's `GetExtraModule` method to obtain the `myCoolExtensionData` object. + +## Extending Planets + +You can extend all planets by hooking into the `OnBodyLoaded` event of the API: + +```cs +var api = ModHelper.Interactions.TryGetModApi("xen.NewHorizons"); +api.GetBodyLoadedEvent().AddListener((name) => { + ModHelper.Console.WriteLine($"Body: {name} Loaded!"); +}); +``` + +In order to get your extra module, first define the module as a class: + +```cs +public class MyCoolExtensionData { + int myCoolExtensionProperty; +} +``` + +Then, use the `GetExtraModule` method: + +```cs +var api = ModHelper.Interactions.TryGetModApi("xen.NewHorizons"); +api.GetBodyLoadedEvent().AddListener((name) => { + ModHelper.Console.WriteLine($"Body: {name} Loaded!"); + var potentialData = api.GetExtraModule(typeof(MyCoolExtensionData), "myCoolExtensionData", name); + // Makes sure the module is valid and not null + if (potentialData is MyCoolExtensionData data) { + ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!"); + } +}); +``` + +## Extending Systems + + From 44984bde2729c58cfe29a697b9edc24cd17bef8c Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 08:38:31 -0400 Subject: [PATCH 11/37] Update API docs to use TryGetModApi --- docs/content/pages/tutorials/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/pages/tutorials/api.md b/docs/content/pages/tutorials/api.md index 114cbe68..817c89ba 100644 --- a/docs/content/pages/tutorials/api.md +++ b/docs/content/pages/tutorials/api.md @@ -106,7 +106,7 @@ public class MyMod : ModBehaviour { void Start() { - INewHorizons NewHorizonsAPI = ModHelper.Interaction.GetModApi("xen.NewHorizons"); + INewHorizons NewHorizonsAPI = ModHelper.Interaction.TryGetModApi("xen.NewHorizons"); } } ``` From 202eb808aa28addffc79610ca9e7df9ed7c31f50 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 08:52:26 -0400 Subject: [PATCH 12/37] Add Mod Dep Warning --- docs/content/pages/tutorials/extending.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/content/pages/tutorials/extending.md b/docs/content/pages/tutorials/extending.md index 649c2473..67e7e5ca 100644 --- a/docs/content/pages/tutorials/extending.md +++ b/docs/content/pages/tutorials/extending.md @@ -25,6 +25,8 @@ Addon developers will add a key to the `extras` object in the root of the config } ``` +**It's up to the addon dev to list your mod as a dependency!** + Your mod will then use the API's `GetExtraModule` method to obtain the `myCoolExtensionData` object. ## Extending Planets From 6722ff7ad40fce6a84804e326514f9786fdfea09 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 17:25:42 -0400 Subject: [PATCH 13/37] Added Support for Systems --- NewHorizons/INewHorizons.cs | 9 +- NewHorizons/Main.cs | 8 +- NewHorizons/NewHorizonsApi.cs | 41 +++-- NewHorizons/Utility/NewHorizonsSystem.cs | 4 +- SchemaExporter/SchemaExporter.cs | 211 ++++++++++++----------- 5 files changed, 152 insertions(+), 121 deletions(-) diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index 7b9936ba..aa014ea6 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -50,9 +50,14 @@ namespace NewHorizons UnityEvent GetBodyLoadedEvent(); /// - /// 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 /// - object GetExtraModule(Type moduleType, string extrasModuleName, string planetName); + object GetExtraModuleForBody(Type moduleType, string extrasModuleName, string planetName); + + /// + /// Gets an object in the `extras` object of a system config, returns null if the key doesn't exist + /// + object GetExtraModuleForSystem(Type moduleType, string extrasModuleName, string systemName); /// /// Allows you to overwrite the default system. This is where the player is respawned after dying. diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 000eb46b..97ba6124 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -127,7 +127,7 @@ namespace NewHorizons BodyDict["SolarSystem"] = new List(); BodyDict["EyeOfTheUniverse"] = new List(); // 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); diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 13a0fae1..e8e36a24 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -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, diff --git a/NewHorizons/Utility/NewHorizonsSystem.cs b/NewHorizons/Utility/NewHorizonsSystem.cs index ae6bafa3..be9a539f 100644 --- a/NewHorizons/Utility/NewHorizonsSystem.cs +++ b/NewHorizons/Utility/NewHorizonsSystem.cs @@ -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; } } diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 2dba6386..33c12666 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -1,104 +1,109 @@ -using System; -using System.Collections.Generic; -using System.IO; -using NewHorizons.External.Configs; -using NJsonSchema; -using NJsonSchema.Generation; - -namespace SchemaExporter; - -public static class SchemaExporter -{ - public static void Main(string[] args) - { - const string folderName = "NewHorizons/Schemas"; - - Directory.CreateDirectory(folderName); - Console.WriteLine("Schema Generator: We're winning!"); - var settings = new JsonSchemaGeneratorSettings - { - IgnoreObsoleteProperties = true, - DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull, - FlattenInheritanceHierarchy = true, - AllowReferencesWithProperties = true - }; - var bodySchema = new Schema("Celestial Body Schema", "Schema for a celestial body in New Horizons", $"{folderName}/body_schema", settings); - bodySchema.Output(); - var systemSchema = - new Schema("Star System Schema", "Schema for a star system in New Horizons", $"{folderName}/star_system_schema", settings); - systemSchema.Output(); - var addonSchema = new Schema("Addon Manifest Schema", - "Schema for an addon manifest in New Horizons", $"{folderName}/addon_manifest_schema", settings); - addonSchema.Output(); - var translationSchema = - new Schema("Translation Schema", "Schema for a translation file in New Horizons", $"{folderName}/translation_schema", settings); - translationSchema.Output(); - Console.WriteLine("Done!"); - } - - private readonly struct Schema - { - private readonly JsonSchemaGeneratorSettings _generatorSettings; - private readonly string _title, _description; - private readonly string _outFileName; - - public Schema(string schemaTitle, string schemaDescription, string fileName, JsonSchemaGeneratorSettings settings) - { - _title = schemaTitle; - _description = schemaDescription; - _outFileName = fileName; - _generatorSettings = settings; - } - - public void Output() - { - Console.WriteLine($"Outputting {_title}"); - File.WriteAllText($"{_outFileName}.json", ToString()); - } - - public override string ToString() - { - return GetJsonSchema().ToJson(); - } - - private JsonSchema GetJsonSchema() - { - var schema = JsonSchema.FromType(_generatorSettings); - schema.Title = _title; - var schemaLinkProp = new JsonSchemaProperty - { - Type = JsonObjectType.String, - Description = "The schema to validate with" - }; - schema.Properties.Add("$schema", schemaLinkProp); - schema.ExtensionData ??= new Dictionary(); - schema.ExtensionData.Add("$docs", new Dictionary - { - {"title", _title}, - {"description", _description} - }); - - if (_title == "Celestial Body Schema") - { - 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" - }); - } - - if (_title == "Star System 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" - }); - } - - return schema; - } - } +using System; +using System.Collections.Generic; +using System.IO; +using NewHorizons.External.Configs; +using NJsonSchema; +using NJsonSchema.Generation; + +namespace SchemaExporter; + +public static class SchemaExporter +{ + public static void Main(string[] args) + { + const string folderName = "NewHorizons/Schemas"; + + Directory.CreateDirectory(folderName); + Console.WriteLine("Schema Generator: We're winning!"); + var settings = new JsonSchemaGeneratorSettings + { + IgnoreObsoleteProperties = true, + DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull, + FlattenInheritanceHierarchy = true, + AllowReferencesWithProperties = true + }; + var bodySchema = new Schema("Celestial Body Schema", "Schema for a celestial body in New Horizons", $"{folderName}/body_schema", settings); + bodySchema.Output(); + var systemSchema = + new Schema("Star System Schema", "Schema for a star system in New Horizons", $"{folderName}/star_system_schema", settings); + systemSchema.Output(); + var addonSchema = new Schema("Addon Manifest Schema", + "Schema for an addon manifest in New Horizons", $"{folderName}/addon_manifest_schema", settings); + addonSchema.Output(); + var translationSchema = + new Schema("Translation Schema", "Schema for a translation file in New Horizons", $"{folderName}/translation_schema", settings); + translationSchema.Output(); + Console.WriteLine("Done!"); + } + + private readonly struct Schema + { + private readonly JsonSchemaGeneratorSettings _generatorSettings; + private readonly string _title, _description; + private readonly string _outFileName; + + public Schema(string schemaTitle, string schemaDescription, string fileName, JsonSchemaGeneratorSettings settings) + { + _title = schemaTitle; + _description = schemaDescription; + _outFileName = fileName; + _generatorSettings = settings; + } + + public void Output() + { + Console.WriteLine($"Outputting {_title}"); + File.WriteAllText($"{_outFileName}.json", ToString()); + } + + public override string ToString() + { + return GetJsonSchema().ToJson(); + } + + private JsonSchema GetJsonSchema() + { + var schema = JsonSchema.FromType(_generatorSettings); + schema.Title = _title; + var schemaLinkProp = new JsonSchemaProperty + { + Type = JsonObjectType.String, + Description = "The schema to validate with" + }; + schema.Properties.Add("$schema", schemaLinkProp); + schema.ExtensionData ??= new Dictionary(); + schema.ExtensionData.Add("$docs", new Dictionary + { + {"title", _title}, + {"description", _description} + }); + + switch (_title) + { + 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 is "Star System Schema" or "Celestial Body Schema") + { + schema.Properties.Add("extras", new JsonSchemaProperty { + Type = JsonObjectType.Object, + Description = "Extra data that may be used by extension mods", + AllowAdditionalProperties = true, + AdditionalPropertiesSchema = new JsonSchema + { + Type = JsonObjectType.Object + } + }); + } + + return schema; + } + } } \ No newline at end of file From 6aad0edd33b40b7980a9f422d06a2c63e2d26f85 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 29 Aug 2022 21:29:01 +0000 Subject: [PATCH 14/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 5 ++++- NewHorizons/Schemas/star_system_schema.json | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index c4fe13eb..02771c9b 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -134,7 +134,10 @@ }, "extras": { "type": "object", - "description": "Extra data that may be used by extension mods" + "description": "Extra data that may be used by extension mods", + "additionalProperties": { + "type": "object" + } } }, "definitions": { diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 54770b00..d8073db0 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -77,7 +77,10 @@ }, "extras": { "type": "object", - "description": "Extra data that may be used by extension mods" + "description": "Extra data that may be used by extension mods", + "additionalProperties": { + "type": "object" + } } }, "definitions": { From 1c99f6c3d43e9d576b572a1fa87e6d5d52482f1a Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 17:31:01 -0400 Subject: [PATCH 15/37] Update Docs Again --- docs/content/pages/tutorials/api.md | 9 +++++++-- docs/content/pages/tutorials/extending.md | 12 +++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/content/pages/tutorials/api.md b/docs/content/pages/tutorials/api.md index 817c89ba..0400351f 100644 --- a/docs/content/pages/tutorials/api.md +++ b/docs/content/pages/tutorials/api.md @@ -52,9 +52,14 @@ public interface INewHorizons UnityEvent GetBodyLoadedEvent(); /// - /// 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 /// - object GetExtraModule(Type moduleType, string extrasModuleName, string planetName); + object GetExtraModuleForBody(Type moduleType, string extrasModuleName, string planetName); + + /// + /// Gets an object in the `extras` object of a system config, returns null if the key doesn't exist + /// + object GetExtraModuleForSystem(Type moduleType, string extrasModuleName, string systemName); /// /// Allows you to overwrite the default system. This is where the player is respawned after dying. diff --git a/docs/content/pages/tutorials/extending.md b/docs/content/pages/tutorials/extending.md index 67e7e5ca..406b5e0a 100644 --- a/docs/content/pages/tutorials/extending.md +++ b/docs/content/pages/tutorials/extending.md @@ -4,8 +4,6 @@ Description: A guide on extending config files with the New Horizons API Sort_Priority: 5 --- - - # Extending Configs This guide will explain how to use the API to add new features to New Horizons. @@ -25,9 +23,9 @@ Addon developers will add a key to the `extras` object in the root of the config } ``` -**It's up to the addon dev to list your mod as a dependency!** +Your mod will then use the API's `GetExtraModuleForBody` method to obtain the `myCoolExtensionData` object. -Your mod will then use the API's `GetExtraModule` method to obtain the `myCoolExtensionData` object. +**It's up to the addon dev to list your mod as a dependency!** ## Extending Planets @@ -48,13 +46,13 @@ public class MyCoolExtensionData { } ``` -Then, use the `GetExtraModule` method: +Then, use the `GetExtraModuleForBody` method: ```cs var api = ModHelper.Interactions.TryGetModApi("xen.NewHorizons"); api.GetBodyLoadedEvent().AddListener((name) => { ModHelper.Console.WriteLine($"Body: {name} Loaded!"); - var potentialData = api.GetExtraModule(typeof(MyCoolExtensionData), "myCoolExtensionData", name); + var potentialData = api.GetExtraModuleForBody(typeof(MyCoolExtensionData), "myCoolExtensionData", name); // Makes sure the module is valid and not null if (potentialData is MyCoolExtensionData data) { ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!"); @@ -64,4 +62,4 @@ api.GetBodyLoadedEvent().AddListener((name) => { ## Extending Systems - +Extending systems is the exact same as extending planets, except you use the `GetExtraModuleForSystem` method instead. From 7cc26d66d972638044f7a7cd7d338859ffe8f4d7 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 17:34:55 -0400 Subject: [PATCH 16/37] Add path for funny --- NewHorizons/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 97ba6124..8c9a7b34 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -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, $"systems/{config.starSystem}.json", mod); SystemDict.Add(config.starSystem, system); From 1fcf21ff0e8134c4ae22c3339d6f420a89a01280 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 17:38:00 -0400 Subject: [PATCH 17/37] Do da stanky leg 2 --- NewHorizons/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 8c9a7b34..a975b0ba 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -618,7 +618,7 @@ namespace NewHorizons starSystemConfig.Migrate(); starSystemConfig.FixCoordinates(); - var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"systems/{config.starSystem}.json", mod); + var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, $"", mod); SystemDict.Add(config.starSystem, system); From c31064c68ed7a1b7346e12bb0cea38f7601cdbfa Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 18:47:53 -0400 Subject: [PATCH 18/37] What if I like changed it LOL!!! --- NewHorizons/Handlers/PlanetCreationHandler.cs | 11 ++++++- NewHorizons/INewHorizons.cs | 8 ++--- NewHorizons/NewHorizonsApi.cs | 32 +++++++++---------- docs/content/pages/tutorials/api.md | 8 ++--- docs/content/pages/tutorials/extending.md | 23 +++++++++---- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index fcb82a02..4147fdb9 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -248,7 +248,16 @@ namespace NewHorizons.Handlers } } } - Main.Instance.OnPlanetLoaded?.Invoke(body.Config.name); + + try + { + Main.Instance.OnPlanetLoaded?.Invoke(body.Config.name); + } + catch (Exception e) + { + Logger.LogError($"Error in event handler for OnPlanetLoaded on body {body.Config.name}: {e.Message} : {e.StackTrace}"); + } + return true; } diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index aa014ea6..8f132ee7 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -50,14 +50,14 @@ namespace NewHorizons UnityEvent GetBodyLoadedEvent(); /// - /// Gets an object in the `extras` object of a body config, returns null if the key doesn't exist + /// Uses JSONPath to query a body /// - object GetExtraModuleForBody(Type moduleType, string extrasModuleName, string planetName); + object QueryBody(Type outType, string bodyName, string path); /// - /// Gets an object in the `extras` object of a system config, returns null if the key doesn't exist + /// Uses JSONPath to query a system /// - object GetExtraModuleForSystem(Type moduleType, string extrasModuleName, string systemName); + object QuerySystem(Type outType, string path); /// /// Allows you to overwrite the default system. This is where the player is respawned after dying. diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index e8e36a24..0ac47b68 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -8,6 +8,8 @@ using System.Collections.Generic; using System.Data.SqlTypes; using System.IO; using System.Linq; +using System.Reflection; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.Events; @@ -101,42 +103,40 @@ namespace NewHorizons } } - private object GetExtraModule(Type moduleType, string key, string path) + private static object QueryJson(Type outType, string filePath, string jsonPath) { - if (path == "") return null; + if (filePath == "") return null; try { - var jsonText = File.ReadAllText(path); + var jsonText = File.ReadAllText(filePath); 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; + return jsonData.SelectToken(jsonPath)?.ToObject(outType); } catch (FileNotFoundException) { return null; } + catch (JsonException e) + { + Logger.LogError($"{e.Message} : {e.StackTrace}"); + return null; + } } - public object GetExtraModuleForBody(Type moduleType, string extraModuleKey, string planetName) + public object QueryBody(Type outType, string bodyName, string jsonPath) { - var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == planetName); + var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == bodyName); return planet == null ? null - : GetExtraModule(moduleType, extraModuleKey, - planet.Mod.ModHelper.Manifest.ModFolderPath + planet.RelativePath); + : QueryJson(outType, planet.Mod.ModHelper.Manifest.ModFolderPath + planet.RelativePath, jsonPath); } - public object GetExtraModuleForSystem(Type moduleType, string extraModuleKey, string systemName) + public object QuerySystem(Type outType, string jsonPath) { var system = Main.SystemDict[Main.Instance.CurrentStarSystem]; return system == null ? null - : GetExtraModule(moduleType, extraModuleKey, - system.Mod.ModHelper.Manifest.ModFolderPath + system.RelativePath); + : QueryJson(outType, system.Mod.ModHelper.Manifest.ModFolderPath + system.RelativePath, jsonPath); } public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, diff --git a/docs/content/pages/tutorials/api.md b/docs/content/pages/tutorials/api.md index 0400351f..5c7a8996 100644 --- a/docs/content/pages/tutorials/api.md +++ b/docs/content/pages/tutorials/api.md @@ -52,14 +52,14 @@ public interface INewHorizons UnityEvent GetBodyLoadedEvent(); /// - /// Gets an object in the `extras` object of a body config, returns null if the key doesn't exist + /// Uses JSONPath to query a body /// - object GetExtraModuleForBody(Type moduleType, string extrasModuleName, string planetName); + object QueryBody(Type outType, string bodyName, string path); /// - /// Gets an object in the `extras` object of a system config, returns null if the key doesn't exist + /// Uses JSONPath to query a system /// - object GetExtraModuleForSystem(Type moduleType, string extrasModuleName, string systemName); + object QuerySystem(Type outType, string path); /// /// Allows you to overwrite the default system. This is where the player is respawned after dying. diff --git a/docs/content/pages/tutorials/extending.md b/docs/content/pages/tutorials/extending.md index 406b5e0a..7c3b4ec4 100644 --- a/docs/content/pages/tutorials/extending.md +++ b/docs/content/pages/tutorials/extending.md @@ -23,7 +23,7 @@ Addon developers will add a key to the `extras` object in the root of the config } ``` -Your mod will then use the API's `GetExtraModuleForBody` method to obtain the `myCoolExtensionData` object. +Your mod will then use the API's `QueryBody` method to obtain the `myCoolExtensionData` object. **It's up to the addon dev to list your mod as a dependency!** @@ -31,7 +31,7 @@ Your mod will then use the API's `GetExtraModuleForBody` method to obtain the `m You can extend all planets by hooking into the `OnBodyLoaded` event of the API: -```cs +```csharp var api = ModHelper.Interactions.TryGetModApi("xen.NewHorizons"); api.GetBodyLoadedEvent().AddListener((name) => { ModHelper.Console.WriteLine($"Body: {name} Loaded!"); @@ -40,19 +40,19 @@ api.GetBodyLoadedEvent().AddListener((name) => { In order to get your extra module, first define the module as a class: -```cs +```csharp public class MyCoolExtensionData { int myCoolExtensionProperty; } ``` -Then, use the `GetExtraModuleForBody` method: +Then, use the `QueryBody` method: -```cs +```csharp var api = ModHelper.Interactions.TryGetModApi("xen.NewHorizons"); api.GetBodyLoadedEvent().AddListener((name) => { ModHelper.Console.WriteLine($"Body: {name} Loaded!"); - var potentialData = api.GetExtraModuleForBody(typeof(MyCoolExtensionData), "myCoolExtensionData", name); + var potentialData = api.QueryBody(typeof(MyCoolExtensionData), "$.extras.myCoolExtensionData", name); // Makes sure the module is valid and not null if (potentialData is MyCoolExtensionData data) { ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!"); @@ -62,4 +62,13 @@ api.GetBodyLoadedEvent().AddListener((name) => { ## Extending Systems -Extending systems is the exact same as extending planets, except you use the `GetExtraModuleForSystem` method instead. +Extending systems is the exact same as extending planets, except you use the `QuerySystem` method instead. + +## Accessing Other Values + +You can also use the `QueryBody` method to get values of the config outside of your extension object + +```csharp +var primaryBody = NHAPI.QueryBody(typeof(string), "Wetrock", "$.Orbit.primaryBody"); + ModHelper.Console.WriteLine($"Primary of {bodyName} is {primaryBody ?? "NULL"}!"); +``` From a9a9b20e31ae35e54717bbb2f536580c6f86723b Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 29 Aug 2022 18:55:58 -0400 Subject: [PATCH 19/37] Fix name inconsistency in docs --- docs/content/pages/tutorials/extending.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/pages/tutorials/extending.md b/docs/content/pages/tutorials/extending.md index 7c3b4ec4..0e9b30bc 100644 --- a/docs/content/pages/tutorials/extending.md +++ b/docs/content/pages/tutorials/extending.md @@ -69,6 +69,6 @@ Extending systems is the exact same as extending planets, except you use the `Qu You can also use the `QueryBody` method to get values of the config outside of your extension object ```csharp -var primaryBody = NHAPI.QueryBody(typeof(string), "Wetrock", "$.Orbit.primaryBody"); +var primaryBody = api.QueryBody(typeof(string), "Wetrock", "$.Orbit.primaryBody"); ModHelper.Console.WriteLine($"Primary of {bodyName} is {primaryBody ?? "NULL"}!"); ``` From 5c04f456b6af51d3fc6bfa19ff3c658ffc48a8b5 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 29 Aug 2022 20:51:41 -0400 Subject: [PATCH 20/37] Just log the exception entirely so that it includes inner exceptions --- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/NewHorizonsApi.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 4147fdb9..ba0ea8f8 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -255,7 +255,7 @@ namespace NewHorizons.Handlers } catch (Exception e) { - Logger.LogError($"Error in event handler for OnPlanetLoaded on body {body.Config.name}: {e.Message} : {e.StackTrace}"); + Logger.LogError($"Error in event handler for OnPlanetLoaded on body {body.Config.name}: {e}"); } return true; diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 0ac47b68..2c551f59 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -118,7 +118,7 @@ namespace NewHorizons } catch (JsonException e) { - Logger.LogError($"{e.Message} : {e.StackTrace}"); + Logger.LogError(e.ToString()); return null; } } From 11dc7551d8b369f5d56b0ca268bd7d6f0a156277 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 29 Aug 2022 21:14:20 -0400 Subject: [PATCH 21/37] Remove unused namespaces --- NewHorizons/NewHorizonsApi.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 2c551f59..4924834f 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -5,10 +5,8 @@ using OWML.Common; using OWML.Utils; using System; using System.Collections.Generic; -using System.Data.SqlTypes; using System.IO; using System.Linq; -using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using UnityEngine; From 192c22733c919d5c3134fb4da0a70fc12580f285 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 29 Aug 2022 22:22:37 -0400 Subject: [PATCH 22/37] GetProfileName method (QSB compat) --- NewHorizons/External/NewHorizonsData.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs index a6273dd7..f90cb479 100644 --- a/NewHorizons/External/NewHorizonsData.cs +++ b/NewHorizons/External/NewHorizonsData.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using NewHorizons.Utility; @@ -11,9 +11,12 @@ namespace NewHorizons.External private static string _activeProfileName; private static readonly string FileName = "save.json"; + // This is its own method so it can be patched by NH-QSB compat + public static string GetProfileName() => StandaloneProfileManager.SharedInstance?.currentProfile?.profileName; + public static void Load() { - _activeProfileName = StandaloneProfileManager.SharedInstance?.currentProfile?.profileName; + _activeProfileName = GetProfileName(); if (_activeProfileName == null) { Logger.LogError("Couldn't find active profile, are you on Gamepass?"); From 0b1325ab85f5b5613aee33926286f343dc725d55 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 29 Aug 2022 22:37:12 -0400 Subject: [PATCH 23/37] Instead of killing player just freeze --- NewHorizons/Main.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index cb64f092..09d20227 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -647,6 +647,13 @@ namespace NewHorizons #region Change star system public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false, bool vessel = false) { + // If we're just on the title screen set the system for later + if (LoadManager.GetCurrentScene() == OWScene.TitleScreen) + { + _currentStarSystem = newStarSystem; + return; + } + if (IsChangingStarSystem) return; IsWarpingFromShip = warp; @@ -658,9 +665,6 @@ namespace NewHorizons IsChangingStarSystem = true; WearingSuit = PlayerState.IsWearingSuit(); - // We kill them so they don't move as much - Locator.GetDeathManager().KillPlayer(DeathType.Meditation); - OWScene sceneToLoad; if (newStarSystem == "EyeOfTheUniverse") @@ -678,12 +682,15 @@ namespace NewHorizons _currentStarSystem = newStarSystem; + // Freeze player inputs + OWInput.ChangeInputMode(InputMode.None); + LoadManager.LoadSceneAsync(sceneToLoad, !vessel, LoadManager.FadeType.ToBlack, 0.1f, true); } void OnDeath(DeathType _) { - // We reset the solar system on death (unless we just killed the player) + // We reset the solar system on death if (!IsChangingStarSystem) { // If the override is a valid system then we go there From 83c562c4a4037c9e262503970aa7ac6f5fcab877 Mon Sep 17 00:00:00 2001 From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com> Date: Mon, 29 Aug 2022 21:38:12 -0500 Subject: [PATCH 24/37] Make rain/snow heights more robust --- .../Builder/Atmosphere/EffectsBuilder.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs index fb405705..c177a9ed 100644 --- a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs @@ -20,6 +20,16 @@ namespace NewHorizons.Builder.Atmosphere SCG._dynamicCullingBounds = false; SCG._waitForStreaming = false; + var minHeight = surfaceSize; + var maxHeight = config.Atmosphere.size; + if (config.HeightMap?.minHeight != null) + { + if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher + else minHeight = config.HeightMap.minHeight; + } + else if (config.Water?.size != null) minHeight = config.Water.size; + else if (config.Lava?.size != null) minHeight = config.Lava.size; + if (config.Atmosphere.hasRain) { var rainGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform); @@ -29,9 +39,9 @@ namespace NewHorizons.Builder.Atmosphere var pvc = rainGO.GetComponent(); pvc._densityByHeight = new AnimationCurve(new Keyframe[] { - new Keyframe(surfaceSize - 0.5f, 0), - new Keyframe(surfaceSize, 10f), - new Keyframe(config.Atmosphere.size, 0f) + new Keyframe(minHeight - 0.5f, 0), + new Keyframe(minHeight, 10f), + new Keyframe(maxHeight, 0f) }); rainGO.GetComponent()._activeInSector = sector; @@ -53,9 +63,9 @@ namespace NewHorizons.Builder.Atmosphere var pvc = snowEmitter.GetComponent(); pvc._densityByHeight = new AnimationCurve(new Keyframe[] { - new Keyframe(surfaceSize - 0.5f, 0), - new Keyframe(surfaceSize, 10f), - new Keyframe(config.Atmosphere.size, 0f) + new Keyframe(minHeight - 0.5f, 0), + new Keyframe(minHeight, 10f), + new Keyframe(maxHeight, 0f) }); snowEmitter.GetComponent()._activeInSector = sector; From 2d03fe04a42efd2ec90903c957beb1730bbb557c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 30 Aug 2022 00:48:39 -0400 Subject: [PATCH 25/37] No - for image key --- NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs b/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs index a1e4da27..7b94ca6c 100644 --- a/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs +++ b/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs @@ -47,7 +47,7 @@ namespace NewHorizons.OtherMods.OWRichPresence var localizedName = TranslationHandler.GetTranslation(name, TranslationHandler.TextType.UI); var message = TranslationHandler.GetTranslation("RICH_PRESENCE_EXPLORING", TranslationHandler.TextType.UI).Replace("{0}", localizedName); - API.CreateTrigger(go, sector, message, name.Replace(" ", "").Replace("'", "").ToLowerInvariant()); + API.CreateTrigger(go, sector, message, name.Replace(" ", "").Replace("'", "").Replace("-", "").ToLowerInvariant()); } public static void OnStarSystemLoaded(string name) From 3ecd8e745a7255337c05611f25c5a74701daff55 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 30 Aug 2022 03:14:08 -0400 Subject: [PATCH 26/37] Loop de Loop --- NewHorizons/Builder/Props/AudioVolumeBuilder.cs | 2 +- NewHorizons/External/Modules/PropModule.cs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/AudioVolumeBuilder.cs b/NewHorizons/Builder/Props/AudioVolumeBuilder.cs index 8e45efc8..9c5d0acc 100644 --- a/NewHorizons/Builder/Props/AudioVolumeBuilder.cs +++ b/NewHorizons/Builder/Props/AudioVolumeBuilder.cs @@ -26,7 +26,7 @@ namespace NewHorizons.Builder.Props var owAudioSource = go.AddComponent(); owAudioSource._audioSource = audioSource; - owAudioSource.loop = true; + owAudioSource.loop = info.loop; owAudioSource.SetTrack((OWAudioMixer.TrackName)Enum.Parse(typeof(OWAudioMixer.TrackName), Enum.GetName(typeof(AudioMixerTrackName), info.track))); AudioUtilities.SetAudioClip(owAudioSource, info.audio, mod); diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 6ed70204..163040a0 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -840,6 +840,11 @@ namespace NewHorizons.External.Modules /// The audio track of this audio volume /// [DefaultValue("environment")] public AudioMixerTrackName track = AudioMixerTrackName.Environment; + + /// + /// Whether to loop this audio while in this audio volume + /// + [DefaultValue(true)] public bool loop = true; } [JsonObject] From e64ad0f9efcf8bea31c0d0c0fb2485865e4fa6ed Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Aug 2022 07:17:30 +0000 Subject: [PATCH 27/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index bc88b9f7..5f638234 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1822,6 +1822,11 @@ "description": "The audio track of this audio volume", "default": "environment", "$ref": "#/definitions/AudioMixerTrackName" + }, + "loop": { + "type": "boolean", + "description": "Whether to loop this audio while in this audio volume", + "default": true } } }, From 11b3381ac291ded01dfc55f403d842f1fab43309 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 30 Aug 2022 03:13:45 -0400 Subject: [PATCH 28/37] Stop dev tools from deleting extras --- NewHorizons/External/Configs/PlanetConfig.cs | 5 +++++ NewHorizons/External/Configs/StarSystemConfig.cs | 5 +++++ SchemaExporter/SchemaExporter.cs | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 4a353011..2b071244 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -169,6 +169,11 @@ namespace NewHorizons.External.Configs /// public WaterModule Water; + /// + /// Extra data that may be used by extension mods + /// + public object extras; + public PlanetConfig() { // Always have to have a base module diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index 2df0dc8c..ce311174 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -102,6 +102,11 @@ namespace NewHorizons.External.Configs /// public CuriosityColorInfo[] curiosities; + /// + /// Extra data that may be used by extension mods + /// + public object extras; + public class NomaiCoordinates { [MinLength(2)] diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 33c12666..c2e94e25 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -92,7 +92,7 @@ public static class SchemaExporter if (_title is "Star System Schema" or "Celestial Body Schema") { - schema.Properties.Add("extras", new JsonSchemaProperty { + schema.Properties["extras"] = new JsonSchemaProperty { Type = JsonObjectType.Object, Description = "Extra data that may be used by extension mods", AllowAdditionalProperties = true, @@ -100,7 +100,7 @@ public static class SchemaExporter { Type = JsonObjectType.Object } - }); + }; } return schema; From 5f2beb7aee7e5c949562717d7a3783f1e29175b7 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 30 Aug 2022 03:21:03 -0400 Subject: [PATCH 29/37] or just play it once --- NewHorizons/External/Modules/PropModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 163040a0..f4275a6e 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -842,7 +842,7 @@ namespace NewHorizons.External.Modules [DefaultValue("environment")] public AudioMixerTrackName track = AudioMixerTrackName.Environment; /// - /// Whether to loop this audio while in this audio volume + /// Whether to loop this audio while in this audio volume or just play it once /// [DefaultValue(true)] public bool loop = true; } From 9709601048decd8c64acb56d17873458b8fe97b8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Aug 2022 07:22:48 +0000 Subject: [PATCH 30/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 8 ++++---- NewHorizons/Schemas/star_system_schema.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 02771c9b..3783d7e7 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -128,16 +128,16 @@ "description": "Add water to this planet", "$ref": "#/definitions/WaterModule" }, - "$schema": { - "type": "string", - "description": "The schema to validate with" - }, "extras": { "type": "object", "description": "Extra data that may be used by extension mods", "additionalProperties": { "type": "object" } + }, + "$schema": { + "type": "string", + "description": "The schema to validate with" } }, "definitions": { diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index d8073db0..032fb8f1 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -71,16 +71,16 @@ "$ref": "#/definitions/CuriosityColorInfo" } }, - "$schema": { - "type": "string", - "description": "The schema to validate with" - }, "extras": { "type": "object", "description": "Extra data that may be used by extension mods", "additionalProperties": { "type": "object" } + }, + "$schema": { + "type": "string", + "description": "The schema to validate with" } }, "definitions": { From 4f15d21592c3d51a771ec332294a7f376a927dc9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Aug 2022 07:23:24 +0000 Subject: [PATCH 31/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5f638234..9b3db160 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1825,7 +1825,7 @@ }, "loop": { "type": "boolean", - "description": "Whether to loop this audio while in this audio volume", + "description": "Whether to loop this audio while in this audio volume or just play it once", "default": true } } From 890b496e7ab5f88a8dd0695a4a085b0fc96c729a Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 03:09:13 -0400 Subject: [PATCH 32/37] Add notification volumes --- .../Props/NotificationVolumeBuilder.cs | 43 ++++++ NewHorizons/Builder/Props/PropBuildManager.cs | 7 + NewHorizons/Components/NotificationVolume.cs | 129 ++++++++++++++++++ NewHorizons/External/Modules/PropModule.cs | 57 ++++++++ NewHorizons/Schemas/body_schema.json | 65 +++++++++ 5 files changed, 301 insertions(+) create mode 100644 NewHorizons/Builder/Props/NotificationVolumeBuilder.cs create mode 100644 NewHorizons/Components/NotificationVolume.cs diff --git a/NewHorizons/Builder/Props/NotificationVolumeBuilder.cs b/NewHorizons/Builder/Props/NotificationVolumeBuilder.cs new file mode 100644 index 00000000..eabb1519 --- /dev/null +++ b/NewHorizons/Builder/Props/NotificationVolumeBuilder.cs @@ -0,0 +1,43 @@ +using NewHorizons.Components; +using NewHorizons.External.Modules; +using NewHorizons.Utility; +using OWML.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; +using NHNotificationVolume = NewHorizons.Components.NotificationVolume; + +namespace NewHorizons.Builder.Props +{ + public static class NotificationVolumeBuilder + { + public static NHNotificationVolume Make(GameObject planetGO, Sector sector, PropModule.NotificationVolumeInfo info, IModBehaviour mod) + { + var go = new GameObject("NotificationVolume"); + go.SetActive(false); + + go.transform.parent = sector?.transform ?? planetGO.transform; + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); + go.layer = LayerMask.NameToLayer("BasicEffectVolume"); + + var shape = go.AddComponent(); + shape.radius = info.radius; + + var owTriggerVolume = go.AddComponent(); + owTriggerVolume._shape = shape; + + var notificationVolume = go.AddComponent(); + notificationVolume.SetTarget(info.target); + if (info.entryNotification != null) notificationVolume.SetEntryNotification(info.entryNotification.displayMessage, info.entryNotification.duration); + if (info.exitNotification != null) notificationVolume.SetExitNotification(info.exitNotification.displayMessage, info.exitNotification.duration); + + go.SetActive(true); + + return notificationVolume; + } + } +} diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 8f442041..1c5afe4b 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -235,6 +235,13 @@ namespace NewHorizons.Builder.Props } } } + if (config.Props.notificationVolumes != null) + { + foreach (var notificationVolume in config.Props.notificationVolumes) + { + NotificationVolumeBuilder.Make(go, sector, notificationVolume, mod); + } + } } } } diff --git a/NewHorizons/Components/NotificationVolume.cs b/NewHorizons/Components/NotificationVolume.cs new file mode 100644 index 00000000..99a35705 --- /dev/null +++ b/NewHorizons/Components/NotificationVolume.cs @@ -0,0 +1,129 @@ +using NewHorizons.Handlers; +using OWML.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace NewHorizons.Components +{ + [RequireComponent(typeof(OWTriggerVolume))] + public class NotificationVolume : MonoBehaviour + { + private NotificationTarget _target = NotificationTarget.All; + private bool _pin = false; + private OWTriggerVolume _triggerVolume; + private NotificationData _entryNotification; + private NotificationData _exitNotification; + + public void Awake() + { + _triggerVolume = this.GetRequiredComponent(); + _triggerVolume.OnEntry += OnTriggerVolumeEntry; + _triggerVolume.OnExit += OnTriggerVolumeExit; + } + + public void OnDestroy() + { + if (_triggerVolume == null) return; + _triggerVolume.OnEntry -= OnTriggerVolumeEntry; + _triggerVolume.OnExit -= OnTriggerVolumeExit; + } + + public void SetPinned(bool pin) => _pin = pin; + + public void SetTarget(NewHorizons.External.Modules.PropModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); + + public void SetTarget(NotificationTarget target) => _target = target; + + public void SetEntryNotification(string displayMessage, float duration = 5) + { + _entryNotification = new NotificationData(_target, TranslationHandler.GetTranslation(displayMessage, TranslationHandler.TextType.UI), duration); + } + + public void SetExitNotification(string displayMessage, float duration = 5) + { + _exitNotification = new NotificationData(_target, TranslationHandler.GetTranslation(displayMessage, TranslationHandler.TextType.UI), duration); + } + + public void OnTriggerVolumeEntry(GameObject hitObj) + { + if (_target == NotificationTarget.All) + { + if (hitObj.CompareTag("PlayerDetector") || hitObj.CompareTag("ShipDetector")) + { + PostEntryNotification(); + } + } + else if (_target == NotificationTarget.Player) + { + if (hitObj.CompareTag("PlayerDetector")) + { + PostEntryNotification(); + } + } + else if (_target == NotificationTarget.Ship) + { + if (hitObj.CompareTag("ShipDetector")) + { + PostEntryNotification(); + } + } + } + + public void OnTriggerVolumeExit(GameObject hitObj) + { + if (_target == NotificationTarget.All) + { + if (hitObj.CompareTag("PlayerDetector") || hitObj.CompareTag("ShipDetector")) + { + PostExitNotification(); + } + } + else if (_target == NotificationTarget.Player) + { + if (hitObj.CompareTag("PlayerDetector")) + { + PostExitNotification(); + } + } + else if (_target == NotificationTarget.Ship) + { + if (hitObj.CompareTag("ShipDetector")) + { + PostExitNotification(); + } + } + } + + public void PostEntryNotification() + { + if (_entryNotification == null) return; + NotificationManager.SharedInstance.PostNotification(_entryNotification, _pin); + } + + public void PostExitNotification() + { + if (_exitNotification == null) return; + NotificationManager.SharedInstance.PostNotification(_exitNotification, _pin); + } + + public void UnpinEntryNotification() + { + if (_entryNotification == null) return; + if (NotificationManager.SharedInstance.IsPinnedNotification(_entryNotification)) + { + NotificationManager.SharedInstance.UnpinNotification(_entryNotification); + } + } + + public void UnpinExitNotification() + { + if (_exitNotification == null) return; + if (NotificationManager.SharedInstance.IsPinnedNotification(_exitNotification)) + { + NotificationManager.SharedInstance.UnpinNotification(_exitNotification); + } + } + } +} diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index f4275a6e..9471df4c 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -98,6 +98,11 @@ namespace NewHorizons.External.Modules /// public RemoteInfo[] remotes; + /// + /// Add notification volumes to this planet + /// + public NotificationVolumeInfo[] notificationVolumes; + [JsonObject] public class ScatterInfo { @@ -1006,6 +1011,58 @@ namespace NewHorizons.External.Modules public string rename; } } + + [JsonObject] + public class NotificationVolumeInfo + { + /// + /// What the notification will show for. + /// + [DefaultValue("all")] public NotificationTarget target = NotificationTarget.All; + + /// + /// The location of this notification volume. Optional (will default to 0,0,0). + /// + public MVector3 position; + + /// + /// The radius of this notification volume. + /// + public float radius; + + /// + /// The notification that will play when you enter this volume. + /// + public NotificationInfo entryNotification; + + /// + /// The notification that will play when you exit this volume. + /// + public NotificationInfo exitNotification; + + + [JsonObject] + public class NotificationInfo + { + /// + /// The message that will be displayed. + /// + public string displayMessage; + + /// + /// The duration this notification will be displayed. + /// + [DefaultValue(5f)] public float duration = 5f; + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum NotificationTarget + { + [EnumMember(Value = @"all")] All = 0, + [EnumMember(Value = @"ship")] Ship = 1, + [EnumMember(Value = @"player")] Player = 2, + } + } } [JsonConverter(typeof(StringEnumConverter))] diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 4e56aedb..9b9bbb0d 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1001,6 +1001,13 @@ "items": { "$ref": "#/definitions/RemoteInfo" } + }, + "notificationVolumes": { + "type": "array", + "description": "Add notification volumes to this planet", + "items": { + "$ref": "#/definitions/NotificationVolumeInfo" + } } } }, @@ -2090,6 +2097,64 @@ } } }, + "NotificationVolumeInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "target": { + "description": "What the notification will show for.", + "default": "all", + "$ref": "#/definitions/NotificationTarget" + }, + "position": { + "description": "The location of this notification volume. Optional (will default to 0,0,0).", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this notification volume.", + "format": "float" + }, + "entryNotification": { + "description": "The notification that will play when you enter this volume.", + "$ref": "#/definitions/NotificationInfo" + }, + "exitNotification": { + "description": "The notification that will play when you exit this volume.", + "$ref": "#/definitions/NotificationInfo" + } + } + }, + "NotificationTarget": { + "type": "string", + "description": "", + "x-enumNames": [ + "All", + "Ship", + "Player" + ], + "enum": [ + "all", + "ship", + "player" + ] + }, + "NotificationInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "displayMessage": { + "type": "string", + "description": "The message that will be displayed." + }, + "duration": { + "type": "number", + "description": "The duration this notification will be displayed.", + "format": "float", + "default": 5.0 + } + } + }, "ReferenceFrameModule": { "type": "object", "additionalProperties": false, From 4ae90dcc25ddf5161e113717ef74653adbaebe9b Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 13:10:20 -0400 Subject: [PATCH 33/37] Reorganize to a volume module --- NewHorizons/Builder/Props/PropBuildManager.cs | 28 --- NewHorizons/Builder/ShipLog/RevealBuilder.cs | 18 +- .../{Props => Volumes}/AudioVolumeBuilder.cs | 4 +- .../NotificationVolumeBuilder.cs | 4 +- .../Builder/Volumes/VolumesBuildManager.cs | 47 +++++ NewHorizons/Components/NotificationVolume.cs | 2 +- NewHorizons/External/Configs/PlanetConfig.cs | 19 ++ NewHorizons/External/Modules/PropModule.cs | 168 +--------------- NewHorizons/External/Modules/VolumesModule.cs | 183 ++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 6 + 10 files changed, 272 insertions(+), 207 deletions(-) rename NewHorizons/Builder/{Props => Volumes}/AudioVolumeBuilder.cs (94%) rename NewHorizons/Builder/{Props => Volumes}/NotificationVolumeBuilder.cs (93%) create mode 100644 NewHorizons/Builder/Volumes/VolumesBuildManager.cs create mode 100644 NewHorizons/External/Modules/VolumesModule.cs diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 1c5afe4b..bda9684d 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -109,20 +109,6 @@ namespace NewHorizons.Builder.Props } } } - if (config.Props.reveal != null) - { - foreach (var revealInfo in config.Props.reveal) - { - try - { - RevealBuilder.Make(go, sector, revealInfo, mod); - } - catch (Exception ex) - { - Logger.LogError($"Couldn't make reveal location [{revealInfo.reveals}] for [{go.name}]:\n{ex}"); - } - } - } if (config.Props.entryLocation != null) { foreach (var entryLocationInfo in config.Props.entryLocation) @@ -207,13 +193,6 @@ namespace NewHorizons.Builder.Props } } } - if (config.Props.audioVolumes != null) - { - foreach (var audioVolume in config.Props.audioVolumes) - { - AudioVolumeBuilder.Make(go, sector, audioVolume, mod); - } - } if (config.Props.signals != null) { foreach (var signal in config.Props.signals) @@ -235,13 +214,6 @@ namespace NewHorizons.Builder.Props } } } - if (config.Props.notificationVolumes != null) - { - foreach (var notificationVolume in config.Props.notificationVolumes) - { - NotificationVolumeBuilder.Make(go, sector, notificationVolume, mod); - } - } } } } diff --git a/NewHorizons/Builder/ShipLog/RevealBuilder.cs b/NewHorizons/Builder/ShipLog/RevealBuilder.cs index 43133771..95f118b6 100644 --- a/NewHorizons/Builder/ShipLog/RevealBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RevealBuilder.cs @@ -7,18 +7,18 @@ namespace NewHorizons.Builder.ShipLog { public static class RevealBuilder { - public static void Make(GameObject go, Sector sector, PropModule.RevealInfo info, IModBehaviour mod) + public static void Make(GameObject go, Sector sector, VolumesModule.RevealVolumeInfo info, IModBehaviour mod) { var newRevealGO = MakeGameObject(go, sector, info, mod); switch (info.revealOn) { - case PropModule.RevealInfo.RevealVolumeType.Enter: + case VolumesModule.RevealVolumeInfo.RevealVolumeType.Enter: MakeTrigger(newRevealGO, sector, info, mod); break; - case PropModule.RevealInfo.RevealVolumeType.Observe: + case VolumesModule.RevealVolumeInfo.RevealVolumeType.Observe: MakeObservable(newRevealGO, sector, info, mod); break; - case PropModule.RevealInfo.RevealVolumeType.Snapshot: + case VolumesModule.RevealVolumeInfo.RevealVolumeType.Snapshot: MakeSnapshot(newRevealGO, sector, info, mod); break; default: @@ -28,7 +28,7 @@ namespace NewHorizons.Builder.ShipLog newRevealGO.SetActive(true); } - private static SphereShape MakeShape(GameObject go, PropModule.RevealInfo info, Shape.CollisionMode collisionMode) + private static SphereShape MakeShape(GameObject go, VolumesModule.RevealVolumeInfo info, Shape.CollisionMode collisionMode) { SphereShape newShape = go.AddComponent(); newShape.radius = info.radius; @@ -36,7 +36,7 @@ namespace NewHorizons.Builder.ShipLog return newShape; } - private static GameObject MakeGameObject(GameObject planetGO, Sector sector, PropModule.RevealInfo info, IModBehaviour mod) + private static GameObject MakeGameObject(GameObject planetGO, Sector sector, VolumesModule.RevealVolumeInfo info, IModBehaviour mod) { GameObject revealTriggerVolume = new GameObject("Reveal Volume (" + info.revealOn + ")"); revealTriggerVolume.SetActive(false); @@ -45,7 +45,7 @@ namespace NewHorizons.Builder.ShipLog return revealTriggerVolume; } - private static void MakeTrigger(GameObject go, Sector sector, PropModule.RevealInfo info, IModBehaviour mod) + private static void MakeTrigger(GameObject go, Sector sector, VolumesModule.RevealVolumeInfo info, IModBehaviour mod) { var shape = MakeShape(go, info, Shape.CollisionMode.Volume); @@ -65,7 +65,7 @@ namespace NewHorizons.Builder.ShipLog } } - private static void MakeObservable(GameObject go, Sector sector, PropModule.RevealInfo info, IModBehaviour mod) + private static void MakeObservable(GameObject go, Sector sector, VolumesModule.RevealVolumeInfo info, IModBehaviour mod) { go.layer = LayerMask.NameToLayer("Interactible"); @@ -96,7 +96,7 @@ namespace NewHorizons.Builder.ShipLog } } - private static void MakeSnapshot(GameObject go, Sector sector, PropModule.RevealInfo info, IModBehaviour mod) + private static void MakeSnapshot(GameObject go, Sector sector, VolumesModule.RevealVolumeInfo info, IModBehaviour mod) { var shape = MakeShape(go, info, Shape.CollisionMode.Manual); diff --git a/NewHorizons/Builder/Props/AudioVolumeBuilder.cs b/NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs similarity index 94% rename from NewHorizons/Builder/Props/AudioVolumeBuilder.cs rename to NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs index 9c5d0acc..b487670a 100644 --- a/NewHorizons/Builder/Props/AudioVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs @@ -9,11 +9,11 @@ using System.Threading.Tasks; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Builder.Props +namespace NewHorizons.Builder.Volumes { public static class AudioVolumeBuilder { - public static AudioVolume Make(GameObject planetGO, Sector sector, PropModule.AudioVolumeInfo info, IModBehaviour mod) + public static AudioVolume Make(GameObject planetGO, Sector sector, VolumesModule.AudioVolumeInfo info, IModBehaviour mod) { var go = new GameObject("AudioVolume"); go.SetActive(false); diff --git a/NewHorizons/Builder/Props/NotificationVolumeBuilder.cs b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs similarity index 93% rename from NewHorizons/Builder/Props/NotificationVolumeBuilder.cs rename to NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs index eabb1519..c91e4161 100644 --- a/NewHorizons/Builder/Props/NotificationVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs @@ -11,11 +11,11 @@ using UnityEngine; using Logger = NewHorizons.Utility.Logger; using NHNotificationVolume = NewHorizons.Components.NotificationVolume; -namespace NewHorizons.Builder.Props +namespace NewHorizons.Builder.Volumes { public static class NotificationVolumeBuilder { - public static NHNotificationVolume Make(GameObject planetGO, Sector sector, PropModule.NotificationVolumeInfo info, IModBehaviour mod) + public static NHNotificationVolume Make(GameObject planetGO, Sector sector, VolumesModule.NotificationVolumeInfo info, IModBehaviour mod) { var go = new GameObject("NotificationVolume"); go.SetActive(false); diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs new file mode 100644 index 00000000..5197aaf4 --- /dev/null +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -0,0 +1,47 @@ +using NewHorizons.Builder.Body; +using NewHorizons.Builder.ShipLog; +using NewHorizons.Builder.Volumes; +using NewHorizons.External.Configs; +using OWML.Common; +using System; +using System.Collections.Generic; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Builder.Volumes +{ + public static class VolumesBuildManager + { + public static void Make(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod) + { + if (config.Volumes.revealVolumes != null) + { + foreach (var revealInfo in config.Volumes.revealVolumes) + { + try + { + RevealBuilder.Make(go, sector, revealInfo, mod); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't make reveal location [{revealInfo.reveals}] for [{go.name}]:\n{ex}"); + } + } + } + if (config.Volumes.audioVolumes != null) + { + foreach (var audioVolume in config.Volumes.audioVolumes) + { + AudioVolumeBuilder.Make(go, sector, audioVolume, mod); + } + } + if (config.Volumes.notificationVolumes != null) + { + foreach (var notificationVolume in config.Volumes.notificationVolumes) + { + NotificationVolumeBuilder.Make(go, sector, notificationVolume, mod); + } + } + } + } +} diff --git a/NewHorizons/Components/NotificationVolume.cs b/NewHorizons/Components/NotificationVolume.cs index 99a35705..2dc81ed1 100644 --- a/NewHorizons/Components/NotificationVolume.cs +++ b/NewHorizons/Components/NotificationVolume.cs @@ -32,7 +32,7 @@ namespace NewHorizons.Components public void SetPinned(bool pin) => _pin = pin; - public void SetTarget(NewHorizons.External.Modules.PropModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); + public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); public void SetTarget(NotificationTarget target) => _target = target; diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 2b071244..4ea8a886 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -169,6 +169,11 @@ namespace NewHorizons.External.Configs /// public WaterModule Water; + /// + /// Add various volumes on this body + /// + public VolumesModule Volumes; + /// /// Extra data that may be used by extension mods /// @@ -317,6 +322,20 @@ namespace NewHorizons.External.Configs if (tornado.downwards) tornado.type = PropModule.TornadoInfo.TornadoType.Downwards; + if (Props?.audioVolumes != null) + { + if (Volumes == null) Volumes = new VolumesModule(); + if (Volumes.audioVolumes == null) Volumes.audioVolumes = new VolumesModule.AudioVolumeInfo[0]; + Volumes.audioVolumes = Volumes.audioVolumes.Concat(Props.audioVolumes).ToArray(); + } + + if (Props?.reveal != null) + { + if (Volumes == null) Volumes = new VolumesModule(); + if (Volumes.revealVolumes == null) Volumes.revealVolumes = new VolumesModule.RevealVolumeInfo[0]; + Volumes.revealVolumes = Volumes.revealVolumes.Concat(Props.reveal).ToArray(); + } + if (Base.sphereOfInfluence != 0f) Base.soiOverride = Base.sphereOfInfluence; // Moved a bunch of stuff off of shiplog module to star system module because it didnt exist when we made this diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 9471df4c..932b1bc0 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -48,11 +48,6 @@ namespace NewHorizons.External.Modules /// public RaftInfo[] rafts; - /// - /// Add triggers that reveal parts of the ship log on this planet - /// - public RevealInfo[] reveal; - /// /// Scatter props around this planet's surface /// @@ -83,11 +78,6 @@ namespace NewHorizons.External.Modules /// public SingularityModule[] singularities; - /// - /// Add audio volumes to this planet - /// - public AudioVolumeInfo[] audioVolumes; - /// /// Add signalscope signals to this planet /// @@ -98,10 +88,9 @@ namespace NewHorizons.External.Modules /// public RemoteInfo[] remotes; - /// - /// Add notification volumes to this planet - /// - public NotificationVolumeInfo[] notificationVolumes; + [Obsolete("reveal is deprecated. Use Volumes->revealVolumes instead.")] public VolumesModule.RevealVolumeInfo[] reveal; + + [Obsolete("audioVolumes is deprecated. Use Volumes->audioVolumes instead.")] public VolumesModule.AudioVolumeInfo[] audioVolumes; [JsonObject] public class ScatterInfo @@ -438,55 +427,6 @@ namespace NewHorizons.External.Modules public string xmlFile; } - [JsonObject] - public class RevealInfo - { - [JsonConverter(typeof(StringEnumConverter))] - public enum RevealVolumeType - { - [EnumMember(Value = @"enter")] Enter = 0, - - [EnumMember(Value = @"observe")] Observe = 1, - - [EnumMember(Value = @"snapshot")] Snapshot = 2 - } - - /// - /// The max view angle (in degrees) the player can see the volume with to unlock the fact (`observe` only) - /// - public float maxAngle = 180f; // Observe Only - - /// - /// The max distance the user can be away from the volume to reveal the fact (`snapshot` and `observe` only) - /// - public float maxDistance = -1f; // Snapshot & Observe Only - - /// - /// The position to place this volume at - /// - public MVector3 position; - - /// - /// The radius of this reveal volume - /// - public float radius = 1f; - - /// - /// What needs to be done to the volume to unlock the facts - /// - [DefaultValue("enter")] public RevealVolumeType revealOn = RevealVolumeType.Enter; - - /// - /// A list of facts to reveal - /// - public string[] reveals; - - /// - /// An achievement to unlock. Optional. - /// - public string achievementID; - } - [JsonObject] public class EntryLocationInfo { @@ -823,35 +763,6 @@ namespace NewHorizons.External.Modules [DefaultValue(1f)] public float probability = 1f; } - [JsonObject] - public class AudioVolumeInfo - { - /// - /// The location of this audio volume. Optional (will default to 0,0,0). - /// - public MVector3 position; - - /// - /// The radius of this audio volume - /// - public float radius; - - /// - /// The audio to use. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list. - /// - public string audio; - - /// - /// The audio track of this audio volume - /// - [DefaultValue("environment")] public AudioMixerTrackName track = AudioMixerTrackName.Environment; - - /// - /// Whether to loop this audio while in this audio volume or just play it once - /// - [DefaultValue(true)] public bool loop = true; - } - [JsonObject] public class RemoteInfo { @@ -1011,78 +922,5 @@ namespace NewHorizons.External.Modules public string rename; } } - - [JsonObject] - public class NotificationVolumeInfo - { - /// - /// What the notification will show for. - /// - [DefaultValue("all")] public NotificationTarget target = NotificationTarget.All; - - /// - /// The location of this notification volume. Optional (will default to 0,0,0). - /// - public MVector3 position; - - /// - /// The radius of this notification volume. - /// - public float radius; - - /// - /// The notification that will play when you enter this volume. - /// - public NotificationInfo entryNotification; - - /// - /// The notification that will play when you exit this volume. - /// - public NotificationInfo exitNotification; - - - [JsonObject] - public class NotificationInfo - { - /// - /// The message that will be displayed. - /// - public string displayMessage; - - /// - /// The duration this notification will be displayed. - /// - [DefaultValue(5f)] public float duration = 5f; - } - - [JsonConverter(typeof(StringEnumConverter))] - public enum NotificationTarget - { - [EnumMember(Value = @"all")] All = 0, - [EnumMember(Value = @"ship")] Ship = 1, - [EnumMember(Value = @"player")] Player = 2, - } - } - } - - [JsonConverter(typeof(StringEnumConverter))] - public enum AudioMixerTrackName - { - [EnumMember(Value = @"undefined")] Undefined = 0, - [EnumMember(Value = @"menu")] Menu = 1, - [EnumMember(Value = @"music")] Music = 2, - [EnumMember(Value = @"environment")] Environment = 4, - [EnumMember(Value = @"environmentUnfiltered")] Environment_Unfiltered = 5, - [EnumMember(Value = @"endTimesSfx")] EndTimes_SFX = 8, - [EnumMember(Value = @"signal")] Signal = 16, - [EnumMember(Value = @"death")] Death = 32, - [EnumMember(Value = @"player")] Player = 64, - [EnumMember(Value = @"playerExternal")] Player_External = 65, - [EnumMember(Value = @"ship")] Ship = 128, - [EnumMember(Value = @"map")] Map = 256, - [EnumMember(Value = @"endTimesMusic")] EndTimes_Music = 512, - [EnumMember(Value = @"muffleWhileRafting")] MuffleWhileRafting = 1024, - [EnumMember(Value = @"muffleIndoors")] MuffleIndoors = 2048, - [EnumMember(Value = @"slideReelMusic")] SlideReelMusic = 4096, } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs new file mode 100644 index 00000000..25bba3a5 --- /dev/null +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -0,0 +1,183 @@ +using NewHorizons.Utility; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class VolumesModule + { + /// + /// Add audio volumes to this planet + /// + public AudioVolumeInfo[] audioVolumes; + + /// + /// Add notification volumes to this planet + /// + public NotificationVolumeInfo[] notificationVolumes; + + /// + /// Add triggers that reveal parts of the ship log on this planet + /// + public RevealVolumeInfo[] revealVolumes; + + [JsonObject] + public class RevealVolumeInfo + { + [JsonConverter(typeof(StringEnumConverter))] + public enum RevealVolumeType + { + [EnumMember(Value = @"enter")] Enter = 0, + + [EnumMember(Value = @"observe")] Observe = 1, + + [EnumMember(Value = @"snapshot")] Snapshot = 2 + } + + /// + /// The max view angle (in degrees) the player can see the volume with to unlock the fact (`observe` only) + /// + public float maxAngle = 180f; // Observe Only + + /// + /// The max distance the user can be away from the volume to reveal the fact (`snapshot` and `observe` only) + /// + public float maxDistance = -1f; // Snapshot & Observe Only + + /// + /// The position to place this volume at + /// + public MVector3 position; + + /// + /// The radius of this reveal volume + /// + public float radius = 1f; + + /// + /// What needs to be done to the volume to unlock the facts + /// + [DefaultValue("enter")] public RevealVolumeType revealOn = RevealVolumeType.Enter; + + /// + /// A list of facts to reveal + /// + public string[] reveals; + + /// + /// An achievement to unlock. Optional. + /// + public string achievementID; + } + + [JsonObject] + public class AudioVolumeInfo + { + /// + /// The location of this audio volume. Optional (will default to 0,0,0). + /// + public MVector3 position; + + /// + /// The radius of this audio volume + /// + public float radius; + + /// + /// The audio to use. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list. + /// + public string audio; + + /// + /// The audio track of this audio volume + /// + [DefaultValue("environment")] public AudioMixerTrackName track = AudioMixerTrackName.Environment; + + /// + /// Whether to loop this audio while in this audio volume or just play it once + /// + [DefaultValue(true)] public bool loop = true; + } + + [JsonObject] + public class NotificationVolumeInfo + { + /// + /// What the notification will show for. + /// + [DefaultValue("all")] public NotificationTarget target = NotificationTarget.All; + + /// + /// The location of this notification volume. Optional (will default to 0,0,0). + /// + public MVector3 position; + + /// + /// The radius of this notification volume. + /// + public float radius; + + /// + /// The notification that will play when you enter this volume. + /// + public NotificationInfo entryNotification; + + /// + /// The notification that will play when you exit this volume. + /// + public NotificationInfo exitNotification; + + + [JsonObject] + public class NotificationInfo + { + /// + /// The message that will be displayed. + /// + public string displayMessage; + + /// + /// The duration this notification will be displayed. + /// + [DefaultValue(5f)] public float duration = 5f; + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum NotificationTarget + { + [EnumMember(Value = @"all")] All = 0, + [EnumMember(Value = @"ship")] Ship = 1, + [EnumMember(Value = @"player")] Player = 2, + } + } + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum AudioMixerTrackName + { + [EnumMember(Value = @"undefined")] Undefined = 0, + [EnumMember(Value = @"menu")] Menu = 1, + [EnumMember(Value = @"music")] Music = 2, + [EnumMember(Value = @"environment")] Environment = 4, + [EnumMember(Value = @"environmentUnfiltered")] Environment_Unfiltered = 5, + [EnumMember(Value = @"endTimesSfx")] EndTimes_SFX = 8, + [EnumMember(Value = @"signal")] Signal = 16, + [EnumMember(Value = @"death")] Death = 32, + [EnumMember(Value = @"player")] Player = 64, + [EnumMember(Value = @"playerExternal")] Player_External = 65, + [EnumMember(Value = @"ship")] Ship = 128, + [EnumMember(Value = @"map")] Map = 256, + [EnumMember(Value = @"endTimesMusic")] EndTimes_Music = 512, + [EnumMember(Value = @"muffleWhileRafting")] MuffleWhileRafting = 1024, + [EnumMember(Value = @"muffleIndoors")] MuffleIndoors = 2048, + [EnumMember(Value = @"slideReelMusic")] SlideReelMusic = 4096, + } +} diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index ba0ea8f8..f30c4778 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -3,6 +3,7 @@ using NewHorizons.Builder.Body; using NewHorizons.Builder.General; using NewHorizons.Builder.Orbital; using NewHorizons.Builder.Props; +using NewHorizons.Builder.Volumes; using NewHorizons.Components; using NewHorizons.Components.Orbital; using NewHorizons.OtherMods.OWRichPresence; @@ -608,6 +609,11 @@ namespace NewHorizons.Handlers PropBuildManager.Make(go, sector, rb, body.Config, body.Mod); } + if (body.Config.Volumes != null) + { + VolumesBuildManager.Make(go, sector, body.Config, body.Mod); + } + if (body.Config.Funnel != null) { FunnelBuilder.Make(go, go.GetComponentInChildren(), rb, body.Config.Funnel); From 0921b23f8fec1013a1c1b0a00b011d7a7c1a4810 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 17:28:38 +0000 Subject: [PATCH 34/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 416 ++++++++++++++------------- 1 file changed, 213 insertions(+), 203 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 9b9bbb0d..a032ac40 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -128,6 +128,10 @@ "description": "Add water to this planet", "$ref": "#/definitions/WaterModule" }, + "Volumes": { + "description": "Add various volumes on this body", + "$ref": "#/definitions/VolumesModule" + }, "extras": { "type": "object", "description": "Extra data that may be used by extension mods", @@ -932,13 +936,6 @@ "$ref": "#/definitions/RaftInfo" } }, - "reveal": { - "type": "array", - "description": "Add triggers that reveal parts of the ship log on this planet", - "items": { - "$ref": "#/definitions/RevealInfo" - } - }, "scatter": { "type": "array", "description": "Scatter props around this planet's surface", @@ -981,13 +978,6 @@ "$ref": "#/definitions/SingularityModule" } }, - "audioVolumes": { - "type": "array", - "description": "Add audio volumes to this planet", - "items": { - "$ref": "#/definitions/AudioVolumeInfo" - } - }, "signals": { "type": "array", "description": "Add signalscope signals to this planet", @@ -1001,13 +991,6 @@ "items": { "$ref": "#/definitions/RemoteInfo" } - }, - "notificationVolumes": { - "type": "array", - "description": "Add notification volumes to this planet", - "items": { - "$ref": "#/definitions/NotificationVolumeInfo" - } } } }, @@ -1351,61 +1334,6 @@ } } }, - "RevealInfo": { - "type": "object", - "additionalProperties": false, - "properties": { - "maxAngle": { - "type": "number", - "description": "The max view angle (in degrees) the player can see the volume with to unlock the fact (`observe` only)", - "format": "float" - }, - "maxDistance": { - "type": "number", - "description": "The max distance the user can be away from the volume to reveal the fact (`snapshot` and `observe` only)", - "format": "float" - }, - "position": { - "description": "The position to place this volume at", - "$ref": "#/definitions/MVector3" - }, - "radius": { - "type": "number", - "description": "The radius of this reveal volume", - "format": "float" - }, - "revealOn": { - "description": "What needs to be done to the volume to unlock the facts", - "default": "enter", - "$ref": "#/definitions/RevealVolumeType" - }, - "reveals": { - "type": "array", - "description": "A list of facts to reveal", - "items": { - "type": "string" - } - }, - "achievementID": { - "type": "string", - "description": "An achievement to unlock. Optional." - } - } - }, - "RevealVolumeType": { - "type": "string", - "description": "", - "x-enumNames": [ - "Enter", - "Observe", - "Snapshot" - ], - "enum": [ - "enter", - "observe", - "snapshot" - ] - }, "ScatterInfo": { "type": "object", "additionalProperties": false, @@ -1815,75 +1743,6 @@ "whiteHole" ] }, - "AudioVolumeInfo": { - "type": "object", - "additionalProperties": false, - "properties": { - "position": { - "description": "The location of this audio volume. Optional (will default to 0,0,0).", - "$ref": "#/definitions/MVector3" - }, - "radius": { - "type": "number", - "description": "The radius of this audio volume", - "format": "float" - }, - "audio": { - "type": "string", - "description": "The audio to use. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list." - }, - "track": { - "description": "The audio track of this audio volume", - "default": "environment", - "$ref": "#/definitions/AudioMixerTrackName" - }, - "loop": { - "type": "boolean", - "description": "Whether to loop this audio while in this audio volume or just play it once", - "default": true - } - } - }, - "AudioMixerTrackName": { - "type": "string", - "description": "", - "x-enumNames": [ - "Undefined", - "Menu", - "Music", - "Environment", - "Environment_Unfiltered", - "EndTimes_SFX", - "Signal", - "Death", - "Player", - "Player_External", - "Ship", - "Map", - "EndTimes_Music", - "MuffleWhileRafting", - "MuffleIndoors", - "SlideReelMusic" - ], - "enum": [ - "undefined", - "menu", - "music", - "environment", - "environmentUnfiltered", - "endTimesSfx", - "signal", - "death", - "player", - "playerExternal", - "ship", - "map", - "endTimesMusic", - "muffleWhileRafting", - "muffleIndoors", - "slideReelMusic" - ] - }, "SignalInfo": { "type": "object", "additionalProperties": false, @@ -2097,64 +1956,6 @@ } } }, - "NotificationVolumeInfo": { - "type": "object", - "additionalProperties": false, - "properties": { - "target": { - "description": "What the notification will show for.", - "default": "all", - "$ref": "#/definitions/NotificationTarget" - }, - "position": { - "description": "The location of this notification volume. Optional (will default to 0,0,0).", - "$ref": "#/definitions/MVector3" - }, - "radius": { - "type": "number", - "description": "The radius of this notification volume.", - "format": "float" - }, - "entryNotification": { - "description": "The notification that will play when you enter this volume.", - "$ref": "#/definitions/NotificationInfo" - }, - "exitNotification": { - "description": "The notification that will play when you exit this volume.", - "$ref": "#/definitions/NotificationInfo" - } - } - }, - "NotificationTarget": { - "type": "string", - "description": "", - "x-enumNames": [ - "All", - "Ship", - "Player" - ], - "enum": [ - "all", - "ship", - "player" - ] - }, - "NotificationInfo": { - "type": "object", - "additionalProperties": false, - "properties": { - "displayMessage": { - "type": "string", - "description": "The message that will be displayed." - }, - "duration": { - "type": "number", - "description": "The duration this notification will be displayed.", - "format": "float", - "default": 5.0 - } - } - }, "ReferenceFrameModule": { "type": "object", "additionalProperties": false, @@ -2580,6 +2381,215 @@ "$ref": "#/definitions/MColor" } } + }, + "VolumesModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "audioVolumes": { + "type": "array", + "description": "Add audio volumes to this planet", + "items": { + "$ref": "#/definitions/AudioVolumeInfo" + } + }, + "notificationVolumes": { + "type": "array", + "description": "Add notification volumes to this planet", + "items": { + "$ref": "#/definitions/NotificationVolumeInfo" + } + }, + "revealVolumes": { + "type": "array", + "description": "Add triggers that reveal parts of the ship log on this planet", + "items": { + "$ref": "#/definitions/RevealVolumeInfo" + } + } + } + }, + "AudioVolumeInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "position": { + "description": "The location of this audio volume. Optional (will default to 0,0,0).", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this audio volume", + "format": "float" + }, + "audio": { + "type": "string", + "description": "The audio to use. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list." + }, + "track": { + "description": "The audio track of this audio volume", + "default": "environment", + "$ref": "#/definitions/AudioMixerTrackName" + }, + "loop": { + "type": "boolean", + "description": "Whether to loop this audio while in this audio volume or just play it once", + "default": true + } + } + }, + "AudioMixerTrackName": { + "type": "string", + "description": "", + "x-enumNames": [ + "Undefined", + "Menu", + "Music", + "Environment", + "Environment_Unfiltered", + "EndTimes_SFX", + "Signal", + "Death", + "Player", + "Player_External", + "Ship", + "Map", + "EndTimes_Music", + "MuffleWhileRafting", + "MuffleIndoors", + "SlideReelMusic" + ], + "enum": [ + "undefined", + "menu", + "music", + "environment", + "environmentUnfiltered", + "endTimesSfx", + "signal", + "death", + "player", + "playerExternal", + "ship", + "map", + "endTimesMusic", + "muffleWhileRafting", + "muffleIndoors", + "slideReelMusic" + ] + }, + "NotificationVolumeInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "target": { + "description": "What the notification will show for.", + "default": "all", + "$ref": "#/definitions/NotificationTarget" + }, + "position": { + "description": "The location of this notification volume. Optional (will default to 0,0,0).", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this notification volume.", + "format": "float" + }, + "entryNotification": { + "description": "The notification that will play when you enter this volume.", + "$ref": "#/definitions/NotificationInfo" + }, + "exitNotification": { + "description": "The notification that will play when you exit this volume.", + "$ref": "#/definitions/NotificationInfo" + } + } + }, + "NotificationTarget": { + "type": "string", + "description": "", + "x-enumNames": [ + "All", + "Ship", + "Player" + ], + "enum": [ + "all", + "ship", + "player" + ] + }, + "NotificationInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "displayMessage": { + "type": "string", + "description": "The message that will be displayed." + }, + "duration": { + "type": "number", + "description": "The duration this notification will be displayed.", + "format": "float", + "default": 5.0 + } + } + }, + "RevealVolumeInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "maxAngle": { + "type": "number", + "description": "The max view angle (in degrees) the player can see the volume with to unlock the fact (`observe` only)", + "format": "float" + }, + "maxDistance": { + "type": "number", + "description": "The max distance the user can be away from the volume to reveal the fact (`snapshot` and `observe` only)", + "format": "float" + }, + "position": { + "description": "The position to place this volume at", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this reveal volume", + "format": "float" + }, + "revealOn": { + "description": "What needs to be done to the volume to unlock the facts", + "default": "enter", + "$ref": "#/definitions/RevealVolumeType" + }, + "reveals": { + "type": "array", + "description": "A list of facts to reveal", + "items": { + "type": "string" + } + }, + "achievementID": { + "type": "string", + "description": "An achievement to unlock. Optional." + } + } + }, + "RevealVolumeType": { + "type": "string", + "description": "", + "x-enumNames": [ + "Enter", + "Observe", + "Snapshot" + ], + "enum": [ + "enter", + "observe", + "snapshot" + ] } }, "$docs": { From 2f7eb0c6957dc1b263b1d662ab64a8207a02b9b5 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 13:44:35 -0400 Subject: [PATCH 35/37] Add hazard volumes --- .../Builder/Volumes/HazardVolumeBuilder.cs | 40 +++++++++++++ .../Builder/Volumes/VolumesBuildManager.cs | 9 ++- NewHorizons/External/Modules/VolumesModule.cs | 60 +++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs diff --git a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs new file mode 100644 index 00000000..2f35c6ab --- /dev/null +++ b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs @@ -0,0 +1,40 @@ +using NewHorizons.External.Modules; +using OWML.Common; +using OWML.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace NewHorizons.Builder.Volumes +{ + public static class HazardVolumeBuilder + { + public static HazardVolume Make(GameObject planetGO, Sector sector, OWRigidbody owrb, VolumesModule.HazardVolumeInfo info, IModBehaviour mod) + { + var go = new GameObject("HazardVolume"); + go.SetActive(false); + + go.transform.parent = sector?.transform ?? planetGO.transform; + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); + go.layer = LayerMask.NameToLayer("BasicEffectVolume"); + + var shape = go.AddComponent(); + shape.radius = info.radius; + + var owTriggerVolume = go.AddComponent(); + owTriggerVolume._shape = shape; + + var hazardVolume = go.AddComponent(); + hazardVolume._attachedBody = owrb; + hazardVolume._type = EnumUtils.Parse(info.type.ToString(), HazardVolume.HazardType.GENERAL); + hazardVolume._damagePerSecond = info.damagePerSecond; + hazardVolume._firstContactDamageType = EnumUtils.Parse(info.firstContactDamage.ToString(), InstantDamageType.Impact); + hazardVolume._firstContactDamage = info.firstContactDamage; + + go.SetActive(true); + + return hazardVolume; + } + } +} diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index 5197aaf4..f7a664b9 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -12,7 +12,7 @@ namespace NewHorizons.Builder.Volumes { public static class VolumesBuildManager { - public static void Make(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod) + public static void Make(GameObject go, Sector sector, OWRigidbody planetBody, PlanetConfig config, IModBehaviour mod) { if (config.Volumes.revealVolumes != null) { @@ -42,6 +42,13 @@ namespace NewHorizons.Builder.Volumes NotificationVolumeBuilder.Make(go, sector, notificationVolume, mod); } } + if (config.Volumes.hazardVolumes != null) + { + foreach (var hazardVolume in config.Volumes.hazardVolumes) + { + HazardVolumeBuilder.Make(go, sector, planetBody, hazardVolume, mod); + } + } } } } diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index 25bba3a5..fe8d29fb 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -19,6 +19,11 @@ namespace NewHorizons.External.Modules /// public AudioVolumeInfo[] audioVolumes; + /// + /// Add hazard volumes to this planet + /// + public HazardVolumeInfo[] hazardVolumes; + /// /// Add notification volumes to this planet /// @@ -158,6 +163,61 @@ namespace NewHorizons.External.Modules [EnumMember(Value = @"player")] Player = 2, } } + + [JsonObject] + public class HazardVolumeInfo + { + /// + /// The location of this hazard volume. Optional (will default to 0,0,0). + /// + public MVector3 position; + + /// + /// The radius of this hazard volume. + /// + public float radius; + + /// + /// The type of hazard for this volume. + /// + [DefaultValue("general")] public HazardType type = HazardType.GENERAL; + + /// + /// The amount of damage you will take per second while inside this volume. + /// + [DefaultValue(10f)] public float damagePerSecond = 10f; + + /// + /// The type of damage you will take when you first touch this volume. + /// + [DefaultValue("impact")] public InstantDamageType _firstContactDamageType = InstantDamageType.Impact; + + /// + /// The amount of damage you will take when you first touch this volume. + /// + public float firstContactDamage; + + [JsonConverter(typeof(StringEnumConverter))] + public enum HazardType + { + [EnumMember(Value = @"none")] NONE = 0, + [EnumMember(Value = @"general")] GENERAL = 1, + [EnumMember(Value = @"darkMatter")] DARKMATTER = 2, + [EnumMember(Value = @"heat")] HEAT = 4, + [EnumMember(Value = @"fire")] FIRE = 8, + [EnumMember(Value = @"sandfall")] SANDFALL = 16, + [EnumMember(Value = @"electricity")] ELECTRICITY = 32, + [EnumMember(Value = @"rapids")] RAPIDS = 64 + } + + [JsonConverter(typeof(StringEnumConverter))] + public enum InstantDamageType + { + [EnumMember(Value = @"impact")] Impact, + [EnumMember(Value = @"puncture")] Puncture, + [EnumMember(Value = @"electrical")] Electrical + } + } } [JsonConverter(typeof(StringEnumConverter))] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index f30c4778..67700c36 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -611,7 +611,7 @@ namespace NewHorizons.Handlers if (body.Config.Volumes != null) { - VolumesBuildManager.Make(go, sector, body.Config, body.Mod); + VolumesBuildManager.Make(go, sector, rb, body.Config, body.Mod); } if (body.Config.Funnel != null) From 1158863bb4ab36283d95fafcb81498544bbb8bc6 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 13:47:17 -0400 Subject: [PATCH 36/37] Oops --- NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs | 2 +- NewHorizons/External/Modules/VolumesModule.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs index 2f35c6ab..67c6f22c 100644 --- a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs @@ -29,7 +29,7 @@ namespace NewHorizons.Builder.Volumes hazardVolume._attachedBody = owrb; hazardVolume._type = EnumUtils.Parse(info.type.ToString(), HazardVolume.HazardType.GENERAL); hazardVolume._damagePerSecond = info.damagePerSecond; - hazardVolume._firstContactDamageType = EnumUtils.Parse(info.firstContactDamage.ToString(), InstantDamageType.Impact); + hazardVolume._firstContactDamageType = EnumUtils.Parse(info.firstContactDamageType.ToString(), InstantDamageType.Impact); hazardVolume._firstContactDamage = info.firstContactDamage; go.SetActive(true); diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index fe8d29fb..43059fbf 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -190,7 +190,7 @@ namespace NewHorizons.External.Modules /// /// The type of damage you will take when you first touch this volume. /// - [DefaultValue("impact")] public InstantDamageType _firstContactDamageType = InstantDamageType.Impact; + [DefaultValue("impact")] public InstantDamageType firstContactDamageType = InstantDamageType.Impact; /// /// The amount of damage you will take when you first touch this volume. From 31014ee2220867bdc6aba000103cc0c40ec799dd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 17:49:51 +0000 Subject: [PATCH 37/37] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index a032ac40..85fabcd8 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2393,6 +2393,13 @@ "$ref": "#/definitions/AudioVolumeInfo" } }, + "hazardVolumes": { + "type": "array", + "description": "Add hazard volumes to this planet", + "items": { + "$ref": "#/definitions/HazardVolumeInfo" + } + }, "notificationVolumes": { "type": "array", "description": "Add notification volumes to this planet", @@ -2478,6 +2485,80 @@ "slideReelMusic" ] }, + "HazardVolumeInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "position": { + "description": "The location of this hazard volume. Optional (will default to 0,0,0).", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this hazard volume.", + "format": "float" + }, + "type": { + "description": "The type of hazard for this volume.", + "default": "general", + "$ref": "#/definitions/HazardType" + }, + "damagePerSecond": { + "type": "number", + "description": "The amount of damage you will take per second while inside this volume.", + "format": "float", + "default": 10.0 + }, + "firstContactDamageType": { + "description": "The type of damage you will take when you first touch this volume.", + "default": "impact", + "$ref": "#/definitions/InstantDamageType" + }, + "firstContactDamage": { + "type": "number", + "description": "The amount of damage you will take when you first touch this volume.", + "format": "float" + } + } + }, + "HazardType": { + "type": "string", + "description": "", + "x-enumNames": [ + "NONE", + "GENERAL", + "DARKMATTER", + "HEAT", + "FIRE", + "SANDFALL", + "ELECTRICITY", + "RAPIDS" + ], + "enum": [ + "none", + "general", + "darkMatter", + "heat", + "fire", + "sandfall", + "electricity", + "rapids" + ] + }, + "InstantDamageType": { + "type": "string", + "description": "", + "x-enumNames": [ + "Impact", + "Puncture", + "Electrical" + ], + "enum": [ + "impact", + "puncture", + "electrical" + ] + }, "NotificationVolumeInfo": { "type": "object", "additionalProperties": false,