Skip to content

Commit

Permalink
Merge pull request #223 from SubnauticaModding/dev
Browse files Browse the repository at this point in the history
SMLHelper 2.10.0
  • Loading branch information
toebeann committed Jul 5, 2021
2 parents 5712bdc + 3f21ddc commit fe94523
Show file tree
Hide file tree
Showing 19 changed files with 621 additions and 72 deletions.
4 changes: 2 additions & 2 deletions Example mod/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.9.7.0")]
[assembly: AssemblyFileVersion("2.9.7.0")]
[assembly: AssemblyVersion("2.10.0.0")]
[assembly: AssemblyFileVersion("2.10.0.0")]
4 changes: 2 additions & 2 deletions Example mod/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"Id": "SMLHelperExampleMod",
"DisplayName": "Example Mod For SMLHelper",
"Author": "The SMLHelper Dev Team",
"Version": "2.9.7",
"Version": "2.10.0",
"Enable": true,
"AssemblyName": "Example mod.dll",
"VersionDependencies": {
"SMLHelper": "2.9.7"
"SMLHelper": "2.10.0"
}
}
6 changes: 3 additions & 3 deletions SMLHelper/Assets/CustomFabricator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public override GameObject GetGameObject()
_ => null
};

return ProcessPrefab(prefab);
return PreProcessPrefab(prefab);
#endif
}

Expand Down Expand Up @@ -205,10 +205,10 @@ public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
break;
};

gameObject.Set(ProcessPrefab(prefab));
gameObject.Set(PreProcessPrefab(prefab));
}

private GameObject ProcessPrefab(GameObject prefab)
private GameObject PreProcessPrefab(GameObject prefab)
{
Constructable constructible = null;
GhostCrafter crafter;
Expand Down
7 changes: 6 additions & 1 deletion SMLHelper/Assets/ModPrefab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ internal IEnumerator GetGameObjectInternalAsync(IOut<GameObject> gameObject)
gameObject.Set(go);
}

private void ProcessPrefab(GameObject go)
/// <summary>
/// Caches the prefab, then sets its TechType and ClassID to a default set of values applicable to most mods.<br/>
/// FOR ADVANCED MODDING ONLY. Do not override unless you know exactly what you are doing.
/// </summary>
/// <param name="go"></param>
protected virtual void ProcessPrefab(GameObject go)
{
if (go.activeInHierarchy) // inactive prefabs don't need to be removed by cache
ModPrefabCache.AddPrefab(go);
Expand Down
40 changes: 24 additions & 16 deletions SMLHelper/Assets/Spawnable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace SMLHelper.V2.Assets
{
using Handlers;
using SMLHelper.V2.Interfaces;
using SMLHelper.V2.Utility;
using Interfaces;
using Utility;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -73,10 +73,17 @@ public abstract class Spawnable: ModPrefab
public virtual Vector2int SizeInInventory { get; } = defaultSize;

/// <summary>
/// Returns the list of <see cref="Vector3"/>s that specify the prefab's Coordinated Spawns.<br/>
/// A lightweight class used to specify the position of a Coordinated Spawn and optionally set its rotation.
/// </summary>
/// <param name="position"></param>
/// <param name="eulerAngles"></param>
public record SpawnLocation(Vector3 position, Vector3 eulerAngles = default);

/// <summary>
/// Returns the list of <see cref="SpawnLocation"/>s that specify the prefab's Coordinated Spawns.<br/>
/// By default this will be null.
/// </summary>
public virtual List<Vector3> CoordinatedSpawns { get; } = null;
public virtual List<SpawnLocation> CoordinatedSpawns { get; } = null;

/// <summary>
/// Returns the List of BiomeData that handles what Biomes this prefab will spawn, how probable it is to spawn there and how many per spawn.
Expand Down Expand Up @@ -127,18 +134,19 @@ protected Spawnable(string classId, string friendlyName, string description)
CraftDataHandler.SetItemSize(TechType, SizeInInventory);
}
if(EntityInfo != null && BiomesToSpawnIn != null)
{
LootDistributionHandler.AddLootDistributionData(this, BiomesToSpawnIn, EntityInfo);
}
else if(EntityInfo != null)
if(EntityInfo != null)
{
WorldEntityDatabaseHandler.AddCustomInfo(ClassID, EntityInfo);
if(BiomesToSpawnIn != null)
LootDistributionHandler.AddLootDistributionData(this, BiomesToSpawnIn, EntityInfo);
}
if (CoordinatedSpawns != null)
{
CoordinatedSpawnsHandler.RegisterCoordinatedSpawnsForOneTechType(TechType, CoordinatedSpawns);
foreach (var (position, eulerAngles) in CoordinatedSpawns)
{
CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(new SpawnInfo(TechType, position, eulerAngles));
}
}
};
}
Expand Down Expand Up @@ -212,15 +220,15 @@ internal virtual void PatchTechType()
/// <returns>Returns the <see cref="Sprite"/> that will be used in the <see cref="SpriteHandler.RegisterSprite(TechType, Sprite)"/> call.</returns>
protected virtual Sprite GetItemSprite()
{
// This is for backwards compatibility with mods that were using the "ModName/Assets" format
string path = this.AssetsFolder != modFolderLocation
// This is for backwards compatibility with mods that were using the "ModName/Assets" format
string path = this.AssetsFolder != modFolderLocation
? IOUtilities.Combine(".", "QMods", this.AssetsFolder.Trim('/'), this.IconFileName)
: Path.Combine(this.AssetsFolder, this.IconFileName);

if(File.Exists(path))
{
return ImageUtils.LoadSpriteFromFile(path);
}
if(File.Exists(path))
{
return ImageUtils.LoadSpriteFromFile(path);
}

if(HasSprite)
Logger.Error($"Sprite for '{this.PrefabFileName}'{Environment.NewLine}Did not find an image file at '{path}'");
Expand Down
6 changes: 6 additions & 0 deletions SMLHelper/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,11 @@ public static class Handler
/// A handler for everything related to creating new BackgroundTypes.
/// </summary>
public static IBackgroundTypeHandler BackgroundTypeHandler => Handlers.BackgroundTypeHandler.Main;

/// <summary>
/// A handler related to Custom Sounds
/// </summary>
public static ICustomSoundHandler SoundHandler => Handlers.CustomSoundHandler.Main;

}
}
86 changes: 75 additions & 11 deletions SMLHelper/Handlers/CoordinatedSpawnsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using System.Collections.Generic;
using SMLHelper.V2.Interfaces;
using SMLHelper.V2.Patchers;
using UnityEngine;

