Fixed Ele/EleD and EleI remapping using additional mappings

This commit is contained in:
2026-06-14 00:28:31 +02:00
parent 2f40eb2660
commit 52e7023bd7
2 changed files with 22 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text;
namespace _2DGAMELIB namespace _2DGAMELIB
{ {
@@ -9,6 +9,12 @@ namespace _2DGAMELIB
{ {
private readonly Dictionary<string, Type> _typeOnlyMap = new(); private readonly Dictionary<string, Type> _typeOnlyMap = new();
private readonly Dictionary<string, (string AssemblyName, Type Type)> _fullMap = new(); private readonly Dictionary<string, (string AssemblyName, Type Type)> _fullMap = new();
private static readonly ConcurrentDictionary<string, Type> _additionalMappings = new();
public static void RegisterMapping(string oldTypeName, Type newType)
{
_additionalMappings[oldTypeName] = newType;
}
public RemappedTypeBinder Add(string oldTypeName, Type newType) public RemappedTypeBinder Add(string oldTypeName, Type newType)
{ {
@@ -33,6 +39,9 @@ namespace _2DGAMELIB
if (_typeOnlyMap.TryGetValue(typeName, out var type)) if (_typeOnlyMap.TryGetValue(typeName, out var type))
return type; return type;
if (_additionalMappings.TryGetValue(typeName, out var extra))
return extra;
var fullName = typeName; var fullName = typeName;
if (!string.IsNullOrEmpty(assemblyName)) if (!string.IsNullOrEmpty(assemblyName))
fullName += ", " + assemblyName; fullName += ", " + assemblyName;
@@ -90,11 +99,16 @@ namespace _2DGAMELIB
var inner = typeName.Substring(bracketStart, bracketEnd - bracketStart + 1); var inner = typeName.Substring(bracketStart, bracketEnd - bracketStart + 1);
// Replace mapped old type names (longest first to avoid partial prefix matches) // Replace mapped old type names (longest first to avoid partial prefix matches)
var sortedKeys = new List<string>(_typeOnlyMap.Keys); var allKeys = new List<string>(_typeOnlyMap.Keys);
sortedKeys.Sort((a, b) => b.Length.CompareTo(a.Length)); allKeys.AddRange(_additionalMappings.Keys);
foreach (var old in sortedKeys) allKeys.Sort((a, b) => b.Length.CompareTo(a.Length));
foreach (var old in allKeys)
{ {
var rep = _typeOnlyMap[old].FullName; Type repType;
if (!_typeOnlyMap.TryGetValue(old, out repType))
_additionalMappings.TryGetValue(old, out repType);
if (repType == null) continue;
var rep = repType.FullName;
inner = inner.Replace(old + ",", rep + ","); inner = inner.Replace(old + ",", rep + ",");
inner = inner.Replace(old + "]", rep + "]"); inner = inner.Replace(old + "]", rep + "]");
} }

View File

@@ -9,6 +9,9 @@ namespace SlaveMatrix
static Program() static Program()
{ {
AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);
RemappedTypeBinder.RegisterMapping("SlaveMatrix.Ele", typeof(Element));
RemappedTypeBinder.RegisterMapping("SlaveMatrix.EleD", typeof(ElementData));
RemappedTypeBinder.RegisterMapping("SlaveMatrix.EleI", typeof(ElementInstance));
} }
[STAThread] [STAThread]