Used string representation of text alignment on unpacking, used bool type for flags in parameters
parent
1eb3d0f292
commit
6235ac685f
|
@ -9,7 +9,7 @@ namespace WatchFace.Parser.Elements.AnalogDialFaceElements
|
||||||
public class ClockHand
|
public class ClockHand
|
||||||
{
|
{
|
||||||
[ParameterId(1)]
|
[ParameterId(1)]
|
||||||
public long OnlyBorder { get; set; }
|
public bool OnlyBorder { get; set; }
|
||||||
|
|
||||||
[JsonConverter(typeof(HexStringJsonConverter))]
|
[JsonConverter(typeof(HexStringJsonConverter))]
|
||||||
[ParameterId(2)]
|
[ParameterId(2)]
|
||||||
|
|
|
@ -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
|
namespace WatchFace.Parser.Elements.BasicElements
|
||||||
{
|
{
|
||||||
|
@ -17,7 +20,8 @@ namespace WatchFace.Parser.Elements.BasicElements
|
||||||
public long BottomRightY { get; set; }
|
public long BottomRightY { get; set; }
|
||||||
|
|
||||||
[ParameterId(5)]
|
[ParameterId(5)]
|
||||||
public long Alignment { get; set; }
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
|
public TextAlignment Alignment { get; set; }
|
||||||
|
|
||||||
[ParameterId(6)]
|
[ParameterId(6)]
|
||||||
public long Spacing { get; set; }
|
public long Spacing { get; set; }
|
||||||
|
|
|
@ -11,9 +11,9 @@ namespace WatchFace.Parser.Elements.DateElements
|
||||||
public OneLineMonthAndDay OneLine { get; set; }
|
public OneLineMonthAndDay OneLine { get; set; }
|
||||||
|
|
||||||
[ParameterId(3)]
|
[ParameterId(3)]
|
||||||
public long TwoDigitsMonth { get; set; }
|
public bool TwoDigitsMonth { get; set; }
|
||||||
|
|
||||||
[ParameterId(4)]
|
[ParameterId(4)]
|
||||||
public long TwoDigitsDay { get; set; }
|
public bool TwoDigitsDay { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ namespace WatchFace.Parser.Elements.WeatherElements
|
||||||
public long DelimiterImageIndex { get; set; }
|
public long DelimiterImageIndex { get; set; }
|
||||||
|
|
||||||
[ParameterId(4)]
|
[ParameterId(4)]
|
||||||
public long AppendDegreesForBoth { get; set; }
|
public bool AppendDegreesForBoth { get; set; }
|
||||||
|
|
||||||
[ParameterId(5)]
|
[ParameterId(5)]
|
||||||
[ParameterImageIndex]
|
[ParameterImageIndex]
|
||||||
|
|
|
@ -7,7 +7,22 @@ namespace WatchFace.Parser.Models
|
||||||
{
|
{
|
||||||
Left = 2,
|
Left = 2,
|
||||||
Right = 4,
|
Right = 4,
|
||||||
|
HCenter = 8,
|
||||||
|
|
||||||
Top = 16,
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,10 +31,18 @@ namespace WatchFace.Parser.Utils
|
||||||
if (propertyValue == null)
|
if (propertyValue == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (propertyType == typeof(long))
|
if (propertyType == typeof(long) ||
|
||||||
|
propertyType == typeof(TextAlignment) ||
|
||||||
|
propertyType == typeof(bool))
|
||||||
{
|
{
|
||||||
Logger.Trace("{0} '{1}': {2}", currentPath, propertyInfo.Name, propertyValue);
|
long value;
|
||||||
result.Add(new Parameter(id, propertyValue));
|
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<>))
|
else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||||
{
|
{
|
||||||
|
@ -51,6 +59,7 @@ namespace WatchFace.Parser.Utils
|
||||||
result.Add(new Parameter(id, Build(propertyValue, currentPath)));
|
result.Add(new Parameter(id, Build(propertyValue, currentPath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +84,10 @@ namespace WatchFace.Parser.Utils
|
||||||
var propertyInfo = properties[parameter.Id];
|
var propertyInfo = properties[parameter.Id];
|
||||||
var propertyType = propertyInfo.PropertyType;
|
var propertyType = propertyInfo.PropertyType;
|
||||||
|
|
||||||
if (propertyType == typeof(long) || propertyType.IsGenericType &&
|
if (propertyType == typeof(long) ||
|
||||||
propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
propertyType == typeof(TextAlignment) ||
|
||||||
|
propertyType == typeof(bool) ||
|
||||||
|
propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||||
{
|
{
|
||||||
Logger.Trace("{0} '{1}': {2}", currentPath, propertyInfo.Name, parameter.Value);
|
Logger.Trace("{0} '{1}': {2}", currentPath, propertyInfo.Name, parameter.Value);
|
||||||
dynamic propertyValue = propertyInfo.GetValue(result, null);
|
dynamic propertyValue = propertyInfo.GetValue(result, null);
|
||||||
|
@ -84,10 +95,15 @@ namespace WatchFace.Parser.Utils
|
||||||
if (propertyType.IsGenericType && propertyValue != null)
|
if (propertyType.IsGenericType && propertyValue != null)
|
||||||
throw new ArgumentException($"Parameter {parameter.Id} is already set for {currentType.Name}");
|
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}");
|
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<>))
|
else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List<>))
|
||||||
{
|
{
|
||||||
|
@ -128,6 +144,7 @@ namespace WatchFace.Parser.Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ namespace WatchFace
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal(e.Message);
|
Logger.Fatal(e);
|
||||||
File.Delete(outputFileName);
|
File.Delete(outputFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ namespace WatchFace
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal(e.Message);
|
Logger.Fatal(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ namespace WatchFace
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal(e.Message);
|
Logger.Fatal(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ namespace WatchFace
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal(e.Message);
|
Logger.Fatal(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ namespace WatchFace
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal(e.Message);
|
Logger.Fatal(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue