Skip to content

Commit

Permalink
Prometheus (quantum lightning + quantum refactor) (#717)
Browse files Browse the repository at this point in the history
## Minor Features
- Implements lightning storms. Resolves #564.
- Can now control if socketed quantum objects align with gravity or use
socket rotation, and if they randomize rotation around the local Y axis.
Fixes #751.

## Improvements
- Makes quantum organization cleaner (split into separate lists by the
type of quantum group, state or socket).
- Quantum socket groups can now have an equal number of props to sockets
and will work accordingly. Fixes #597
  • Loading branch information
xen-42 authored Jan 8, 2025
2 parents 1f44218 + 63445a1 commit 63672ea
Show file tree
Hide file tree
Showing 31 changed files with 839 additions and 253 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ManifestFileVersion: 0
CRC: 2356174904
CRC: 2772415118
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: c9b4a60ca4efa0ba50065dea6e758ce7
Hash: a1c50cfbd83ea025ed5ff8a920ceb135
TypeTreeHash:
serializedVersion: 2
Hash: 65942a71d50cdc9f2387a8fa9383a3f8
Hash: 8a96558a3d9470a68866aeaaa30830cf
HashAppended: 0
ClassTypes:
- Class: 1
Expand Down Expand Up @@ -87,6 +87,8 @@ ClassTypes:
Script: {fileID: 11500000, guid: 13ab18a571ddf1b4f8dc92e3fa31b22e, type: 3}
- Class: 114
Script: {fileID: 11500000, guid: 3d5c87c5a00ca19449219c7c54f41ee7, type: 3}
- Class: 114
Script: {fileID: 11500000, guid: db82bd26294f5b848aaa8cb1ad0dc252, type: 3}
- Class: 114
Script: {fileID: 11500000, guid: 840ab63696e59254eb425242136805dd, type: 3}
- Class: 114
Expand Down Expand Up @@ -198,5 +200,6 @@ Assets:
- Assets/SlideReels/Prefab_DW_Reel_8.prefab
- Assets/Vessel_Body.prefab
- Assets/AmbientLight_QM.png
- Assets/QuantumLightning/Prefab_EYE_QuantumLightningObject.prefab
- Assets/SlideReels/Prefab_IP_Reel_7.prefab
Dependencies: []
File renamed without changes.
2 changes: 1 addition & 1 deletion NewHorizons/Builder/Atmosphere/CloudsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal static void InitPrefabs()
}
_qmBottomMeshGroup.variants = variants.ToArray();
}
if (_transparentCloud == null) _transparentCloud = Main.NHAssetBundle.LoadAsset<Material>("Assets/Resources/TransparentCloud.mat");
if (_transparentCloud == null) _transparentCloud = AssetBundleUtilities.NHAssetBundle.LoadAsset<Material>("Assets/Resources/TransparentCloud.mat");
}

public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, bool cloaked, IModBehaviour mod)
Expand Down
3 changes: 2 additions & 1 deletion NewHorizons/Builder/Body/BrambleDimensionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.Utility;
using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;
using OWML.Common;
using System.Collections.Generic;
Expand Down Expand Up @@ -78,7 +79,7 @@ internal static void InitPrefabs()
if (_exitWarps == null) _exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/OuterWarp_Hub").InstantiateInactive().Rename("Prefab_Bramble_OuterWarp").DontDestroyOnLoad();
if (_repelVolume == null) _repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive().Rename("Prefab_Bramble_RepelVolume").DontDestroyOnLoad();
if (_material == null) _material = new Material(GameObject.Find("DB_PioneerDimension_Body/Sector_PioneerDimension").GetComponent<EffectRuleset>()._material).DontDestroyOnLoad();
if (_wallCollision == null) _wallCollision = Main.NHPrivateAssetBundle.LoadAsset<GameObject>("BrambleCollision");
if (_wallCollision == null) _wallCollision = AssetBundleUtilities.NHPrivateAssetBundle.LoadAsset<GameObject>("BrambleCollision");
}

