Use abstraction, switch from hexString to int

pull/54/head
Alexis Drai 2 years ago
parent 20b57ce31b
commit 7c0c0d5fd9

@ -8,14 +8,37 @@ namespace Model
{
public class ColorDieFace : AbstractDieFace
{
private string ColorHex;
/// <summary>
/// a decimal representation of the hex (...representation of the color)
/// </summary>
protected override int Value { get; }
public ColorDieFace(string v)
/// <summary>
/// accepts hex strings like "ffbb84" ([RRGGBB])
/// </summary>
/// <param name="hexValueString">hex string</param>
public ColorDieFace(string hexValueString)
{
this.ColorHex = v;
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
// if style is ("f0b"), this constructor can develop it to "ff00bb" before doing the job
Value = int.Parse(hexValueString, System.Globalization.NumberStyles.HexNumber);
}
public string getColorHex() { return ColorHex; }
public void setColorHex(string ColorHex) { this.ColorHex = ColorHex; }
/// <summary>
/// accepts a decimal value that represents a color hex (0 is black, 65280 is green...)
/// </summary>
/// <param name="decimalValue"></param>
public ColorDieFace(int decimalValue)
{
Value = decimalValue;
}
public override object GetPracticalValue()
{
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
// maybe prepend it with a "#"...
return Value.ToString("X");
}
}
}

Loading…
Cancel
Save