Skip to content

Commit

Permalink
as requested by teinarrs.
Browse files Browse the repository at this point in the history
  • Loading branch information
anvilvapre committed Mar 16, 2021
1 parent 029c8e9 commit d1c430c
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions OpenRA.Game/FieldLoader.cs
Expand Up @@ -74,50 +74,48 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
new ConcurrentCache<string, IntegerExpression>(expression => new IntegerExpression(expression));

static readonly Dictionary<Type, Func<string, Type, string, MemberInfo, object>> TypeParsers =
new Dictionary<Type, Func<string, Type, string, MemberInfo, object>>();
new Dictionary<Type, Func<string, Type, string, MemberInfo, object>>()
{
{ typeof(int), ParseInt },
{ typeof(ushort), ParseUShort },
{ typeof(long), ParseLong },
{ typeof(float), ParseFloat },
{ typeof(decimal), ParseDecimal },
{ typeof(string), ParseString },
{ typeof(Color), ParseColor },
{ typeof(Hotkey), ParseHotkey },
{ typeof(HotkeyReference), ParseHotkeyReference },
{ typeof(WDist), ParseWDist },
{ typeof(WVec), ParseWVec },
{ typeof(WVec[]), ParseWVecArray },
{ typeof(WPos), ParseWPos },
{ typeof(WAngle), ParseWAngle },
{ typeof(WRot), ParseWRot },
{ typeof(CPos), ParseCPos },
{ typeof(CVec), ParseCVec },
{ typeof(CVec[]), ParseCVecArray },
{ typeof(BooleanExpression), ParseBooleanExpression },
{ typeof(IntegerExpression), ParseIntegerExpression },
{ typeof(Enum), ParseEnum },
{ typeof(bool), ParseBool },
{ typeof(int2[]), ParseInt2Array },
{ typeof(Size), ParseSize },
{ typeof(int2), ParseInt2 },
{ typeof(float2), ParseFloat2 },
{ typeof(float3), ParseFloat3 },
{ typeof(Rectangle), ParseRectangle },
{ typeof(DateTime), ParseDateTime }
};

static readonly Dictionary<Type, Func<string, Type, string, MiniYaml, MemberInfo, object>> GenericTypeParsers =
new Dictionary<Type, Func<string, Type, string, MiniYaml, MemberInfo, object>>();

static FieldLoader()
{
TypeParsers.Add(typeof(int), ParseInt);
TypeParsers.Add(typeof(ushort), ParseUShort);
TypeParsers.Add(typeof(long), ParseLong);
TypeParsers.Add(typeof(float), ParseFloat);
TypeParsers.Add(typeof(decimal), ParseDecimal);
TypeParsers.Add(typeof(string), ParseString);
TypeParsers.Add(typeof(Color), ParseColor);
TypeParsers.Add(typeof(Hotkey), ParseHotkey);
TypeParsers.Add(typeof(HotkeyReference), ParseHotkeyReference);
TypeParsers.Add(typeof(WDist), ParseWDist);
TypeParsers.Add(typeof(WVec), ParseWVec);
TypeParsers.Add(typeof(WVec[]), ParseWVecArray);
TypeParsers.Add(typeof(WPos), ParseWPos);
TypeParsers.Add(typeof(WAngle), ParseWAngle);
TypeParsers.Add(typeof(WRot), ParseWRot);
TypeParsers.Add(typeof(CPos), ParseCPos);
TypeParsers.Add(typeof(CVec), ParseCVec);
TypeParsers.Add(typeof(CVec[]), ParseCVecArray);
TypeParsers.Add(typeof(BooleanExpression), ParseBooleanExpression);
TypeParsers.Add(typeof(IntegerExpression), ParseIntegerExpression);
TypeParsers.Add(typeof(Enum), ParseEnum);
TypeParsers.Add(typeof(bool), ParseBool);
TypeParsers.Add(typeof(int2[]), ParseInt2Array);
TypeParsers.Add(typeof(Size), ParseSize);
TypeParsers.Add(typeof(int2), ParseInt2);
TypeParsers.Add(typeof(float2), ParseFloat2);
TypeParsers.Add(typeof(float3), ParseFloat3);
TypeParsers.Add(typeof(Rectangle), ParseRectangle);
TypeParsers.Add(typeof(DateTime), ParseDateTime);
TypeParsers.TrimExcess();

GenericTypeParsers.Add(typeof(HashSet<>), ParseHashSetOrList);
GenericTypeParsers.Add(typeof(List<>), ParseHashSetOrList);
GenericTypeParsers.Add(typeof(Dictionary<,>), ParseDictionary);
GenericTypeParsers.Add(typeof(BitSet<>), ParseBitSet);
GenericTypeParsers.Add(typeof(Nullable<>), ParseNullable);
GenericTypeParsers.TrimExcess();
}
new Dictionary<Type, Func<string, Type, string, MiniYaml, MemberInfo, object>>()
{
{ typeof(HashSet<>), ParseHashSetOrList },
{ typeof(List<>), ParseHashSetOrList },
{ typeof(Dictionary<,>), ParseDictionary },
{ typeof(BitSet<>), ParseBitSet },
{ typeof(Nullable<>), ParseNullable },
};

static object ParseInt(string fieldName, Type fieldType, string value, MemberInfo field)
{
Expand Down

0 comments on commit d1c430c

Please sign in to comment.