Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Biome and Goto commands #515

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow adding teleports w/ console command handler
  • Loading branch information
LeeTwentyThree committed Dec 20, 2023
commit 65e5de1ae64b61689aabc5148af409acacfc3928
13 changes: 13 additions & 0 deletions Nautilus/Handlers/ConsoleCommandsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;
using Nautilus.Commands;
using Nautilus.Patchers;
using UnityEngine;

namespace Nautilus.Handlers;

Expand Down Expand Up @@ -79,4 +80,16 @@ public static void RegisterConsoleCommands(Type type)
{
ConsoleCommandsPatcher.ParseCustomCommands(type);
}

public static void AddBiomeTeleportPosition(string biomeName, Vector3 position)
{
ConsoleCommandsPatcher.BiomeTeleportPositionsToAdd.Add(new TeleportPosition{name = biomeName, position = position});
ConsoleCommandsPatcher.UpdateTeleportPositions();
}

public static void AddGotoTeleportPosition(string locationName, Vector3 position)
{
ConsoleCommandsPatcher.GotoTeleportPositionsToAdd.Add(new TeleportPosition{name = locationName, position = position});
ConsoleCommandsPatcher.UpdateTeleportPositions();
}
}
37 changes: 37 additions & 0 deletions Nautilus/Patchers/ConsoleCommandsPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ internal static class ConsoleCommandsPatcher
private static Color ModOriginColor = new(0, 1, 0);
private static Color ModConflictColor = new(0.75f, 0.75f, 0.75f);

internal static List<TeleportPosition> GotoTeleportPositionsToAdd = new List<TeleportPosition>();
internal static List<TeleportPosition> BiomeTeleportPositionsToAdd = new List<TeleportPosition>();

public static void Patch(Harmony harmony)
{
harmony.PatchAll(typeof(ConsoleCommandsPatcher));
Expand Down Expand Up @@ -281,4 +284,38 @@ public static string StripXML(this string source)
{
return xmlRegex.Replace(source, string.Empty);
}

[HarmonyPatch(typeof(GotoConsoleCommand), nameof(GotoConsoleCommand.Awake))]
[HarmonyPostfix]
private static void GotoConsoleCommandAwakePostfix(GotoConsoleCommand __instance)
{
UpdateTeleportPositions();
}

[HarmonyPatch(typeof(BiomeConsoleCommand), nameof(BiomeConsoleCommand.Awake))]
[HarmonyPostfix]
private static void BiomeConsoleCommandAwakePostfix(BiomeConsoleCommand __instance)
{
UpdateTeleportPositions();
}

internal static void UpdateTeleportPositions()
{
if (GotoConsoleCommand.main != null && GotoTeleportPositionsToAdd.Count > 0)
{
AddTeleportPositionsToCommandData(GotoConsoleCommand.main.data, GotoTeleportPositionsToAdd);
}
if (BiomeConsoleCommand.main != null && BiomeTeleportPositionsToAdd.Count > 0)
{
AddTeleportPositionsToCommandData(BiomeConsoleCommand.main.data, BiomeTeleportPositionsToAdd);
}
}

private static void AddTeleportPositionsToCommandData(TeleportCommandData commandData, List<TeleportPosition> positionsToAdd)
{
var list = new List<TeleportPosition>(commandData.locations);
list.AddRange(positionsToAdd);
commandData.locations = list.ToArray();
positionsToAdd.Clear();
}
}