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

Bump to 3.0.4 to support v1.17 #122

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions Docs/workshop/Beta/description.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[img]https://i.imgur.com/eFtUCf9.png[/img]
[img]https://i.imgur.com/a0VrMRr.png[/img]
[h1][b][BETA] Parallel Road Tool[/b][/h1]
helps you easily drawing parallel and stacked networks.

Expand All @@ -15,11 +15,11 @@ Main features are:
[quote]
[h1][b]Stable version is [url=https://steamcommunity.com/sharedfiles/filedetails/?id=1440928803]here[/url][/b].[/h1]
[h1][b]The beta version is meant for testing only and it can be unstable.[/b][/h1]
[b]Tested on C:S version 1.16.0-f3[/b]
[b]Tested on C:S version 1.17.0-f3[/b]
[/quote]

[quote]
[h1]Current version: [b]3.0.0-dev[/b][/h1]
[h1]Current version: [b]3.0.4-dev[/b][/h1]
[list]
[*] Moved mod core to Harmony for better compatibility with other mods
[*] Completely rewritten mod's core logic/engine
Expand Down
6 changes: 3 additions & 3 deletions Docs/workshop/Stable/description.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[img]https://i.imgur.com/eFtUCf9.png[/img]
[img]https://i.imgur.com/a0VrMRr.png[/img]
[h1][b]Parallel Road Tool[/b][/h1]
helps you easily drawing parallel and stacked networks.

Expand All @@ -14,11 +14,11 @@ Main features are:

[quote]
[h1]For new features and/or debugging, you can subscribe to the [url=https://steamcommunity.com/sharedfiles/filedetails/?id=1400711138]beta version[/url][/h1]
[b]Tested on C:S version 1.16.0-f3[/b]
[b]Tested on C:S version 1.17.0-f3[/b]
[/quote]

[quote]
[h1]Current version: [b]3.0.0[/b][/h1]
[h1]Current version: [b]3.0.4[/b][/h1]
[list]
[*] Moved mod core to Harmony for better compatibility with other mods
[*] Completely rewritten mod's core logic/engine
Expand Down
15 changes: 9 additions & 6 deletions ParallelRoadTool/Managers/ParallelRoadToolManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ParallelRoadToolManager.cs" company="ST-Apps (S. Tenuta)">
// <copyright file="ParallelRoadToolManager.cs" company="ST-Apps (S. Tenuta)">
// Copyright (c) ST-Apps (S. Tenuta). All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
// </copyright>
Expand Down Expand Up @@ -32,13 +32,13 @@ public class ParallelRoadToolManager : MonoBehaviour
/// Buffer where all the <see cref="NetTool.ControlPoint" /> generated during the overlay are stored.
/// These points will be retrieved just before network creation so that we don't have to recompute them.
/// </summary>
private readonly List<NetTool.ControlPoint[]> _controlPointsBuffer = new ();
private readonly List<NetTool.ControlPoint[]> _controlPointsBuffer = new();

/// <summary>
/// Buffer where nodes metadata will be stored while building.
/// This will map any node created with this mod with their corresponding offset one.
/// </summary>
private readonly Dictionary<ushort, NetTool.ControlPoint[]> _nodesBuffer = new ();
private readonly Dictionary<ushort, NetTool.ControlPoint[]> _nodesBuffer = new();

/// <summary>
/// Currently selected <see cref="NetInfo" /> using game's <see cref="NetTool" />.
Expand All @@ -59,7 +59,7 @@ public class ParallelRoadToolManager : MonoBehaviour
/// Gets the <see cref="List{T}" /> containing all the selected <see cref="NetInfoItem" /> objects.
/// This contains all the parallel/stacked networks that will be built once a main segment is created.
/// </summary>
public List<NetInfoItem> SelectedNetworkTypes { get; } = new ();
public List<NetInfoItem> SelectedNetworkTypes { get; } = new();

/// <summary>
/// Gets <see cref="List{T}" /> containing all the available <see cref="NetInfo" /> objects.
Expand Down Expand Up @@ -693,9 +693,12 @@ private void RefreshNetworks(bool sort = false)
// We clone the list to an array to select items using the right index, taken from previously sorted collection.
var tmpControlPoints = _controlPointsBuffer.ToArray();
_controlPointsBuffer.Clear();
foreach (var item in sorted)
if (tmpControlPoints.Any())
{
_controlPointsBuffer.Add(tmpControlPoints[item.Index]);
foreach (var item in sorted)
{
_controlPointsBuffer.Add(tmpControlPoints[item.Index]);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ParallelRoadTool/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class Mod : PatcherMod<UIOptionsPanel, PatcherBase>, IUserMod
/// <summary>
/// Minimum minor version that is compatible with the mod.
/// </summary>
private const string CompatibleVersion = "1.16";
private const string CompatibleVersion = "1.17";

/// <summary>
/// Simplified name, used for file-system operations.
Expand Down
2 changes: 1 addition & 1 deletion ParallelRoadTool/Models/NetInfoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public NetInfoItem(NetInfo netInfo, float horizontalOffset, float verticalOffset
/// <summary>
/// Gets network's name, used also as a unique id.
/// </summary>
public string Name => NetInfo.name;
public string Name => NetInfo?.name ?? "null";

/// <summary>
/// Gets a generated name used for display purposes.
Expand Down
54 changes: 54 additions & 0 deletions ParallelRoadTool/Patches/NetToolNodePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,60 @@ private static bool CanRun(bool test, bool visualize, bool switchDir)
[HarmonyPatch]
internal static class NetToolReversePatch
{
[HarmonyFinalizer]
[HarmonyPatch(
typeof(NetTool),
nameof(NetTool.CreateNode),
new[]
{
typeof(NetInfo),
typeof(NetTool.ControlPoint),
typeof(NetTool.ControlPoint),
typeof(NetTool.ControlPoint),
typeof(FastList<NetTool.NodePosition>),
typeof(int),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(ushort),
typeof(ushort),
typeof(ushort),
typeof(int),
typeof(int),
},
new[]
{
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Normal,
ArgumentType.Out,
ArgumentType.Out,
ArgumentType.Out,
ArgumentType.Out,
})]
static Exception Finalizer(Exception __exception)
{
if (__exception != null)
{
Log._Debug($"[{nameof(NetToolReversePatch)}.{nameof(Finalizer)}] Got exception: {__exception.Message}");
}

return null;
}

[HarmonyReversePatch]
[HarmonyPatch(
typeof(NetTool),
Expand Down
2 changes: 1 addition & 1 deletion ParallelRoadTool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
// 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("3.0.1")]
[assembly: AssemblyVersion("3.0.4")]
5 changes: 4 additions & 1 deletion ParallelRoadTool/UI/Presets/UIPresetDetailsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public UIPresetDetailsPanel()

public void ClearPreset()
{
_netItemsList.Clear();
if (_netItemsList != null)
{
_netItemsList.Clear();
}
}

public void LoadPreset(IEnumerable<NetInfoItem> networks)
Expand Down
46 changes: 28 additions & 18 deletions ParallelRoadTool/Utils/ControlPointUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ParallelRoadTool.Utils;
using Extensions;
using Managers;
using Patches;
using System;
using UnityEngine;

internal static class ControlPointUtils
Expand Down Expand Up @@ -258,23 +259,32 @@ public static bool CanCreate(
NetTool.ControlPoint currentEndPoint,
bool isReversed)
{
return NetToolReversePatch.CreateNode(
netInfo,
currentStartPoint,
currentMiddlePoint,
currentEndPoint,
NetTool.m_nodePositionsSimulation,
1000,
true,
false,
true,
true,
false,
isReversed,
0,
out _,
out _,
out _,
out _) == ToolBase.ToolErrors.None;
try
{
return NetToolReversePatch.CreateNode(
netInfo,
currentStartPoint,
currentMiddlePoint,
currentEndPoint,
NetTool.m_nodePositionsSimulation,
1000,
true,
false,
true,
true,
false,
isReversed,
0,
out _,
out _,
out _,
out _) == ToolBase.ToolErrors.None;
}
catch (Exception ex)
{
Log._Debug($"[{nameof(ControlPointUtils)}.{nameof(CanCreate)}] Caused an exception: {ex.Message}");
return false;
}

}
}
2 changes: 1 addition & 1 deletion ParallelRoadTool/Utils/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class Log
{
private static readonly object LogLock = new ();

private static readonly string LogFilename = Path.Combine(Application.dataPath, Path.Combine("Logs", "ParallelRoadTtool.log"));
private static readonly string LogFilename = Path.Combine(Application.dataPath, Path.Combine("Logs", "ParallelRoadTool.log"));

private static readonly Stopwatch Sw = Stopwatch.StartNew();

Expand Down
2 changes: 1 addition & 1 deletion Submodules/AlgernonCommons
2 changes: 1 addition & 1 deletion Translations/en-EN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"HARMONY_NOT_INSTALLED","The required Harmony 2 mod dependency was not installed","Possible cause of Harmony error - Harmony not installed."
"HARMONY_MOD_ERROR","An old and/or broken mod is preventing Harmony 2 from operating properly","Possible cause of Harmony error - a broken mod (not this one) can cause things to stop working."
"HARMONY_MOD_CONFLICT","Another mod may be trying to apply a conflicting Harmony patch","Possible cause of Harmony error - two mods trying to patch the same thing at once."
"WRONG_VERSION","Loading Screen Mod Revisited is not compatible with this game version.","Warning displayed on startup if an incompatible game version is detected"
"WRONG_VERSION","Parallel Road Tool is not compatible with this game version.","Warning displayed on startup if an incompatible game version is detected"
"SHUT_DOWN","As a safety measure, the mod has shut down and will not operate.","Warning displayed on startup if an incompatible game version is detected"
"MOD_DESCRIPTION","Helps you easily drawing parallel and stacked networks"
"FAILED","failed"
Expand Down