Skip to content

Commit

Permalink
1.18.0 (#759)
Browse files Browse the repository at this point in the history
## Major features
- Custom items and item sockets, as an extension of the existing
details. Interactivity can be added without code by setting dialogue
conditions with an item's `pickupCondition` or socket's
`insertCondition`, and then turning other details on or off using their
`activationCondition`.

## Minor features
- Added API methods for looking up translated strings for localization.

## Bug fixes
- Fixes orbs on copied details
- Fix slide module default values #754
- Fix slides being inverted in the ship log #746
  • Loading branch information
xen-42 committed Dec 17, 2023
2 parents dd79d18 + 8e0fbbb commit b6702b4
Show file tree
Hide file tree
Showing 27 changed files with 1,085 additions and 164 deletions.
5 changes: 3 additions & 2 deletions NewHorizons/Builder/Body/BrambleDimensionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NewHorizons.External.Modules.Props;
using NewHorizons.Utility;
using NewHorizons.Utility.OWML;
using OWML.Common;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -80,7 +81,7 @@ internal static void InitPrefabs()
if (_wallCollision == null) _wallCollision = Main.NHPrivateAssetBundle.LoadAsset<GameObject>("BrambleCollision");
}

public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject ao, Sector sector, OWRigidbody owRigidBody)
public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject ao, Sector sector, IModBehaviour mod, OWRigidbody owRigidBody)
{
InitPrefabs();

Expand All @@ -102,7 +103,7 @@ public static GameObject Make(NewHorizonsBody body, GameObject go, NHAstroObject
default: geometryPrefab = _hubGeometry; break;
}

var geometry = DetailBuilder.Make(go, sector, geometryPrefab, new DetailInfo());
var geometry = DetailBuilder.Make(go, sector, mod, geometryPrefab, new DetailInfo());

var exitWarps = _exitWarps.InstantiateInactive();
var repelVolume = _repelVolume.InstantiateInactive();
Expand Down
36 changes: 23 additions & 13 deletions NewHorizons/Builder/Props/DetailBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ static DetailBuilder()
SceneManager.sceneUnloaded += SceneManager_sceneUnloaded;
}

#region obsolete
// Never change method signatures, people directly reference the NH dll and it can break backwards compatability
// In particular, Outer Wives needs this method signature
[Obsolete]
public static GameObject Make(GameObject go, Sector sector, GameObject prefab, DetailInfo detail)
=> Make(go, sector, null, prefab, detail);
#endregion

private static void SceneManager_sceneUnloaded(Scene scene)
{
foreach (var prefab in _fixedPrefabCache.Values)
Expand All @@ -52,24 +60,16 @@ public static GameObject GetSpawnedGameObjectByDetailInfo(DetailInfo detail)
/// <summary>
/// Create a detail using an asset bundle or a path in the scene hierarchy of the item to copy.
/// </summary>
public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, DetailInfo detail)
public static GameObject Make(GameObject planetGO, Sector sector, IModBehaviour mod, DetailInfo info)
{
if (detail.assetBundle != null)
if (info.assetBundle != null)
{
// Shouldn't happen
if (mod == null) return null;

return Make(go, sector, AssetBundleUtilities.LoadPrefab(detail.assetBundle, detail.path, mod), detail);
return Make(planetGO, sector, mod, AssetBundleUtilities.LoadPrefab(info.assetBundle, info.path, mod), info);
}
else
return Make(go, sector, detail);
}

/// <summary>
/// Create a detail using a path in the scene hierarchy of the item to copy.
/// </summary>
public static GameObject Make(GameObject planetGO, Sector sector, DetailInfo info)
{
if (_emptyPrefab == null) _emptyPrefab = new GameObject("Empty");

// Allow for empty game objects so you can set up conditional activation on them and parent other props to them
Expand All @@ -82,14 +82,14 @@ public static GameObject Make(GameObject planetGO, Sector sector, DetailInfo inf
}
else
{
return Make(planetGO, sector, prefab, info);
return Make(planetGO, sector, mod, prefab, info);
}
}

/// <summary>
/// Create a detail using a prefab.
/// </summary>
public static GameObject Make(GameObject go, Sector sector, GameObject prefab, DetailInfo detail)
public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, GameObject prefab, DetailInfo detail)
{
if (prefab == null) return null;

Expand Down Expand Up @@ -163,6 +163,16 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D
}
}

if (detail.item != null)
{
ItemBuilder.MakeItem(prop, go, sector, detail.item, mod);
}

if (detail.itemSocket != null)
{
ItemBuilder.MakeSocket(prop, go, sector, detail.itemSocket);
}

// Items should always be kept loaded else they will vanish in your hand as you leave the sector
if (isItem) detail.keepLoaded = true;

Expand Down
65 changes: 5 additions & 60 deletions NewHorizons/Builder/Props/GravityCannonBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NewHorizons.Builder.Props.TranslatorText;
using NewHorizons.Components.Orbital;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Shuttle;
Expand All @@ -18,7 +17,6 @@ public static class GravityCannonBuilder
{
private static GameObject _interfacePrefab;
private static GameObject _detailedPlatformPrefab, _platformPrefab;
private static GameObject _orbPrefab;

internal static void InitPrefab()
{
Expand Down Expand Up @@ -59,24 +57,16 @@ internal static void InitPrefab()
GameObject.DestroyImmediate(_platformPrefab.FindChild("Structure_NOM_GravityCannon_Crystals"));
GameObject.DestroyImmediate(_platformPrefab.FindChild("Structure_NOM_GravityCannon_Geo"));
}

if (_orbPrefab == null)
{
_orbPrefab = SearchUtilities.Find("Prefab_NOM_InterfaceOrb")
.InstantiateInactive()
.Rename("Prefab_NOM_InterfaceOrb")
.DontDestroyOnLoad();
}
}

