Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTwentyThree committed Mar 1, 2024
2 parents ac6bb52 + cc80268 commit d89aa75
Show file tree
Hide file tree
Showing 31 changed files with 1,150 additions and 539 deletions.
24 changes: 24 additions & 0 deletions CLA/Signatures.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
"created_at": "2023-11-24T08:52:03Z",
"repoId": 123711758,
"pullRequestNo": 505
},
{
"name": "tornac1234",
"id": 24827220,
"comment_id": 1873536486,
"created_at": "2024-01-02T00:09:02Z",
"repoId": 123711758,
"pullRequestNo": 523
},
{
"name": "RamuneNeptune",
"id": 94365980,
"comment_id": 1880001483,
"created_at": "2024-01-07T09:15:31Z",
"repoId": 123711758,
"pullRequestNo": 526
},
{
"name": "Indigocoder1",
"id": 130301845,
"comment_id": 1968259999,
"created_at": "2024-02-28T05:28:05Z",
"repoId": 123711758,
"pullRequestNo": 534
}
]
}
3 changes: 3 additions & 0 deletions Example mod/BiomeHandlerExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ private void Awake()

// Add the biome somewhere to the world
CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(new SpawnInfo(volumePrefabInfo.ClassID, new Vector3(-1400, -80, 600), Quaternion.identity, new Vector3(50, 50, 50)));

// Add this biome to the "biome" command
ConsoleCommandsHandler.AddBiomeTeleportPosition("nautilusexamplebiome", new Vector3(-1400, -80, 600));
}
}
4 changes: 2 additions & 2 deletions Nautilus/Assets/Gadgets/GadgetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ public static ICustomPrefab SetSpawns(this ICustomPrefab customPrefab, params Sp
{
customPrefab.AddOnRegister(() =>
{
foreach ((Vector3 position, Vector3 eulerAngles) in spawnLocations)
foreach (var spawnLocation in spawnLocations)
{
CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(new SpawnInfo(customPrefab.Info.ClassID, position, eulerAngles));
CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(new SpawnInfo(customPrefab.Info.ClassID, spawnLocation.Position, spawnLocation.EulerAngles, spawnLocation.Scale));
}
});

Expand Down
53 changes: 35 additions & 18 deletions Nautilus/Assets/ModPrefabCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace Nautilus.Assets;
/// </summary>
public static class ModPrefabCache
{
internal static HashSet<string> RunningPrefabs = new();

private static ModPrefabCacheInstance _cacheInstance;
internal static Dictionary<string, ModPrefabRequest> Requests { get; } = new Dictionary<string, ModPrefabRequest>();

/// <summary> Adds the given prefab to the cache. </summary>
/// <param name="prefab"> The prefab object that is disabled and cached. </param>
Expand Down Expand Up @@ -84,49 +85,65 @@ private void Awake()

gameObject.AddComponent<SceneCleanerPreserve>();
DontDestroyOnLoad(gameObject);
SaveUtils.RegisterOnQuitEvent(ModPrefabCache.RunningPrefabs.Clear);
}

public void EnterPrefabIntoCache(GameObject prefab)
{
// Proper prefabs can never exist in the scene, so parenting them is dangerous and pointless.
if(prefab.IsPrefab())
{
InternalLogger.Debug($"Game Object: {prefab} is a proper prefab. Skipping parenting for cache.");
}
else
{
prefab.transform.parent = _prefabRoot;
prefab.SetActive(true);
}

var prefabIdentifier = prefab.GetComponent<PrefabIdentifier>();

if(prefabIdentifier == null)
if (prefabIdentifier == null)
{
InternalLogger.Warn($"ModPrefabCache: prefab {prefab.name} is missing a PrefabIdentifier component! Unable to add to cache.");
return;
}

// Proper prefabs can never exist in the scene, so parenting them is dangerous and pointless.
if(!Entries.ContainsKey(prefabIdentifier.classId))
if (!Entries.ContainsKey(prefabIdentifier.classId))
{
Entries.Add(prefabIdentifier.classId, prefab);
InternalLogger.Debug($"ModPrefabCache: added prefab {prefab}");
// Proper prefabs can never exist in the scene, so parenting them is dangerous and pointless.
if (prefab.IsPrefab())
{
InternalLogger.Debug($"Game Object: {prefab} is a proper prefab. Skipping parenting for cache.");
}
else
{
prefab.transform.parent = _prefabRoot;
ResetIds(prefab);
prefab.SetActive(true);
}
}
else // this should never happen
else // This should never happen
{
InternalLogger.Warn($"ModPrefabCache: prefab {prefabIdentifier.classId} already existed in cache!");
}
}
}

public void RemoveCachedPrefab(string classId)
{
if(Entries.TryGetValue(classId, out var prefab))
if (Entries.TryGetValue(classId, out var prefab))
{
if(!prefab.IsPrefab())
Destroy(prefab);
InternalLogger.Debug($"ModPrefabCache: removed prefab {classId}");
Entries.Remove(classId);
}
}

private void ResetIds(GameObject prefab)
{
var uniqueIds = prefab.GetAllComponentsInChildren<UniqueIdentifier>();

foreach (var uniqueId in uniqueIds)
{
if (string.IsNullOrEmpty(uniqueId.id))
{
continue;
}

UniqueIdentifier.identifiers.Remove(uniqueId.id);
uniqueId.id = null;
}
}
}
7 changes: 2 additions & 5 deletions Nautilus/Assets/ModPrefabRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ internal class ModPrefabRequest: IPrefabRequest