namespace SMLHelper.V2.Handlers
{
using System.Collections.Generic;
using Interfaces;
using Patchers;
using UnityEngine;
#if SUBNAUTICA_STABLE
using Oculus.Newtonsoft.Json;
#else
using Newtonsoft.Json;
#endif


/// <summary>
/// a Handler that handles and registers Coordinated (<see cref="Vector3"/> spawns).
/// </summary>
Expand Down Expand Up @@ -54,6 +61,21 @@ void ICoordinatedSpawnHandler.RegisterCoordinatedSpawns(List<SpawnInfo> spawnInf
LargeWorldStreamerPatcher.spawnInfos.AddRange(spawnInfos);
}

/// <summary>
/// Registers Multiple Coordinated spawns with rotations for one single passed TechType
/// </summary>
/// <param name="techTypeToSpawn">The TechType to spawn</param>
/// <param name="coordinatesAndRotationsToSpawnTo">the coordinates(Key) and the rotations(Value) the <see cref="TechType"/> should spawn to</param>
void ICoordinatedSpawnHandler.RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, Dictionary<Vector3, Vector3> coordinatesAndRotationsToSpawnTo)
{
var spawnInfos = new List<SpawnInfo>();
foreach (var kvp in coordinatesAndRotationsToSpawnTo)
{
spawnInfos.Add(new SpawnInfo(techTypeToSpawn, kvp.Key, kvp.Value));
}
LargeWorldStreamerPatcher.spawnInfos.AddRange(spawnInfos);
}

#endregion

#region Static Methods
Expand Down Expand Up @@ -86,6 +108,16 @@ public static void RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSp
Main.RegisterCoordinatedSpawnsForOneTechType(techTypeToSpawn, coordinatesToSpawnTo);
}

/// <summary>
/// Registers Multiple Coordinated spawns with rotations for one single passed TechType
/// </summary>
/// <param name="techTypeToSpawn">The TechType to spawn</param>
/// <param name="coordinatesAndRotationsToSpawnTo">the coordinates(Key) and the rotations(Value) the <see cref="TechType"/> should spawn to</param>
public static void RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, Dictionary<Vector3, Vector3> coordinatesAndRotationsToSpawnTo)
{
Main.RegisterCoordinatedSpawnsForOneTechType(techTypeToSpawn, coordinatesAndRotationsToSpawnTo);
}

#endregion
}

Expand All @@ -95,12 +127,16 @@ public static void RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSp
/// </summary>
public class SpawnInfo
{
internal readonly TechType techType;
internal readonly string classId;
internal readonly Vector3 spawnPosition;
internal readonly Quaternion rotation;

internal SpawnType spawnType;
[JsonProperty]
internal TechType techType { get; }
[JsonProperty]
internal string classId { get; }
[JsonProperty]
internal Vector3 spawnPosition { get; }
[JsonProperty]
internal Quaternion rotation { get; }
[JsonProperty]
internal SpawnType spawnType { get; }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand Down Expand Up @@ -156,11 +192,39 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation)
spawnType = SpawnType.ClassId;
}

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="techType">TechType to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation)
{
this.techType = techType;
this.spawnPosition = spawnPosition;
this.rotation = Quaternion.Euler(rotation);
spawnType = SpawnType.TechType;
}

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="classId">ClassID to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation)
{
this.classId = classId;
this.spawnPosition = spawnPosition;
this.rotation = Quaternion.Euler(rotation);
spawnType = SpawnType.ClassId;
}

internal enum SpawnType
{
ClassId,
TechType
}
}
#endregion
}
}
Loading

0 comments on commit fe94523

Please sign in to comment.