public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject ao, Sector sector, IModBehaviour mod, OWRigidbody owRigidBody)
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Builder/Body/HeightMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static GameObject Make(GameObject planetGO, Sector sector, HeightMapModul
cubeSphere.SetActive(false);
cubeSphere.transform.SetParent(sector?.transform ?? planetGO.transform, false);

if (PlanetShader == null) PlanetShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapperTriplanar.shader");
if (PlanetShader == null) PlanetShader = AssetBundleUtilities.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapperTriplanar.shader");

var stretch = module.stretch != null ? (Vector3)module.stretch : Vector3.one;

Expand Down
8 changes: 4 additions & 4 deletions NewHorizons/Builder/Body/RingBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public static GameObject MakeRingGraphics(GameObject rootObject, Sector sector,
var ringMesh = ringMF.mesh;
var ringMR = ringGO.AddComponent<MeshRenderer>();

if (RingShader == null) RingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring.shader");
if (UnlitRingShader == null) UnlitRingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitTransparent.shader");
if (RingShader1Pixel == null) RingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring1Pixel.shader");
if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitRing1Pixel.shader");
if (RingShader == null) RingShader = AssetBundleUtilities.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring.shader");
if (UnlitRingShader == null) UnlitRingShader = AssetBundleUtilities.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitTransparent.shader");
if (RingShader1Pixel == null) RingShader1Pixel = AssetBundleUtilities.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring1Pixel.shader");
if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = AssetBundleUtilities.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitRing1Pixel.shader");

var mat = new Material(ring.unlit ? UnlitRingShader : RingShader);
if (ringTexture.width == 1)
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Builder/General/AmbientLightBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Light Make(GameObject planetGO, Sector sector, AmbientLightModule
}
else
{
var baseCubemap = Main.NHPrivateAssetBundle.LoadAsset<Cubemap>("AmbientLight_QM");
var baseCubemap = AssetBundleUtilities.NHPrivateAssetBundle.LoadAsset<Cubemap>("AmbientLight_QM");
var cubemap = new Cubemap(baseCubemap.width, baseCubemap.format, baseCubemap.mipmapCount != 1);
cubemap.name = key;
cubemap.wrapMode = baseCubemap.wrapMode;
Expand Down
32 changes: 16 additions & 16 deletions NewHorizons/Builder/Props/DetailBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,23 @@ namespace NewHorizons.Builder.Props
{
public static class DetailBuilder
{
private static readonly Dictionary<DetailInfo, GameObject> _detailInfoToCorrespondingSpawnedGameObject = new();
private static readonly Dictionary<(Sector, string), (GameObject prefab, bool isItem)> _fixedPrefabCache = new();
private static GameObject _emptyPrefab;

private static readonly Dictionary<DetailInfo, GameObject> _detailInfoToGameObject = new();

public static GameObject GetGameObjectFromDetailInfo(DetailInfo info)
{
if (_detailInfoToGameObject.ContainsKey(info))
{
return _detailInfoToGameObject[info];
}
else
{
return null;
}
}

static DetailBuilder()
{
SceneManager.sceneUnloaded += SceneManager_sceneUnloaded;
Expand All @@ -48,20 +61,7 @@ private static void SceneManager_sceneUnloaded(Scene scene)
UnityEngine.Object.Destroy(prefab.prefab);
}
_fixedPrefabCache.Clear();
_detailInfoToCorrespondingSpawnedGameObject.Clear();
}

// i dont like how this is just a random collection in this class but quantum guy uses it :(
public static GameObject GetSpawnedGameObjectByDetailInfo(DetailInfo detail)
{
if (!_detailInfoToCorrespondingSpawnedGameObject.ContainsKey(detail))
{
return null;
}
else
{
return _detailInfoToCorrespondingSpawnedGameObject[detail];
}
_detailInfoToGameObject.Clear();
}

/// <summary>
Expand Down Expand Up @@ -301,7 +301,7 @@ public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, G
ConditionalObjectActivation.SetUp(prop, detail.deactivationCondition, detail.blinkWhenActiveChanged, false);
}

_detailInfoToCorrespondingSpawnedGameObject[detail] = prop;
_detailInfoToGameObject[detail] = prop;

return prop;
}
Expand Down
6 changes: 3 additions & 3 deletions NewHorizons/Builder/Props/ProjectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Linq;
using UnityEngine;
using UnityEngine.InputSystem;
using static NewHorizons.Main;
using static NewHorizons.Utility.Files.AssetBundleUtilities;

namespace NewHorizons.Builder.Props
{
Expand Down Expand Up @@ -543,12 +543,12 @@ private static (SlideReelAsyncImageLoader inverted, SlideReelAsyncImageLoader at
if (useInvertedCache && cacheExists)
{
// Load the inverted images used when displaying slide reels to a screen
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/inverted_blank_slide_reel.png")));
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/inverted_blank_slide_reel.png")));
}
else
{
// Used to then make cached stuff
imageLoader.PathsToLoad.Add((i, Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/blank_slide_reel.png")));
imageLoader.PathsToLoad.Add((i, Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/blank_slide_reel.png")));
}
}
else
Expand Down
33 changes: 6 additions & 27 deletions NewHorizons/Builder/Props/PropBuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static void Make(GameObject go, Sector sector, OWRigidbody planetBody, Ne
MakeGeneralProps(go, config.Props.audioSources, (audioSource) => AudioSourceBuilder.Make(go, sector, audioSource, mod), (audioSource) => audioSource.audio);
RemoteBuilder.MakeGeneralProps(go, sector, config.Props.remotes, nhBody);
if (Main.HasDLC) MakeGeneralProps(go, config.Props.projectionTotems, (totem) => ProjectionTotemBuilder.Make(go, sector, totem, mod));
// For quantum groups, make the details in advance
if (config.Props.socketQuantumGroups != null) MakeGeneralProps(go, config.Props.socketQuantumGroups.SelectMany(x => x.details), (detail) => DetailBuilder.Make(go, sector, mod, detail), (detail) => detail.path);
if (config.Props.stateQuantumGroups != null) MakeGeneralProps(go, config.Props.stateQuantumGroups.SelectMany(x => x.details), (detail) => DetailBuilder.Make(go, sector, mod, detail), (detail) => detail.path);
if (config.Props.lightningQuantumGroups != null) MakeGeneralProps(go, config.Props.lightningQuantumGroups, (lightning) => QuantumBuilder.MakeQuantumLightning(go, sector, mod, lightning));

RunMultiPass();

Expand All @@ -162,33 +166,8 @@ public static void Make(GameObject go, Sector sector, OWRigidbody planetBody, Ne
}
}

if (config.Props.quantumGroups != null)
{
Dictionary<string, List<GameObject>> propsByGroup = new Dictionary<string, List<GameObject>>();
foreach (var detail in config.Props.details)
{
if (detail.quantumGroupID != null)
{
if (!propsByGroup.ContainsKey(detail.quantumGroupID)) propsByGroup[detail.quantumGroupID] = new List<GameObject>();
propsByGroup[detail.quantumGroupID].Add(DetailBuilder.GetSpawnedGameObjectByDetailInfo(detail));
}
}

foreach (var quantumGroup in config.Props.quantumGroups)
{
if (!propsByGroup.ContainsKey(quantumGroup.id)) continue;
var propsInGroup = propsByGroup[quantumGroup.id];

try
{
QuantumBuilder.Make(go, sector, config, mod, quantumGroup, propsInGroup.ToArray());
}
catch (Exception ex)
{
NHLogger.LogError($"Couldn't make quantum group \"{quantumGroup.id}\" for [{go.name}]:\n{ex}");
}
}
}
if (config.Props.socketQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.socketQuantumGroups);
if (config.Props.stateQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.stateQuantumGroups);
}

private static bool _ignoreParent;
Expand Down
Loading

0 comments on commit 63672ea

Please sign in to comment.