private readonly PrefabInfo prefabInfo;

private CoroutineTask<GameObject> task;
private IEnumerator task;

private TaskResult<GameObject> taskResult;

public ModPrefabRequest(PrefabInfo prefabInfo)
{
this.prefabInfo = prefabInfo;
ModPrefabCache.Requests[prefabInfo.ClassID] = this;
}

private void Init()
Expand All @@ -37,7 +36,7 @@ private void Init()
return;
}

task = new CoroutineTask<GameObject>(PrefabHandler.GetPrefabAsync(taskResult, prefabInfo, factory), taskResult);
task = PrefabHandler.GetPrefabAsync(taskResult, prefabInfo, factory);
}

public object Current
Expand Down Expand Up @@ -66,14 +65,12 @@ public bool MoveNext()

public void Reset()
{
Init();
task.Reset();
Done = false;
}

public void Release()
{
ModPrefabCache.RemovePrefabFromCache(prefabInfo.ClassID);
taskResult = null;
task = null;
Done = false;
Expand Down
12 changes: 11 additions & 1 deletion Nautilus/Assets/PrefabTemplates/AtmosphereVolumeTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections;
using Nautilus.MonoBehaviours;
using UnityEngine;

namespace Nautilus.Assets.PrefabTemplates;

/// <summary>
/// A template for Atmosphere Volumes, which are basic invisible triggers for mini-biomes.
/// A template for Atmosphere Volumes, which are basic invisible triggers for mini-biomes. Atmosphere volumes can affect fog, music, ambient sounds and even the player's swim speed.
/// </summary>
public class AtmosphereVolumeTemplate : PrefabTemplate
{
Expand All @@ -23,6 +24,10 @@ public class AtmosphereVolumeTemplate : PrefabTemplate
/// The priority of this atmosphere volume. Atmosphere volumes with higher priorities override those with lower priorities. The default priority is 10.
/// </summary>
public int Priority { get; set; }
/// <summary>
/// Whether this atmosphere volume can be entered while inside a vehicle or not. For unknown reasons, this is NOT true for base game volumes. However, in this template, it is true by default.
/// </summary>
public bool CanEnterWhileInsideVehicle { get; set; } = true;

/// <summary>
/// Determines the loading distance of this atmosphere volume prefab. Default value is <see cref="LargeWorldEntity.CellLevel.Far"/>. Although vanilla prefabs always use Batch for this, this does not work with our custom systems.
Expand Down Expand Up @@ -78,6 +83,11 @@ public override IEnumerator GetPrefabAsync(TaskResult<GameObject> gameObject)
var atmosphereVolume = prefab.AddComponent<AtmosphereVolume>();
atmosphereVolume.overrideBiome = OverrideBiome;
atmosphereVolume.priority = Priority;

if (CanEnterWhileInsideVehicle)
{
prefab.AddComponent<AtmosphereVolumeTriggerFix>().atmosphereVolume = atmosphereVolume;
}

ModifyPrefab?.Invoke(prefab);
if (ModifyPrefabAsync is { })
Expand Down
19 changes: 18 additions & 1 deletion Nautilus/Assets/SpawnLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,21 @@ namespace Nautilus.Assets;
/// </summary>
/// <param name="Position">The world position.</param>
/// <param name="EulerAngles">Euler angles for the rotation the spawned object will appear with.</param>
public record SpawnLocation(Vector3 Position, Vector3 EulerAngles = default);
public record SpawnLocation(Vector3 Position, Vector3 EulerAngles = default)
{
/// <summary>
/// The scale that the object is spawned at. If default (0, 0, 0) will be resolved to (1, 1, 1).
/// </summary>
public Vector3 Scale { get; init; }

/// <summary>
/// Defines the spawn location with world position and optional euler angles. Used in the Coordinated Spawns system.
/// </summary>
/// <param name="Position">The world position.</param>
/// <param name="EulerAngles">Euler angles for the rotation the spawned object will appear with.</param>
/// <param name="Scale">The scale that the object is spawned at. If default (0, 0, 0) will be resolved to (1, 1, 1).</param>
public SpawnLocation(Vector3 Position, Vector3 EulerAngles, Vector3 Scale) : this(Position, EulerAngles)
{
this.Scale = Scale;
}
}
Loading

0 comments on commit d89aa75

Please sign in to comment.