Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.14.4 #696

Merged
merged 6 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions NewHorizons/Builder/Body/StarBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using NewHorizons.Components.SizeControllers;
using NewHorizons.Utility;
using UnityEngine;
using NewHorizons.Components.Stars;
using NewHorizons.External.Modules.VariableSize;
using NewHorizons.Utility;
using NewHorizons.Utility.Files;
using NewHorizons.Utility.OuterWilds;
using OWML.Common;
using System.Linq;
using NewHorizons.Components.Stars;
using NewHorizons.Utility.OuterWilds;
using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;
using UnityEngine;

namespace NewHorizons.Builder.Body
{
Expand Down Expand Up @@ -54,6 +53,7 @@ internal static void InitPrefabs()
if (_starSurface == null) _starSurface = SearchUtilities.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface").InstantiateInactive().Rename("Prefab_Surface_Star").DontDestroyOnLoad();
if (_starSolarFlareEmitter == null) _starSolarFlareEmitter = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter").InstantiateInactive().Rename("Prefab_SolarFlareEmitter_Star").DontDestroyOnLoad();
if (_supernovaPrefab == null) _supernovaPrefab = SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive().Rename("Prefab_Supernova").DontDestroyOnLoad();

if (_mainSequenceMaterial == null) _mainSequenceMaterial = new Material(SearchUtilities.Find("Sun_Body").GetComponent<SunController>()._startSurfaceMaterial).DontDestroyOnLoad();
if (_giantMaterial == null) _giantMaterial = new Material(SearchUtilities.Find("Sun_Body").GetComponent<SunController>()._endSurfaceMaterial).DontDestroyOnLoad();
if (_flareMaterial == null)
Expand Down Expand Up @@ -344,7 +344,6 @@ public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector,
solarFlareEmitter.transform.localPosition = Vector3.zero;
solarFlareEmitter.transform.localScale = Vector3.one;
solarFlareEmitter.name = "SolarFlareEmitter";
solarFlareEmitter.SetActive(true);

var emitter = solarFlareEmitter.GetComponent<SolarFlareEmitter>();

Expand All @@ -361,10 +360,19 @@ public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector,
}

var material = new Material(_flareMaterial);
// Since the star isn't awake yet the controllers haven't been made
foreach (var prefab in new GameObject[] { emitter.domePrefab, emitter.loopPrefab, emitter.streamerPrefab })

// Make our own copies of all prefabs to make sure we don't actually modify them
// else it will affect any other star using these prefabs
// #668
emitter._domePrefab = emitter.domePrefab.InstantiateInactive();
emitter._loopPrefab = emitter.loopPrefab.InstantiateInactive();
emitter._streamerPrefab = emitter.streamerPrefab.InstantiateInactive();

// Get all possible controllers, prefabs or already created ones
foreach (var controller in new GameObject[] { emitter.domePrefab, emitter.loopPrefab, emitter.streamerPrefab }
.Select(x => x.GetComponent<SolarFlareController>())
.Concat(emitter.GetComponentsInChildren<SolarFlareController>()))
{
var controller = prefab.GetComponent<SolarFlareController>();
// controller._meshRenderer doesn't exist yet since Awake hasn't been called
if (starModule.tint != null)
{
Expand All @@ -376,6 +384,8 @@ public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector,
{
controller._scaleFactor = Vector3.one * starModule.solarFlareSettings.scaleFactor;
}
controller.gameObject.SetActive(true);
controller.enabled = true;
}

starGO.transform.position = rootObject.transform.position;
Expand Down Expand Up @@ -413,6 +423,8 @@ public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector,
}
}

solarFlareEmitter.SetActive(true);

return starGO;
}

Expand Down
4 changes: 3 additions & 1 deletion NewHorizons/Builder/Props/DetailBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D
// Just swap all the children to a new game object
var newDetailGO = new GameObject(prop.name);
newDetailGO.SetActive(false);
newDetailGO.transform.position = prop.transform.position;
newDetailGO.transform.parent = prop.transform.parent;
newDetailGO.transform.position = prop.transform.position;
newDetailGO.transform.rotation = prop.transform.rotation;
newDetailGO.transform.localScale = prop.transform.localScale;

// Can't modify parents while looping through children bc idk
var children = new List<Transform>();
Expand Down
21 changes: 21 additions & 0 deletions NewHorizons/Patches/SolarFlareEmitterPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using HarmonyLib;
using System.Linq;

namespace NewHorizons.Patches
{
[HarmonyPatch(typeof(SolarFlareEmitter))]
public static class SolarFlareEmitterPatches
{
[HarmonyPostfix]
[HarmonyPatch(nameof(SolarFlareEmitter.Awake))]
public static void SolarFlareEmitter_Awake(SolarFlareEmitter __instance)
{
// Because in StarBuilder we use inactive game objects instead of real prefabs these objects all get created inactive
foreach (var flare in __instance._streamers.Concat(__instance._loops).Concat(__instance._domes))
{
flare.gameObject.SetActive(true);
flare.enabled = true;
}
}
}
}
2 changes: 1 addition & 1 deletion NewHorizons/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "1.14.3",
"version": "1.14.4",
"owmlVersion": "2.9.3",
"dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],
Expand Down