Skip to content

Commit

Permalink
Merge branch 'main' into hawkbar-docs-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawkbat committed Apr 13, 2024
2 parents bd3560b + fe7be24 commit 3d630b2
Show file tree
Hide file tree
Showing 43 changed files with 429 additions and 203 deletions.
Binary file modified NewHorizons/Assets/DefaultMapModeStar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion NewHorizons/Assets/addon-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Trifid#Tester\n#Programmer",
"Nageld#Programmer",
"Ernesto#Fish",
"With help from#Raicuparta\n#dgarroDC\n#jtsalomo\n#and the modding community",
"With help from#Raicuparta\n#dgarroDC\n#jtsalomo\n#coderCleric\n#TRSasasusu\n#and the modding community",
" ",
"Based off Marshmallow made by#_nebula",
"With help from#AmazingAlek\n#Raicuparta\n#and the Outer Wilds discord server",
Expand Down
7 changes: 5 additions & 2 deletions NewHorizons/Builder/Atmosphere/FogBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.Utility;
using NewHorizons.Utility.Files;
using OWML.Common;
using System;
using UnityEngine;

namespace NewHorizons.Builder.Atmosphere
{
public static class FogBuilder
Expand All @@ -26,7 +26,9 @@ public static class FogBuilder

internal static void InitPrefabs()
{
if (_ramp == null) _ramp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/FogColorRamp.png");
// Checking null here it was getting destroyed and wouldnt reload and never worked outside of the first loop
// GetTexture caches itself anyway so it doesn't matter that this gets called multiple times
_ramp = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/FogColorRamp.png");

if (_isInit) return;

Expand Down Expand Up @@ -73,6 +75,7 @@ public static PlanetaryFogController Make(GameObject planetGO, Sector sector, At
atmo.fogRampPath != null ? ImageUtilities.GetTexture(mod, atmo.fogRampPath) :
atmo.fogTint != null ? ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor()) :
_ramp;

PFC.fogColorRampTexture = colorRampTexture;
PFC.fogColorRampIntensity = 1f;
if (atmo.fogTint != null)
Expand Down
1 change: 1 addition & 0 deletions NewHorizons/Builder/Atmosphere/SunOverrideBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.VariableSize;
using UnityEngine;

namespace NewHorizons.Builder.Atmosphere
{
public static class SunOverrideBuilder
Expand Down
8 changes: 6 additions & 2 deletions NewHorizons/Builder/General/AstroObjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using NewHorizons.Components;
using NewHorizons.Components.Orbital;
using NewHorizons.External.Configs;
using NewHorizons.External;
using NewHorizons.Utility.OWML;
using UnityEngine;

namespace NewHorizons.Builder.General
{
public static class AstroObjectBuilder
{
public static NHAstroObject Make(GameObject body, AstroObject primaryBody, PlanetConfig config, bool isVanilla)
public static NHAstroObject Make(GameObject body, AstroObject primaryBody, NewHorizonsBody nhBody, bool isVanilla)
{
NHAstroObject astroObject = body.AddComponent<NHAstroObject>();
astroObject.modUniqueName = nhBody.Mod.ModHelper.Manifest.UniqueName;

var config = nhBody.Config;

astroObject.isVanilla = isVanilla;
astroObject.HideDisplayName = !config.Base.hasMapMarker;
astroObject.invulnerableToSun = config.Base.invulnerableToSun;
Expand Down
2 changes: 2 additions & 0 deletions NewHorizons/Builder/General/RFVolumeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static GameObject Make(GameObject planetGO, OWRigidbody owrb, float spher
{
// We can't not build a reference frame volume, Cloak requires one to be there
module.maxTargetDistance = 0f;
module.targetWhenClose = true;
module.targetColliderRadius = 0f;
module.hideInMap = true;
owrb.SetIsTargetable(false);
}
Expand Down
53 changes: 31 additions & 22 deletions NewHorizons/Builder/Props/Audio/SignalBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using HarmonyLib;
using NewHorizons.External;
using NewHorizons.External.Modules.Props.Audio;
using NewHorizons.Utility;
using NewHorizons.Utility.OWML;
using OWML.Common;
using OWML.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -36,27 +38,16 @@ public static void Init()
};
NumberOfFrequencies = EnumUtils.GetValues<SignalFrequency>().Length;

_qmSignals = new (){ SearchUtilities.Find("QuantumMoon_Body/Signal_Quantum").GetComponent<AudioSignal>() };
_qmSignals = new () { SearchUtilities.Find("QuantumMoon_Body/Signal_Quantum").GetComponent<AudioSignal>() };
_cloakedSignals = new();

Initialized = true;

SceneManager.sceneUnloaded -= OnSceneUnloaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
Main.Instance.OnStarSystemLoaded.RemoveListener(OnStarSystemLoaded);
Main.Instance.OnStarSystemLoaded.AddListener(OnStarSystemLoaded);
}

private static HashSet<SignalFrequency> _frequenciesInUse = new();

private static void OnSceneUnloaded(Scene _)
{
_frequenciesInUse.Clear();
}

private static void OnStarSystemLoaded(string starSystem)
{
// If its the base game solar system or eye we get all the main frequencies
var starSystem = Main.Instance.CurrentStarSystem;
if (starSystem == "SolarSystem" || starSystem == "EyeOfTheUniverse")
{
_frequenciesInUse.Add(SignalFrequency.Quantum);
Expand All @@ -69,19 +60,43 @@ private static void OnStarSystemLoaded(string starSystem)
// We don't want a scenario where the player knows no frequencies
_frequenciesInUse.Add(SignalFrequency.Traveler);

// Make sure the NH save file has all the right frequencies
// Skip "default"
for (int i = 1; i < PlayerData._currentGameSave.knownFrequencies.Length; i++)
{
if (PlayerData._currentGameSave.knownFrequencies[i])
{
NewHorizonsData.LearnFrequency(AudioSignal.IndexToFrequency(i).ToString());
}
}

NHLogger.LogVerbose($"Frequencies in use in {starSystem}: {_frequenciesInUse.Join(x => x.ToString())}");
}

private static HashSet<SignalFrequency> _frequenciesInUse = new();

private static void OnSceneUnloaded(Scene _)
{
_frequenciesInUse.Clear();
}

public static bool IsFrequencyInUse(SignalFrequency freq) => _frequenciesInUse.Contains(freq);

public static bool IsFrequencyInUse(string freqString)
{
if (Enum.TryParse<SignalFrequency>(freqString, out var freq))
{
return IsFrequencyInUse(freq);
}
return false;
}

public static bool IsCloaked(this AudioSignal signal) => _cloakedSignals.Contains(signal);

public static bool IsOnQuantumMoon(this AudioSignal signal) => _qmSignals.Contains(signal);

public static SignalFrequency AddFrequency(string str)
{
if (_customFrequencyNames == null) Init();

var freq = CollectionUtilities.KeyByValue(_customFrequencyNames, str);
if (freq != default) return freq;

Expand All @@ -99,23 +114,19 @@ public static SignalFrequency AddFrequency(string str)
NumberOfFrequencies = EnumUtils.GetValues<SignalFrequency>().Length;

// This stuff happens after the signalscope is Awake so we have to change the number of frequencies now
Object.FindObjectOfType<Signalscope>()._strongestSignals = new AudioSignal[NumberOfFrequencies + 1];
GameObject.FindObjectOfType<Signalscope>()._strongestSignals = new AudioSignal[NumberOfFrequencies + 1];

return freq;
}

public static string GetCustomFrequencyName(SignalFrequency frequencyName)
{
if (_customFrequencyNames == null) Init();

_customFrequencyNames.TryGetValue(frequencyName, out string name);
return name;
}

public static SignalName AddSignalName(string str)
{
if (_customSignalNames == null) Init();

var name = CollectionUtilities.KeyByValue(_customSignalNames, str);
if (name != default) return name;

Expand All @@ -129,8 +140,6 @@ public static SignalName AddSignalName(string str)

public static string GetCustomSignalName(SignalName signalName)
{
if (_customSignalNames == null) Init();

_customSignalNames.TryGetValue(signalName, out string name);
return name;
}
Expand Down
9 changes: 8 additions & 1 deletion NewHorizons/Builder/Props/BrambleNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NewHorizons.Utility;
using NewHorizons.Utility.OuterWilds;
using NewHorizons.Utility.OWML;
using Newtonsoft.Json;
using OWML.Common;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -414,7 +415,13 @@ public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo conf
{
foreach (var signalConfig in connectedSignals)
{
var signalGO = SignalBuilder.Make(go, sector, signalConfig, mod);
// Have to ensure that this new signal doesn't use parent path, else it looks for a parent that only exists on the original body
// Have to make a copy of it as well to avoid modifying the old body's info
var signalConfigCopy = JsonConvert.DeserializeObject<SignalInfo>(JsonConvert.SerializeObject(signalConfig));
signalConfigCopy.parentPath = null;
signalConfigCopy.isRelativeToParent = false;

var signalGO = SignalBuilder.Make(go, sector, signalConfigCopy, mod);
signalGO.GetComponent<AudioSignal>()._identificationDistance = 0;
signalGO.GetComponent<AudioSignal>()._sourceRadius = 1;
signalGO.transform.position = brambleNode.transform.position;
Expand Down
33 changes: 14 additions & 19 deletions NewHorizons/Builder/Props/DetailBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, G
GameObject prop;
bool isItem;
bool invalidComponentFound = false;
bool isFromAssetBundle = !string.IsNullOrEmpty(detail.assetBundle);

// We save copies with all their components fixed, good if the user is placing the same detail more than once
if (detail?.path != null && _fixedPrefabCache.TryGetValue((sector, detail.path), out var storedPrefab))
Expand Down Expand Up @@ -139,12 +140,21 @@ public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, G
}
else
{
FixSectoredComponent(component, sector, existingSectors, detail.keepLoaded);
// Fix cull groups only when not from an asset bundle (because then they're there on purpose!)
// keepLoaded should remove existing groups
// renderers/colliders get enabled later so we dont have to do that here
if (detail.keepLoaded && !isFromAssetBundle && component is SectorCullGroup or SectorCollisionGroup or SectorLightsCullGroup)
{
UnityEngine.Object.DestroyImmediate(component);
continue;
}

FixSectoredComponent(component, sector, existingSectors);
}

// Asset bundle is a real string -> Object loaded from unity
// If they're adding dialogue we have to manually register the xml text
if (!string.IsNullOrEmpty(detail.assetBundle) && component is CharacterDialogueTree dialogue)
if (isFromAssetBundle && component is CharacterDialogueTree dialogue)
{
DialogueBuilder.AddTranslation(dialogue._xmlCharacterDialogueAsset.text, null);
}
Expand Down Expand Up @@ -278,32 +288,17 @@ public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, G
/// <summary>
/// Fix components that have sectors. Has a specific fix if there is a VisionTorchItem on the object.
/// </summary>
private static void FixSectoredComponent(Component component, Sector sector, HashSet<Sector> existingSectors, bool keepLoaded)
private static void FixSectoredComponent(Component component, Sector sector, HashSet<Sector> existingSectors)
{
// keepLoaded should remove existing groups
// renderers/colliders get enabled later so we dont have to do that here
if (keepLoaded && component is SectorCullGroup or SectorCollisionGroup or SectorLightsCullGroup)
{
UnityEngine.Object.DestroyImmediate(component);
return;
}

// fix Sector stuff, eg SectorCullGroup (without this, props that have a SectorCullGroup component will become invisible inappropriately)
if (component is ISectorGroup sectorGroup && !existingSectors.Contains(sectorGroup.GetSector()))
{
sectorGroup.SetSector(sector);
}

// Not doing else if here because idk if any of the classes below implement ISectorGroup

// Null check else shuttles controls break
// parent sector is always null before Awake so this code actually never runs lol
if (component is Sector s && s.GetParentSector() != null && !existingSectors.Contains(s.GetParentSector()))
{
s.SetParentSector(sector);
}

else if(component is SectoredMonoBehaviour behaviour && !existingSectors.Contains(behaviour._sector))
if(component is SectoredMonoBehaviour behaviour && !existingSectors.Contains(behaviour._sector))
{
// not using SetSector here because it registers the events twice
// perhaps this happens with ISectorGroup.SetSector or Sector.SetParentSector too? idk and nothing seems to break because of it yet
Expand Down
4 changes: 3 additions & 1 deletion NewHorizons/Builder/Props/DialogueBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ private static CharacterDialogueTree AddToExistingDialogue(DialogueInfo info, st
// We just have to merge the dialogue options
var dialogueOptions = newDialogueNode.GetChildNode("DialogueOptionsList").GetChildNodes("DialogueOption");
var existingDialogueOptionsList = existingNode.GetChildNode("DialogueOptionsList");
var firstNode = existingDialogueOptionsList.ChildNodes[0];
foreach (XmlNode node in dialogueOptions)
{
var importedNode = existingDialogueOptionsList.OwnerDocument.ImportNode(node, true);
existingDialogueOptionsList.AppendChild(importedNode);
// We add them to the start because normally the last option is to return to menu or exit
existingDialogueOptionsList.PrependChild(importedNode);
}
}
else
Expand Down
4 changes: 4 additions & 0 deletions NewHorizons/Builder/Props/ItemBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static NHItem MakeItem(GameObject go, GameObject planetGO, Sector sector,
item.DisplayName = itemName;
item.ItemType = itemType;
item.Droppable = info.droppable;
item.HoldOffset = info.holdOffset ?? Vector3.zero;
item.HoldRotation = info.holdRotation ?? Vector3.zero;
item.SocketOffset = info.socketOffset ?? Vector3.zero;
item.SocketRotation = info.socketRotation ?? Vector3.zero;
if (!string.IsNullOrEmpty(info.pickupAudio))
{
item.PickupAudio = AudioTypeHandler.GetAudioType(info.pickupAudio, mod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ internal static void RefreshArcs(NomaiWallText nomaiWallText, GameObject convers
}

ArcCacheData[] cachedData = null;
if (nhBody.Cache?.ContainsKey(cacheKey) ?? false)
if (nhBody?.Cache?.ContainsKey(cacheKey) ?? false)
cachedData = nhBody.Cache.Get<ArcCacheData[]>(cacheKey);

var arranger = nomaiWallText.gameObject.AddComponent<NomaiTextArcArranger>();
Expand Down
15 changes: 14 additions & 1 deletion NewHorizons/Builder/ShipLog/MapModeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObj
{
if (body.Config.ShipLog == null) continue;

if (body.Config.ShipLog?.mapMode?.manualPosition == null)
if (body.Config.ShipLog.mapMode?.manualPosition == null)
{
flagAutoPositionUsed = true;
}
Expand All @@ -45,6 +45,12 @@ public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObj
}
}

// If they're both false, just default to auto (this means that no planets even have ship log info)
if (!flagManualPositionUsed && !flagAutoPositionUsed)
{
flagAutoPositionUsed = true;
}

var isBaseSolarSystem = systemName == "SolarSystem";

// Default to MANUAL in Base Solar System (we can't automatically fix them so it might just break, but AUTO breaks even more!)
Expand Down Expand Up @@ -142,6 +148,7 @@ private static ShipLogAstroObject AddShipLogAstroObject(GameObject gameObject, N

astroObject._imageObj = CreateImage(gameObject, image, body.Config.name + " Revealed", layer);
astroObject._outlineObj = CreateImage(gameObject, outline, body.Config.name + " Outline", layer);

if (ShipLogHandler.BodyHasEntries(body))
{
Image revealedImage = astroObject._imageObj.GetComponent<Image>();
Expand All @@ -156,6 +163,12 @@ private static ShipLogAstroObject AddShipLogAstroObject(GameObject gameObject, N

Rect imageRect = astroObject._imageObj.GetComponent<RectTransform>().rect;
astroObject._unviewedObj.transform.localPosition = new Vector3(imageRect.width / 2 + unviewedIconOffset, imageRect.height / 2 + unviewedIconOffset, 0);

// Set all icons inactive, they will be conditionally activated when the map mode is opened for the first time
astroObject._unviewedObj.SetActive(false);
astroObject._imageObj.SetActive(false);
astroObject._outlineObj.SetActive(false);

return astroObject;
}
#endregion
Expand Down
Loading

0 comments on commit 3d630b2

Please sign in to comment.