Used string representation of text alignment on unpacking, used bool type for flags in parameters

fonts_experiment 1.0.2.2
Valeriy Mironov 2017-12-09 14:36:15 +02:00
parent 1eb3d0f292
commit 6235ac685f
7 changed files with 55 additions and 19 deletions

View File

@ -9,7 +9,7 @@ namespace WatchFace.Parser.Elements.AnalogDialFaceElements
public class ClockHand
{
[ParameterId(1)]
public long OnlyBorder { get; set; }
public bool OnlyBorder { get; set; }
[JsonConverter(typeof(HexStringJsonConverter))]
[ParameterId(2)]

View File

@ -1,4 +1,7 @@
using WatchFace.Parser.Attributes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using WatchFace.Parser.Attributes;
using WatchFace.Parser.Models;
namespace WatchFace.Parser.Elements.BasicElements
{
@ -17,7 +20,8 @@ namespace WatchFace.Parser.Elements.BasicElements
public long BottomRightY { get; set; }
[ParameterId(5)]
public long Alignment { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public TextAlignment Alignment { get; set; }
[ParameterId(6)]
public long Spacing { get; set; }

View File

@ -11,9 +11,9 @@ namespace WatchFace.Parser.Elements.DateElements
public OneLineMonthAndDay OneLine { get; set; }
[ParameterId(3)]
public long TwoDigitsMonth { get; set; }
public bool TwoDigitsMonth { get; set; }
[ParameterId(4)]
public long TwoDigitsDay { get; set; }
public bool TwoDigitsDay { get; set; }
}
}

View File

@ -17,7 +17,7 @@ namespace WatchFace.Parser.Elements.WeatherElements
public long DelimiterImageIndex { get; set; }
[ParameterId(4)]
public long AppendDegreesForBoth { get; set; }
public bool AppendDegreesForBoth { get; set; }
[ParameterId(5)]
[ParameterImageIndex]

View File

@ -7,7 +7,22 @@ namespace WatchFace.Parser.Models
{
Left = 2,
Right = 4,
HCenter = 8,
Top = 16,
Bottom = 32
Bottom = 32,
VCenter = 64,
TopCenter = Top | HCenter,
TopLeft = Top | Left,
TopRight = Top | Right,
Center = VCenter | HCenter,
CenterLeft = VCenter | Left,
CenterRight = VCenter | Right,
BottomCenter = Bottom | HCenter,
BottomLeft = Bottom | Left,
BottomRight = Bottom | Right
}
}

View File

@ -31,10 +31,18 @@ namespace WatchFace.Parser.Utils
if (propertyValue == null)
continue;
if (propertyType == typeof(long))
if (propertyType == typeof(long) ||
propertyType == typeof(TextAlignment) ||
propertyType == typeof(bool))
{
Logger.Trace("{0} '{1}': {2}", currentPath, propertyInfo.Name, propertyValue);
result.Add(new Parameter(id, propertyValue));
long value;
if (propertyType == typeof(bool))
value = propertyValue ? 1 : 0;
else
value = (long) propertyValue;
Logger.Trace("{0} '{1}': {2}", currentPath, propertyInfo.Name, value);
result.Add(new Parameter(id, value));
}
else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
@ -51,6 +59,7 @@ namespace WatchFace.Parser.Utils
result.Add(new Parameter(id, Build(propertyValue, currentPath)));
}
}
return result;
}
@ -75,8 +84,10 @@ namespace WatchFace.Parser.Utils
var propertyInfo = properties[parameter.Id];
var propertyType = propertyInfo.PropertyType;
if (propertyType == typeof(long) || propertyType.IsGenericType &&
propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
if (propertyType == typeof(long) ||
propertyType == typeof(TextAlignment) ||
propertyType == typeof(bool) ||
propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
Logger.Trace("{0} '{1}': {2}", currentPath, propertyInfo.Name, parameter.Value);
dynamic propertyValue = propertyInfo.GetValue(result, null);
@ -84,10 +95,15 @@ namespace WatchFace.Parser.Utils
if (propertyType.IsGenericType && propertyValue != null)
throw new ArgumentException($"Parameter {parameter.Id} is already set for {currentType.Name}");
if (!propertyType.IsGenericType && propertyValue != 0)
if (!propertyType.IsGenericType && propertyType == typeof(long) && propertyValue != 0)
throw new ArgumentException($"Parameter {parameter.Id} is already set for {currentType.Name}");
propertyInfo.SetValue(result, parameter.Value, null);
if (propertyType == typeof(TextAlignment))
propertyInfo.SetValue(result, (TextAlignment) parameter.Value, null);
else if (propertyType == typeof(bool))
propertyInfo.SetValue(result, parameter.Value > 0, null);
else
propertyInfo.SetValue(result, parameter.Value, null);
}
else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List<>))
{
@ -128,6 +144,7 @@ namespace WatchFace.Parser.Utils
}
}
}
return result;
}
}

View File

@ -217,7 +217,7 @@ namespace WatchFace
}
catch (Exception e)
{
Logger.Fatal(e.Message);
Logger.Fatal(e);
File.Delete(outputFileName);
}
}
@ -237,7 +237,7 @@ namespace WatchFace
}
catch (Exception e)
{
Logger.Fatal(e.Message);
Logger.Fatal(e);
return null;
}
}
@ -251,7 +251,7 @@ namespace WatchFace
}
catch (Exception e)
{
Logger.Fatal(e.Message);
Logger.Fatal(e);
return null;
}
}
@ -283,7 +283,7 @@ namespace WatchFace
}
catch (Exception e)
{
Logger.Fatal(e.Message);
Logger.Fatal(e);
return null;
}
}
@ -303,7 +303,7 @@ namespace WatchFace
}
catch (Exception e)
{
Logger.Fatal(e.Message);
Logger.Fatal(e);
}
}