Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Metious committed Jun 25, 2024
2 parents a1d3154 + ecf439d commit 7b2b79c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Nautilus/Assets/PrefabInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static PrefabInfo WithTechType(string classId, bool unlockAtStart = false
/// <param name="displayName">The display name of this Tech Type, can be anything. If null or empty, this will use the language line "{enumName}" instead.</param>
/// <param name="description">The tooltip displayed when hovered in the PDA, can be anything. If null or empty, this will use the language line "Tooltip_{enumName}" instead.</param>
/// <param name="language">The language for this entry. Defaults to English.</param>
/// <param name="unlockAtStart">Whether this tech type should be unlocked on game start or not. Default to <see langword="true"/>.</param>
/// <param name="unlockAtStart">Whether this tech type should be unlocked on game start or not. Defaults to <see langword="false"/>.</param>
/// <param name="techTypeOwner">The assembly that owns the created tech type. The name of this assembly will be shown in the PDA.</param>
/// <returns>An instance of the constructed <see cref="PrefabInfo"/>.</returns>
public static PrefabInfo WithTechType(string classId, string displayName, string description, string language = "English", bool unlockAtStart = false, Assembly techTypeOwner = null)
Expand Down Expand Up @@ -109,4 +109,4 @@ public PrefabInfo WithFileName(string fileName)
{
return this with {PrefabFileName = fileName};
}
}
}
4 changes: 2 additions & 2 deletions Nautilus/Crafting/TabNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ internal TabNode(string[] path, CraftTree.Type scheme, Sprite sprite, string nam
Sprite = sprite;
DisplayName = displayName;
Name = name;
Id = $"{Scheme.ToString()}_{Name}";
Id = $"{Scheme.ToString()}Menu_{Name}";

ModSprite.Add(new ModSprite(SpriteManager.Group.Category, Id, Sprite));
ModSprite.Add(new ModSprite(SpriteManager.Group.Category, $"{Scheme.ToString()}_{Name}", Sprite));

if (!string.IsNullOrEmpty(displayName))
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
src: url("days_one.ttf");
}

[data-bs-theme=dark] .lang-diff {
background: #0d1117;
}

.lang-diff-rem {
color: rgb(236, 89, 117);
}

.lang-diff-add {
color: rgb(62, 175, 124);;
color: rgb(62, 175, 124);
}

@media (min-width: 1600px) {
Expand Down
48 changes: 36 additions & 12 deletions Nautilus/Documentation/guides/sml2-to-nautilus.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ In this article, we will be talking about the necessary changes you must apply t

## Namespace
The root namespace for Nautilus is not the same as SMLHelper 2.0.
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- &lt;RootNamespace&gt;SMLHelper.V2&lt;/RootNamespace&gt;</span>
<span class="lang-diff-add">+ &lt;RootNamespace&gt;Nautilus&lt;/RootNamespace&gt;</span>

</pre>

## Referencing
Expand All @@ -23,7 +25,8 @@ mentioned in your code.

### Handler.cs
Following the handler interfaces change, the overly under-used `Handler` class will leave us in Nautilus
<pre class="lang-diff">
<pre class="hljs">

// Handler.cs
<span class="lang-diff-rem">
- namespace SMLHelper.V2
Expand All @@ -45,16 +48,19 @@ Following the handler interfaces change, the overly under-used `Handler` class w
- ...
- }
</span>

</pre>

### BioReactorHandler
The `BioReactorHandler` class is removed in Nautilus because it only had one very simple method to patch, and was forcing patch-time. That means if you tried to modify a bio charge _after_
SML's entry point, it didn't get applied.

The following example demonstrates how you can implement the same functionality the `BioReactorHandler` class offered.
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- BioReactorHandler.SetBioreactorCharge(TechType.Peeper, 69f);</span>
<span class="lang-diff-add">+ BaseBioReactor.charge[TechType.Peeper] = 69f;</span>

</pre>

### FishHandler
Expand All @@ -63,7 +69,8 @@ The `FishHandler` has been removed in Nautilus. At the time being, we have not a

### PDAEncyclopediaHandler And PDALogHandler
Beginning with Nautilus, both of these handler methods were moved to `PDAHandler` as they only had one method each.
<pre class="lang-diff">
<pre class="hljs">