public static GameObject Make(GameObject planetGO, Sector sector, GravityCannonInfo info, IModBehaviour mod)
{
InitPrefab();

if (_interfacePrefab == null || planetGO == null || sector == null || _detailedPlatformPrefab == null || _platformPrefab == null || _orbPrefab == null) return null;
if (_interfacePrefab == null || planetGO == null || sector == null || _detailedPlatformPrefab == null || _platformPrefab == null) return null;

var detailInfo = new DetailInfo(info.controls) { keepLoaded = true };
var gravityCannonObject = DetailBuilder.Make(planetGO, sector, _interfacePrefab, detailInfo);
var gravityCannonObject = DetailBuilder.Make(planetGO, sector, mod, _interfacePrefab, detailInfo);
gravityCannonObject.SetActive(false);

var gravityCannonController = gravityCannonObject.GetComponent<GravityCannonController>();
Expand All @@ -87,7 +77,7 @@ public static GameObject Make(GameObject planetGO, Sector sector, GravityCannonI
gravityCannonController._retrieveShipLogFact = info.retrieveReveal ?? string.Empty;
gravityCannonController._launchShipLogFact = info.launchReveal ?? string.Empty;

CreatePlatform(planetGO, sector, gravityCannonController, info);
CreatePlatform(planetGO, sector, mod, gravityCannonController, info);

if (info.computer != null)
{
Expand All @@ -102,56 +92,11 @@ public static GameObject Make(GameObject planetGO, Sector sector, GravityCannonI
gravityCannonController._nomaiComputer = null;
}

CreateOrb(planetGO, gravityCannonController);

gravityCannonObject.SetActive(true);

return gravityCannonObject;
}

private static void CreateOrb(GameObject planetGO, GravityCannonController gravityCannonController)
{
var orb = _orbPrefab.InstantiateInactive().Rename(_orbPrefab.name);
orb.transform.parent = gravityCannonController.transform;
orb.transform.localPosition = new Vector3(0f, 0.9673f, 0f);
orb.transform.localScale = Vector3.one;
orb.SetActive(true);

var planetBody = planetGO.GetComponent<OWRigidbody>();
var orbBody = orb.GetComponent<OWRigidbody>();

var nomaiInterfaceOrb = orb.GetComponent<NomaiInterfaceOrb>();
nomaiInterfaceOrb._orbBody = orbBody;
nomaiInterfaceOrb._slotRoot = gravityCannonController.gameObject;
orbBody._origParent = planetGO.transform;
orbBody._origParentBody = planetBody;
nomaiInterfaceOrb._slots = nomaiInterfaceOrb._slotRoot.GetComponentsInChildren<NomaiInterfaceSlot>();
nomaiInterfaceOrb.SetParentBody(planetBody);
nomaiInterfaceOrb._safetyRails = new OWRail[0];
nomaiInterfaceOrb.RemoveAllLocks();

var spawnVelocity = planetBody.GetVelocity();
var spawnAngularVelocity = planetBody.GetPointTangentialVelocity(orbBody.transform.position);
var velocity = spawnVelocity + spawnAngularVelocity;

orbBody._lastVelocity = velocity;
orbBody._currentVelocity = velocity;

// detect planet gravity
// somehow Intervention has GetAttachedOWRigidbody as null sometimes, idk why
var gravityVolume = planetGO.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
orb.GetComponent<ConstantForceDetector>()._detectableFields = gravityVolume ? new ForceVolume[] { gravityVolume } : new ForceVolume[0];

Delay.RunWhenAndInNUpdates(() =>
{
foreach (var component in orb.GetComponents<MonoBehaviour>())
{
component.enabled = true;
}
nomaiInterfaceOrb.RemoveAllLocks();
}, () => Main.IsSystemReady, 10);
}

private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo, NomaiShuttleController.ShuttleID id)
{
// Load the position info from the GeneralPropInfo
Expand All @@ -175,9 +120,9 @@ private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector,
return computer;
}

private static GameObject CreatePlatform(GameObject planetGO, Sector sector, GravityCannonController gravityCannonController, GravityCannonInfo platformInfo)
private static GameObject CreatePlatform(GameObject planetGO, Sector sector, IModBehaviour mod, GravityCannonController gravityCannonController, GravityCannonInfo platformInfo)
{
var platform = DetailBuilder.Make(planetGO, sector, platformInfo.detailed ? _detailedPlatformPrefab : _platformPrefab, new DetailInfo(platformInfo) { keepLoaded = true });
var platform = DetailBuilder.Make(planetGO, sector, mod, platformInfo.detailed ? _detailedPlatformPrefab : _platformPrefab, new DetailInfo(platformInfo) { keepLoaded = true });

gravityCannonController._forceVolume = platform.FindChild("ForceVolume").GetComponent<DirectionalForceVolume>();
gravityCannonController._platformTrigger = platform.FindChild("PlatformTrigger").GetComponent<OWTriggerVolume>();
Expand Down
Loading

0 comments on commit b6702b4

Please sign in to comment.