Starting implement deserialize migration
This commit is contained in:
28
2DGAMELIB/_2DGAMELIB/ObjExtensions.cs
Normal file
28
2DGAMELIB/_2DGAMELIB/ObjExtensions.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace _2DGAMELIB
|
||||
{
|
||||
public static class ObjExtensions
|
||||
{
|
||||
static readonly Dictionary<string, string> KeyMap = new()
|
||||
{
|
||||
["咳"] = "Cough"
|
||||
};
|
||||
|
||||
public static void MigrateKeys(this Obj obj)
|
||||
{
|
||||
var newDict = new OrderedDictionary<string, Difs>();
|
||||
|
||||
foreach (var key in obj.Keys)
|
||||
{
|
||||
var newKey = KeyMap.TryGetValue(key, out var mapped) ? mapped : key;
|
||||
|
||||
newDict.Add(newKey, obj.Difss[key]);
|
||||
}
|
||||
|
||||
obj.Difss = newDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ namespace _2DGAMELIB
|
||||
|
||||
private static double s0;
|
||||
|
||||
|
||||
public static Color Reverse(this Color c)
|
||||
{
|
||||
return Color.FromArgb(c.A, 255 - c.R, 255 - c.G, 255 - c.B);
|
||||
@@ -159,10 +158,12 @@ namespace _2DGAMELIB
|
||||
|
||||
public static Obj ObjLoad(this byte[] bd)
|
||||
{
|
||||
return bd.Load<byte[]>().ToDeserialObject<Obj>().SetDefaultR();
|
||||
}
|
||||
Obj obj = bd.Load<byte[]>().ToDeserialObject<Obj>().SetDefaultR();
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static bool Lot(this double p)
|
||||
|
||||
public static bool Lot(this double p)
|
||||
{
|
||||
return RNG.XS.NextDouble() < p;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user