mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-04 05:11:50 +01:00
Let the signatures of saved trainsets go with their sceneries
They were kept by the trainset's text for the whole session, behind one lock, and every reload added more. They are now kept as long as a trainset holds that text.
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using StarterNG.Classes;
|
using StarterNG.Classes;
|
||||||
@@ -163,17 +164,14 @@ public static class SceneryTrainsetText
|
|||||||
public static bool IsModified(Trainset trainset) =>
|
public static bool IsModified(Trainset trainset) =>
|
||||||
trainset.Parsed && Signature(trainset) != SavedSignature(trainset.RawEntry);
|
trainset.Parsed && Signature(trainset) != SavedSignature(trainset.RawEntry);
|
||||||
|
|
||||||
private static readonly Dictionary<string, string> SavedSignatures = new();
|
/// <summary>
|
||||||
|
/// By the text a trainset holds, for as long as one holds it: a scenery read again
|
||||||
|
/// brings texts of its own, and those of the one it replaces go with it.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly ConditionalWeakTable<string, string> SavedSignatures = new();
|
||||||
|
|
||||||
private static string SavedSignature(string raw)
|
private static string SavedSignature(string raw) =>
|
||||||
{
|
SavedSignatures.GetValue(raw, text => Signature(new Trainset(text)));
|
||||||
lock (SavedSignatures)
|
|
||||||
{
|
|
||||||
if (!SavedSignatures.TryGetValue(raw, out string? signature))
|
|
||||||
SavedSignatures[raw] = signature = Signature(new Trainset(raw));
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string Signature(Trainset trainset) =>
|
private static string Signature(Trainset trainset) =>
|
||||||
trainset.Velocity.ToString(CultureInfo.InvariantCulture) + "\n" +
|
trainset.Velocity.ToString(CultureInfo.InvariantCulture) + "\n" +
|
||||||
|
|||||||
Reference in New Issue
Block a user