PDAEncyclopedia.EntryData entry = new PDAEncyclopedia.EntryData()
{
key = "SomeEncy",
Expand All @@ -76,13 +83,16 @@ PDAEncyclopedia.EntryData entry = new PDAEncyclopedia.EntryData()

<span class="lang-diff-rem">- PDALogHandler.AddCustomEntry("SomeLog", "SomeLanguageKey");</span>
<span class="lang-diff-add">+ PDAHandler.AddLogEntry("SomeLog", "SomeLanguageKey");</span>

</pre>

### InGameMenuHandler
The methods `InGameMenuHandler` class had have been moved to the `Nautilus.Utility` namespace and the class has been renamed to `SaveUtils`.
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- InGameMenuHandler.RegisterOnSaveEvent(() => ErrorMessage.AddMessage("We do be saving!"));</span>
<span class="lang-diff-add">+ SaveUtils.RegisterOnSaveEvent(() => ErrorMessage.AddMessage("We do be saving!"));</span>

</pre>

## Enum Handlers
Expand Down Expand Up @@ -117,51 +127,63 @@ Below we will talk about the necessary changes you will need to make your custom


### Configuring Custom TechType Objects
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- TechType customTech = TechTypeHandler.AddTechType("CustomTech", "Custom Tech", "Custom Tech that makes me go yes.", SpriteManager.Get(TechType.Titanium), unlockedAtStart: false);</span>
<span class="lang-diff-add">+ TechType customTech = EnumHandler.AddEntry&lt;TechType&gt;("CustomTech")
+ .WithPdaInfo("Custom Tech", "Custom Tech that makes me go yes.", unlockedAtStart: false)
+ .WithIcon(SpriteManager.Get(TechType.Titanium));</span>

</pre>

### Configuring Custom CraftData.BackgroundType Objects
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- CraftData.BackgroundType customBG = BackgroundTypeHandler.AddBackgroundType("CustomBackground", SpriteManager.GetBackground(TechType.Battery));</span>
<span class="lang-diff-add">+ CraftData.BackgroundType customBG = EnumHandler.AddEntry&lt;CraftData.BackgroundType&gt;("CustomBackground")
+ .WithBackground(SpriteManager.GetBackground(TechType.Battery));</span>

</pre>

### Configuring Custom EquipmentType Objects
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- EquipmentType customEquipment = EquipmentHandler.AddEquipmentType("CustomEquipment");</span>
<span class="lang-diff-add">+ EquipmentType customEquipment = EnumHandler.AddEntry&lt;EquipmentType&gt;("CustomEquipment");</span>

</pre>

### Configuring Custom PingType Objects
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- PingType customPing = PingHandler.RegisterNewPingType("CustomPing", SpriteManager.Get(SpriteManager.Group.Pings, PingType.Signal.ToString()));</span>
<span class="lang-diff-add">+ PingType customPing = EnumHandler.AddEntry&lt;PingType&gt;("CustomPing")
+ .WithIcon(SpriteManager.Get(SpriteManager.Group.Pings, PingType.Signal.ToString()));</span>

</pre>

### Configuring Custom TechCategory and TechGroup Objects
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- TechGroup customGroup = TechGroupHandler.AddTechCategory("CustomGroup", "Custom Group");</span>
<span class="lang-diff-add">+ TechGroup customGroup = EnumHandler.AddEntry&lt;TechCategory&gt;("CustomGroup").WithPdaInfo("Custom Group");</span>

<span class="lang-diff-rem">- TechCategory customCategory = TechCategoryHandler.AddTechCategory("CustomCategory", "Custom Category");
- TechCategoryHandler.TryRegisterTechCategoryToTechGroup(customGroup, customCategory);</span>
<span class="lang-diff-add">+ TechCategory customCategory = EnumHandler.AddEntry&lt;TechCategory&gt;("CustomCategory").WithPdaInfo("Custom Group")
+ .RegisterToTechGroup(customGroup);</span>

</pre>

### Configuring Custom CraftTree.Type Objects
<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- ModCraftTreeRoot root = CraftTreeHandler.CreateCustomCraftTreeAndType(CustomTree, out CraftTree.Type customTree);</span>
<span class="lang-diff-add">+ CraftTree.Type customTree = EnumHandler.AddEntry&lt;CraftTree.Type&gt;("CustomTree")
+ .CreateCraftTreeRoot(out ModCraftTreeRoot root);</span>

root.AddTabNode("SomeTab");

</pre>

___
Expand Down Expand Up @@ -512,7 +534,8 @@ Since we discovered the best practices and better ways to deal with custom sound
Beginning with Nautilus, all custom sounds will require a bus instead of a SoundChannel to determine the effects (E.G: reverb, muffling, low-pass, etc..) and the volume slider.
Additionally, the `PlaySound` signature was also modified and renamed to `TryPlaySound`.

<pre class="lang-diff">
<pre class="hljs">

<span class="lang-diff-rem">- Channel channel = AudioUtils.PlaySound(soundPath, SoundChannel.Music);</span>
<span class="lang-diff-add">+ if (AudioUtils.TryPlaySound(soundPath, AudioUtils.BusPaths.Music, out Channel channel))
+ {
Expand Down Expand Up @@ -540,6 +563,7 @@ Additionally, the `PlaySound` signature was also modified and renamed to `TryPla
+ // do something with channel
+ }
</span>

</pre>

> [!WARNING]
Expand Down
46 changes: 35 additions & 11 deletions Nautilus/Handlers/CoordinatedSpawnsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,23 @@ public struct SpawnInfo : IEquatable<SpawnInfo>
internal Vector3 Scale { get; }
// For the sake of backwards compatibility, a scale of 0x0x0 is automatically converted to 1x1x1. Sorry, no 0x scale entities allowed.
internal Vector3 ActualScale => Scale == default ? Vector3.one : Scale;
internal Action<GameObject> OnSpawned { get; }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="techType">TechType to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition)
: this(default, techType, spawnPosition, Quaternion.identity, Vector3.one) { }
: this(default, techType, spawnPosition, Quaternion.identity, Vector3.one, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="classId">ClassID to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
public SpawnInfo(string classId, Vector3 spawnPosition)
: this(classId, default, spawnPosition, Quaternion.identity, Vector3.one) { }
: this(classId, default, spawnPosition, Quaternion.identity, Vector3.one, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -101,7 +102,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition)
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation)
: this(default, techType, spawnPosition, rotation, Vector3.one) { }
: this(default, techType, spawnPosition, rotation, Vector3.one, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -110,7 +111,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation)
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation)
: this(classId, default, spawnPosition, rotation, Vector3.one) { }
: this(classId, default, spawnPosition, rotation, Vector3.one, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -120,7 +121,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation)
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale)
: this(default, techType, spawnPosition, rotation, scale) { }
: this(default, techType, spawnPosition, rotation, scale, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -130,7 +131,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation,
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vector3 scale)
: this(classId, default, spawnPosition, rotation, scale) { }
: this(classId, default, spawnPosition, rotation, scale, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -139,7 +140,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vec
/// <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(default, techType, spawnPosition, Quaternion.Euler(rotation), Vector3.one) { }
: this(default, techType, spawnPosition, Quaternion.Euler(rotation), Vector3.one, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -148,7 +149,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation)
/// <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, default, spawnPosition, Quaternion.Euler(rotation), Vector3.one) { }
: this(classId, default, spawnPosition, Quaternion.Euler(rotation), Vector3.one, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -158,7 +159,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation)
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation, Vector3 scale)
: this(default, techType, spawnPosition, Quaternion.Euler(rotation), scale) { }
: this(default, techType, spawnPosition, Quaternion.Euler(rotation), scale, null) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -168,10 +169,32 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation, Vec
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation, Vector3 scale)
: this(classId, default, spawnPosition, Quaternion.Euler(rotation), scale) { }
: this(classId, default, spawnPosition, Quaternion.Euler(rotation), scale, null) { }

/// <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>
/// <param name="scale">Scale to spawn with.</param>
/// <param name="onSpawned">Callback that is used when the object is successfully spawned.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale, Action<GameObject> onSpawned)
: this(default, techType, spawnPosition, rotation, scale, onSpawned) { }

/// <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>
/// <param name="scale">Scale to spawn with.</param>
/// <param name="onSpawned">Callback that is used when the object is successfully spawned.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vector3 scale, Action<GameObject> onSpawned)
: this(classId, default, spawnPosition, rotation, scale, onSpawned) { }

[JsonConstructor]
internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale)
internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale, Action<GameObject> onSpawned)
{
ClassId = classId;
TechType = techType;
Expand All @@ -183,6 +206,7 @@ internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Qua
_ => SpawnType.TechType
};
Scale = scale;
OnSpawned = onSpawned;
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Nautilus/Handlers/PrefabHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ private static IEnumerator InitPrefabAsync(TaskResult<GameObject> gameObject, Pr
InternalLogger.Error($"PrefabHandler: PrefabFactory returned null for {info.ClassID}");
yield break;
}
obj.SetActive(false);

var techType = info.TechType;
var classId = info.ClassID;
Expand Down
2 changes: 2 additions & 0 deletions Nautilus/MonoBehaviours/EntitySpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private IEnumerator SpawnAsync()

obj.SetActive(true);

spawnInfo.OnSpawned?.Invoke(obj);

LargeWorldEntity.Register(obj);

LargeWorldStreamerPatcher.SavedSpawnInfos.Add(spawnInfo);
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"template": [
"default",
"modern",
"DocFX/template"
"DocFX/custom"
]
}
}
2 changes: 1 addition & 1 deletion Version.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- The assembly uses this version number. !-->
<VersionPrefix>1.0.0</VersionPrefix>
<SuffixNumber>30</SuffixNumber>
<SuffixNumber>32</SuffixNumber>
<VersionSuffix>pre.$(SuffixNumber)</VersionSuffix>
</PropertyGroup>
</Project>

0 comments on commit 7b2b79c

Please sign in to comment.