This commit is contained in:
7H3LaughingMan 2025-05-01 21:52:34 +00:00 committed by GitHub
commit 9138b4072c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1092 additions and 51 deletions

View file

@ -0,0 +1,225 @@
using System.Globalization;
namespace DotTiled.Tests.UnitTests;
public class TiledColorTests
{
[Fact]
public void DefaultConstructor()
{
var tiledColor = new TiledColor();
Assert.Equal<byte>(0x00, tiledColor.A);
Assert.Equal<byte>(0x00, tiledColor.R);
Assert.Equal<byte>(0x00, tiledColor.G);
Assert.Equal<byte>(0x00, tiledColor.B);
}
[Fact]
public void PackedValueConstructor()
{
var tiledColor = new TiledColor(0x11223344);
Assert.Equal<byte>(0x11, tiledColor.A);
Assert.Equal<byte>(0x22, tiledColor.R);
Assert.Equal<byte>(0x33, tiledColor.G);
Assert.Equal<byte>(0x44, tiledColor.B);
}
[Fact]
public void NonAlphaConstructor()
{
var tiledColor = new TiledColor(0x11, 0x22, 0x33);
Assert.Equal<byte>(0xFF, tiledColor.A);
Assert.Equal<byte>(0x11, tiledColor.R);
Assert.Equal<byte>(0x22, tiledColor.G);
Assert.Equal<byte>(0x33, tiledColor.B);
}
[Fact]
public void AlphaConstructor()
{
var tiledColor = new TiledColor(0x11, 0x22, 0x33, 0x44);
Assert.Equal<byte>(0x11, tiledColor.A);
Assert.Equal<byte>(0x22, tiledColor.R);
Assert.Equal<byte>(0x33, tiledColor.G);
Assert.Equal<byte>(0x44, tiledColor.B);
}
[Fact]
public void NonAlphaParsing()
{
var tiledColor = TiledColor.Parse("#112233", CultureInfo.InvariantCulture);
Assert.Equal<byte>(0x11, tiledColor.R);
Assert.Equal<byte>(0x22, tiledColor.G);
Assert.Equal<byte>(0x33, tiledColor.B);
}
[Fact]
public void AlphaParsing()
{
var tiledColor = TiledColor.Parse("#11223344", CultureInfo.InvariantCulture);
Assert.Equal<byte>(0x11, tiledColor.A);
Assert.Equal<byte>(0x22, tiledColor.R);
Assert.Equal<byte>(0x33, tiledColor.G);
Assert.Equal<byte>(0x44, tiledColor.B);
}
[Fact]
public void Static_TiledColors_ToString()
{
Assert.Equal("#00000000", TiledColor.Transparent.ToString());
Assert.Equal("#fff0f8ff", TiledColor.AliceBlue.ToString());
Assert.Equal("#fffaebd7", TiledColor.AntiqueWhite.ToString());
Assert.Equal("#ff00ffff", TiledColor.Aqua.ToString());
Assert.Equal("#ff7fffd4", TiledColor.Aquamarine.ToString());
Assert.Equal("#fff0ffff", TiledColor.Azure.ToString());
Assert.Equal("#fff5f5dc", TiledColor.Beige.ToString());
Assert.Equal("#ffffe4c4", TiledColor.Bisque.ToString());
Assert.Equal("#ff000000", TiledColor.Black.ToString());
Assert.Equal("#ffffebcd", TiledColor.BlanchedAlmond.ToString());
Assert.Equal("#ff0000ff", TiledColor.Blue.ToString());
Assert.Equal("#ff8a2be2", TiledColor.BlueViolet.ToString());
Assert.Equal("#ffa52a2a", TiledColor.Brown.ToString());
Assert.Equal("#ffdeb887", TiledColor.BurlyWood.ToString());
Assert.Equal("#ff5f9ea0", TiledColor.CadetBlue.ToString());
Assert.Equal("#ff7fff00", TiledColor.Chartreuse.ToString());
Assert.Equal("#ffd2691e", TiledColor.Chocolate.ToString());
Assert.Equal("#ffff7f50", TiledColor.Coral.ToString());
Assert.Equal("#ff6495ed", TiledColor.CornflowerBlue.ToString());
Assert.Equal("#fffff8dc", TiledColor.Cornsilk.ToString());
Assert.Equal("#ffdc143c", TiledColor.Crimson.ToString());
Assert.Equal("#ff00ffff", TiledColor.Cyan.ToString());
Assert.Equal("#ff00008b", TiledColor.DarkBlue.ToString());
Assert.Equal("#ff008b8b", TiledColor.DarkCyan.ToString());
Assert.Equal("#ffb8860b", TiledColor.DarkGoldenRod.ToString());
Assert.Equal("#ffa9a9a9", TiledColor.DarkGray.ToString());
Assert.Equal("#ffa9a9a9", TiledColor.DarkGrey.ToString());
Assert.Equal("#ff006400", TiledColor.DarkGreen.ToString());
Assert.Equal("#ffbdb76b", TiledColor.DarkKhaki.ToString());
Assert.Equal("#ff8b008b", TiledColor.DarkMagenta.ToString());
Assert.Equal("#ff556b2f", TiledColor.DarkOliveGreen.ToString());
Assert.Equal("#ffff8c00", TiledColor.DarkOrange.ToString());
Assert.Equal("#ff9932cc", TiledColor.DarkOrchid.ToString());
Assert.Equal("#ff8b0000", TiledColor.DarkRed.ToString());
Assert.Equal("#ffe9967a", TiledColor.DarkSalmon.ToString());
Assert.Equal("#ff8fbc8f", TiledColor.DarkSeaGreen.ToString());
Assert.Equal("#ff483d8b", TiledColor.DarkSlateBlue.ToString());
Assert.Equal("#ff2f4f4f", TiledColor.DarkSlateGray.ToString());
Assert.Equal("#ff2f4f4f", TiledColor.DarkSlateGrey.ToString());
Assert.Equal("#ff00ced1", TiledColor.DarkTurquoise.ToString());
Assert.Equal("#ff9400d3", TiledColor.DarkViolet.ToString());
Assert.Equal("#ffff1493", TiledColor.DeepPink.ToString());
Assert.Equal("#ff00bfff", TiledColor.DeepSkyBlue.ToString());
Assert.Equal("#ff696969", TiledColor.DimGray.ToString());
Assert.Equal("#ff696969", TiledColor.DimGrey.ToString());
Assert.Equal("#ff1e90ff", TiledColor.DodgerBlue.ToString());
Assert.Equal("#ffb22222", TiledColor.FireBrick.ToString());
Assert.Equal("#fffffaf0", TiledColor.FloralWhite.ToString());
Assert.Equal("#ff228b22", TiledColor.ForestGreen.ToString());
Assert.Equal("#ffff00ff", TiledColor.Fuchsia.ToString());
Assert.Equal("#ffdcdcdc", TiledColor.Gainsboro.ToString());
Assert.Equal("#fff8f8ff", TiledColor.GhostWhite.ToString());
Assert.Equal("#ffffd700", TiledColor.Gold.ToString());
Assert.Equal("#ffdaa520", TiledColor.GoldenRod.ToString());
Assert.Equal("#ff808080", TiledColor.Gray.ToString());
Assert.Equal("#ff808080", TiledColor.Grey.ToString());
Assert.Equal("#ff008000", TiledColor.Green.ToString());
Assert.Equal("#ffadff2f", TiledColor.GreenYellow.ToString());
Assert.Equal("#fff0fff0", TiledColor.HoneyDew.ToString());
Assert.Equal("#ffff69b4", TiledColor.HotPink.ToString());
Assert.Equal("#ffcd5c5c", TiledColor.IndianRed.ToString());
Assert.Equal("#ff4b0082", TiledColor.Indigo.ToString());
Assert.Equal("#fffffff0", TiledColor.Ivory.ToString());
Assert.Equal("#fff0e68c", TiledColor.Khaki.ToString());
Assert.Equal("#ffe6e6fa", TiledColor.Lavender.ToString());
Assert.Equal("#fffff0f5", TiledColor.LavenderBlush.ToString());
Assert.Equal("#ff7cfc00", TiledColor.LawnGreen.ToString());
Assert.Equal("#fffffacd", TiledColor.LemonChiffon.ToString());
Assert.Equal("#ffadd8e6", TiledColor.LightBlue.ToString());
Assert.Equal("#fff08080", TiledColor.LightCoral.ToString());
Assert.Equal("#ffe0ffff", TiledColor.LightCyan.ToString());
Assert.Equal("#fffafad2", TiledColor.LightGoldenRodYellow.ToString());
Assert.Equal("#ffd3d3d3", TiledColor.LightGray.ToString());
Assert.Equal("#ffd3d3d3", TiledColor.LightGrey.ToString());
Assert.Equal("#ff90ee90", TiledColor.LightGreen.ToString());
Assert.Equal("#ffffb6c1", TiledColor.LightPink.ToString());
Assert.Equal("#ffffa07a", TiledColor.LightSalmon.ToString());
Assert.Equal("#ff20b2aa", TiledColor.LightSeaGreen.ToString());
Assert.Equal("#ff87cefa", TiledColor.LightSkyBlue.ToString());
Assert.Equal("#ff778899", TiledColor.LightSlateGray.ToString());
Assert.Equal("#ff778899", TiledColor.LightSlateGrey.ToString());
Assert.Equal("#ffb0c4de", TiledColor.LightSteelBlue.ToString());
Assert.Equal("#ffffffe0", TiledColor.LightYellow.ToString());
Assert.Equal("#ff00ff00", TiledColor.Lime.ToString());
Assert.Equal("#ff32cd32", TiledColor.LimeGreen.ToString());
Assert.Equal("#fffaf0e6", TiledColor.Linen.ToString());
Assert.Equal("#ffff00ff", TiledColor.Magenta.ToString());
Assert.Equal("#ff800000", TiledColor.Maroon.ToString());
Assert.Equal("#ff66cdaa", TiledColor.MediumAquaMarine.ToString());
Assert.Equal("#ff0000cd", TiledColor.MediumBlue.ToString());
Assert.Equal("#ffba55d3", TiledColor.MediumOrchid.ToString());
Assert.Equal("#ff9370db", TiledColor.MediumPurple.ToString());
Assert.Equal("#ff3cb371", TiledColor.MediumSeaGreen.ToString());
Assert.Equal("#ff7b68ee", TiledColor.MediumSlateBlue.ToString());
Assert.Equal("#ff00fa9a", TiledColor.MediumSpringGreen.ToString());
Assert.Equal("#ff48d1cc", TiledColor.MediumTurquoise.ToString());
Assert.Equal("#ffc71585", TiledColor.MediumVioletRed.ToString());
Assert.Equal("#ff191970", TiledColor.MidnightBlue.ToString());
Assert.Equal("#fff5fffa", TiledColor.MintCream.ToString());
Assert.Equal("#ffffe4e1", TiledColor.MistyRose.ToString());
Assert.Equal("#ffffe4b5", TiledColor.Moccasin.ToString());
Assert.Equal("#ffffdead", TiledColor.NavajoWhite.ToString());
Assert.Equal("#ff000080", TiledColor.Navy.ToString());
Assert.Equal("#fffdf5e6", TiledColor.OldLace.ToString());
Assert.Equal("#ff808000", TiledColor.Olive.ToString());
Assert.Equal("#ff6b8e23", TiledColor.OliveDrab.ToString());
Assert.Equal("#ffffa500", TiledColor.Orange.ToString());
Assert.Equal("#ffff4500", TiledColor.OrangeRed.ToString());
Assert.Equal("#ffda70d6", TiledColor.Orchid.ToString());
Assert.Equal("#ffeee8aa", TiledColor.PaleGoldenRod.ToString());
Assert.Equal("#ff98fb98", TiledColor.PaleGreen.ToString());
Assert.Equal("#ffafeeee", TiledColor.PaleTurquoise.ToString());
Assert.Equal("#ffdb7093", TiledColor.PaleVioletRed.ToString());
Assert.Equal("#ffffefd5", TiledColor.PapayaWhip.ToString());
Assert.Equal("#ffffdab9", TiledColor.PeachPuff.ToString());
Assert.Equal("#ffcd853f", TiledColor.Peru.ToString());
Assert.Equal("#ffffc0cb", TiledColor.Pink.ToString());
Assert.Equal("#ffdda0dd", TiledColor.Plum.ToString());
Assert.Equal("#ffb0e0e6", TiledColor.PowderBlue.ToString());
Assert.Equal("#ff800080", TiledColor.Purple.ToString());
Assert.Equal("#ff663399", TiledColor.RebeccaPurple.ToString());
Assert.Equal("#ffff0000", TiledColor.Red.ToString());
Assert.Equal("#ffbc8f8f", TiledColor.RosyBrown.ToString());
Assert.Equal("#ff4169e1", TiledColor.RoyalBlue.ToString());
Assert.Equal("#ff8b4513", TiledColor.SaddleBrown.ToString());
Assert.Equal("#fffa8072", TiledColor.Salmon.ToString());
Assert.Equal("#fff4a460", TiledColor.SandyBrown.ToString());
Assert.Equal("#ff2e8b57", TiledColor.SeaGreen.ToString());
Assert.Equal("#fffff5ee", TiledColor.SeaShell.ToString());
Assert.Equal("#ffa0522d", TiledColor.Sienna.ToString());
Assert.Equal("#ffc0c0c0", TiledColor.Silver.ToString());
Assert.Equal("#ff87ceeb", TiledColor.SkyBlue.ToString());
Assert.Equal("#ff6a5acd", TiledColor.SlateBlue.ToString());
Assert.Equal("#ff708090", TiledColor.SlateGray.ToString());
Assert.Equal("#ff708090", TiledColor.SlateGrey.ToString());
Assert.Equal("#fffffafa", TiledColor.Snow.ToString());
Assert.Equal("#ff00ff7f", TiledColor.SpringGreen.ToString());
Assert.Equal("#ff4682b4", TiledColor.SteelBlue.ToString());
Assert.Equal("#ffd2b48c", TiledColor.Tan.ToString());
Assert.Equal("#ff008080", TiledColor.Teal.ToString());
Assert.Equal("#ffd8bfd8", TiledColor.Thistle.ToString());
Assert.Equal("#ffff6347", TiledColor.Tomato.ToString());
Assert.Equal("#ff40e0d0", TiledColor.Turquoise.ToString());
Assert.Equal("#ffee82ee", TiledColor.Violet.ToString());
Assert.Equal("#fff5deb3", TiledColor.Wheat.ToString());
Assert.Equal("#ffffffff", TiledColor.White.ToString());
Assert.Equal("#fff5f5f5", TiledColor.WhiteSmoke.ToString());
Assert.Equal("#ffffff00", TiledColor.Yellow.ToString());
Assert.Equal("#ff9acd32", TiledColor.YellowGreen.ToString());
}
}

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
namespace DotTiled; namespace DotTiled;
@ -172,7 +171,7 @@ public class Map : HasPropertiesBase
/// <summary> /// <summary>
/// The background color of the map. /// The background color of the map.
/// </summary> /// </summary>
public TiledColor BackgroundColor { get; set; } = TiledColor.Parse("#00000000", CultureInfo.InvariantCulture); public TiledColor BackgroundColor { get; set; } = TiledColor.Transparent;
/// <summary> /// <summary>
/// Stores the next available ID for new layers. This number is used to prevent reuse of the same ID after layers have been removed. /// Stores the next available ID for new layers. This number is used to prevent reuse of the same ID after layers have been removed.

View file

@ -7,27 +7,831 @@ namespace DotTiled;
/// <summary> /// <summary>
/// Represents a Tiled color. /// Represents a Tiled color.
/// </summary> /// </summary>
public class TiledColor : IParsable<TiledColor>, IEquatable<TiledColor> public struct TiledColor : IParsable<TiledColor>, IEquatable<TiledColor>
{ {
/// <summary> #region Static TiledColors
/// The red component of the color.
/// </summary>
public required byte R { get; set; }
/// <summary> /// <summary>
/// The green component of the color. /// Transparent <see cref="TiledColor"/> (A:0, R:0, G:0, B:0)
/// </summary> /// </summary>
public required byte G { get; set; } public static TiledColor Transparent => new TiledColor();
/// <summary> /// <summary>
/// The blue component of the color. /// Alice Blue <see cref="TiledColor"/> (A: 255, R:240, G:248, B: 255)
/// </summary> /// </summary>
public required byte B { get; set; } public static TiledColor AliceBlue => new TiledColor(0xFFF0F8FF);
/// <summary> /// <summary>
/// The alpha component of the color. /// Antique White <see cref="TiledColor"/> (A: 255, R:250, G:235, B: 215)
/// </summary> /// </summary>
public byte A { get; set; } = 255; public static TiledColor AntiqueWhite => new TiledColor(0xFFFAEBD7);
/// <summary>
/// Aqua <see cref="TiledColor"/> (A: 255, R:0, G:255, B: 255)
/// </summary>
public static TiledColor Aqua => new TiledColor(0xFF00FFFF);
/// <summary>
/// Aquamarine <see cref="TiledColor"/> (A: 255, R:127, G:255, B: 212)
/// </summary>
public static TiledColor Aquamarine => new TiledColor(0xFF7FFFD4);
/// <summary>
/// Azure <see cref="TiledColor"/> (A: 255, R:240, G:255, B: 255)
/// </summary>
public static TiledColor Azure => new TiledColor(0xFFF0FFFF);
/// <summary>
/// Beige <see cref="TiledColor"/> (A: 255, R:245, G:245, B: 220)
/// </summary>
public static TiledColor Beige => new TiledColor(0xFFF5F5DC);
/// <summary>
/// Bisque <see cref="TiledColor"/> (A: 255, R:255, G:228, B: 196)
/// </summary>
public static TiledColor Bisque => new TiledColor(0xFFFFE4C4);
/// <summary>
/// Black <see cref="TiledColor"/> (A: 255, R:0, G:0, B: 0)
/// </summary>
public static TiledColor Black => new TiledColor(0xFF000000);
/// <summary>
/// Blanched Almond <see cref="TiledColor"/> (A: 255, R:255, G:235, B: 205)
/// </summary>
public static TiledColor BlanchedAlmond => new TiledColor(0xFFFFEBCD);
/// <summary>
/// Blue <see cref="TiledColor"/> (A: 255, R:0, G:0, B: 255)
/// </summary>
public static TiledColor Blue => new TiledColor(0xFF0000FF);
/// <summary>
/// Blue Violet <see cref="TiledColor"/> (A: 255, R:138, G:43, B: 226)
/// </summary>
public static TiledColor BlueViolet => new TiledColor(0xFF8A2BE2);
/// <summary>
/// Brown <see cref="TiledColor"/> (A: 255, R:165, G:42, B: 42)
/// </summary>
public static TiledColor Brown => new TiledColor(0xFFA52A2A);
/// <summary>
/// Burly Wood <see cref="TiledColor"/> (A: 255, R:222, G:184, B: 135)
/// </summary>
public static TiledColor BurlyWood => new TiledColor(0xFFDEB887);
/// <summary>
/// Cadet Blue <see cref="TiledColor"/> (A: 255, R:95, G:158, B: 160)
/// </summary>
public static TiledColor CadetBlue => new TiledColor(0xFF5F9EA0);
/// <summary>
/// Chartreuse <see cref="TiledColor"/> (A: 255, R:127, G:255, B: 0)
/// </summary>
public static TiledColor Chartreuse => new TiledColor(0xFF7FFF00);
/// <summary>
/// Chocolate <see cref="TiledColor"/> (A: 255, R:210, G:105, B: 30)
/// </summary>
public static TiledColor Chocolate => new TiledColor(0xFFD2691E);
/// <summary>
/// Coral <see cref="TiledColor"/> (A: 255, R:255, G:127, B: 80)
/// </summary>
public static TiledColor Coral => new TiledColor(0xFFFF7F50);
/// <summary>
/// Cornflower Blue <see cref="TiledColor"/> (A: 255, R:100, G:149, B: 237)
/// </summary>
public static TiledColor CornflowerBlue => new TiledColor(0xFF6495ED);
/// <summary>
/// Cornsilk <see cref="TiledColor"/> (A: 255, R:255, G:248, B: 220)
/// </summary>
public static TiledColor Cornsilk => new TiledColor(0xFFFFF8DC);
/// <summary>
/// Crimson <see cref="TiledColor"/> (A: 255, R:220, G:20, B: 60)
/// </summary>
public static TiledColor Crimson => new TiledColor(0xFFDC143C);
/// <summary>
/// Cyan <see cref="TiledColor"/> (A: 255, R:0, G:255, B: 255)
/// </summary>
public static TiledColor Cyan => new TiledColor(0xFF00FFFF);
/// <summary>
/// Dark Blue <see cref="TiledColor"/> (A: 255, R:0, G:0, B: 139)
/// </summary>
public static TiledColor DarkBlue => new TiledColor(0xFF00008B);
/// <summary>
/// Dark Cyan <see cref="TiledColor"/> (A: 255, R:0, G:139, B: 139)
/// </summary>
public static TiledColor DarkCyan => new TiledColor(0xFF008B8B);
/// <summary>
/// Dark Golden Rod <see cref="TiledColor"/> (A: 255, R:184, G:134, B: 11)
/// </summary>
public static TiledColor DarkGoldenRod => new TiledColor(0xFFB8860B);
/// <summary>
/// Dark Gray <see cref="TiledColor"/> (A: 255, R:169, G:169, B: 169)
/// </summary>
public static TiledColor DarkGray => new TiledColor(0xFFA9A9A9);
/// <summary>
/// Dark Grey <see cref="TiledColor"/> (A: 255, R:169, G:169, B: 169)
/// </summary>
public static TiledColor DarkGrey => new TiledColor(0xFFA9A9A9);
/// <summary>
/// Dark Green <see cref="TiledColor"/> (A: 255, R:0, G:100, B: 0)
/// </summary>
public static TiledColor DarkGreen => new TiledColor(0xFF006400);
/// <summary>
/// Dark Khaki <see cref="TiledColor"/> (A: 255, R:189, G:183, B: 107)
/// </summary>
public static TiledColor DarkKhaki => new TiledColor(0xFFBDB76B);
/// <summary>
/// Dark Magenta <see cref="TiledColor"/> (A: 255, R:139, G:0, B: 139)
/// </summary>
public static TiledColor DarkMagenta => new TiledColor(0xFF8B008B);
/// <summary>
/// Dark Olive Green <see cref="TiledColor"/> (A: 255, R:85, G:107, B: 47)
/// </summary>
public static TiledColor DarkOliveGreen => new TiledColor(0xFF556B2F);
/// <summary>
/// Dark Orange <see cref="TiledColor"/> (A: 255, R:255, G:140, B: 0)
/// </summary>
public static TiledColor DarkOrange => new TiledColor(0xFFFF8C00);
/// <summary>
/// Dark Orchid <see cref="TiledColor"/> (A: 255, R:153, G:50, B: 204)
/// </summary>
public static TiledColor DarkOrchid => new TiledColor(0xFF9932CC);
/// <summary>
/// Dark Red <see cref="TiledColor"/> (A: 255, R:139, G:0, B: 0)
/// </summary>
public static TiledColor DarkRed => new TiledColor(0xFF8B0000);
/// <summary>
/// Dark Salmon <see cref="TiledColor"/> (A: 255, R:233, G:150, B: 122)
/// </summary>
public static TiledColor DarkSalmon => new TiledColor(0xFFE9967A);
/// <summary>
/// Dark Sea Green <see cref="TiledColor"/> (A: 255, R:143, G:188, B: 143)
/// </summary>
public static TiledColor DarkSeaGreen => new TiledColor(0xFF8FBC8F);
/// <summary>
/// Dark Slate Blue <see cref="TiledColor"/> (A: 255, R:72, G:61, B: 139)
/// </summary>
public static TiledColor DarkSlateBlue => new TiledColor(0xFF483D8B);
/// <summary>
/// Dark Slate Gray <see cref="TiledColor"/> (A: 255, R:47, G:79, B: 79)
/// </summary>
public static TiledColor DarkSlateGray => new TiledColor(0xFF2F4F4F);
/// <summary>
/// Dark Slate Grey <see cref="TiledColor"/> (A: 255, R:47, G:79, B: 79)
/// </summary>
public static TiledColor DarkSlateGrey => new TiledColor(0xFF2F4F4F);
/// <summary>
/// Dark Turquoise <see cref="TiledColor"/> (A: 255, R:0, G:206, B: 209)
/// </summary>
public static TiledColor DarkTurquoise => new TiledColor(0xFF00CED1);
/// <summary>
/// Dark Violet <see cref="TiledColor"/> (A: 255, R:148, G:0, B: 211)
/// </summary>
public static TiledColor DarkViolet => new TiledColor(0xFF9400D3);
/// <summary>
/// Deep Pink <see cref="TiledColor"/> (A: 255, R:255, G:20, B: 147)
/// </summary>
public static TiledColor DeepPink => new TiledColor(0xFFFF1493);
/// <summary>
/// Deep Sky Blue <see cref="TiledColor"/> (A: 255, R:0, G:191, B: 255)
/// </summary>
public static TiledColor DeepSkyBlue => new TiledColor(0xFF00BFFF);
/// <summary>
/// Dim Gray <see cref="TiledColor"/> (A: 255, R:105, G:105, B: 105)
/// </summary>
public static TiledColor DimGray => new TiledColor(0xFF696969);
/// <summary>
/// Dim Grey <see cref="TiledColor"/> (A: 255, R:105, G:105, B: 105)
/// </summary>
public static TiledColor DimGrey => new TiledColor(0xFF696969);
/// <summary>
/// Dodger Blue <see cref="TiledColor"/> (A: 255, R:30, G:144, B: 255)
/// </summary>
public static TiledColor DodgerBlue => new TiledColor(0xFF1E90FF);
/// <summary>
/// Fire Brick <see cref="TiledColor"/> (A: 255, R:178, G:34, B: 34)
/// </summary>
public static TiledColor FireBrick => new TiledColor(0xFFB22222);
/// <summary>
/// Floral White <see cref="TiledColor"/> (A: 255, R:255, G:250, B: 240)
/// </summary>
public static TiledColor FloralWhite => new TiledColor(0xFFFFFAF0);
/// <summary>
/// Forest Green <see cref="TiledColor"/> (A: 255, R:34, G:139, B: 34)
/// </summary>
public static TiledColor ForestGreen => new TiledColor(0xFF228B22);
/// <summary>
/// Fuchsia <see cref="TiledColor"/> (A: 255, R:255, G:0, B: 255)
/// </summary>
public static TiledColor Fuchsia => new TiledColor(0xFFFF00FF);
/// <summary>
/// Gainsboro <see cref="TiledColor"/> (A: 255, R:220, G:220, B: 220)
/// </summary>
public static TiledColor Gainsboro => new TiledColor(0xFFDCDCDC);
/// <summary>
/// Ghost White <see cref="TiledColor"/> (A: 255, R:248, G:248, B: 255)
/// </summary>
public static TiledColor GhostWhite => new TiledColor(0xFFF8F8FF);
/// <summary>
/// Gold <see cref="TiledColor"/> (A: 255, R:255, G:215, B: 0)
/// </summary>
public static TiledColor Gold => new TiledColor(0xFFFFD700);
/// <summary>
/// Golden Rod <see cref="TiledColor"/> (A: 255, R:218, G:165, B: 32)
/// </summary>
public static TiledColor GoldenRod => new TiledColor(0xFFDAA520);
/// <summary>
/// Gray <see cref="TiledColor"/> (A: 255, R:128, G:128, B: 128)
/// </summary>
public static TiledColor Gray => new TiledColor(0xFF808080);
/// <summary>
/// Grey <see cref="TiledColor"/> (A: 255, R:128, G:128, B: 128)
/// </summary>
public static TiledColor Grey => new TiledColor(0xFF808080);
/// <summary>
/// Green <see cref="TiledColor"/> (A: 255, R:0, G:128, B: 0)
/// </summary>
public static TiledColor Green => new TiledColor(0xFF008000);
/// <summary>
/// Green Yellow <see cref="TiledColor"/> (A: 255, R:173, G:255, B: 47)
/// </summary>
public static TiledColor GreenYellow => new TiledColor(0xFFADFF2F);
/// <summary>
/// Honey Dew <see cref="TiledColor"/> (A: 255, R:240, G:255, B: 240)
/// </summary>
public static TiledColor HoneyDew => new TiledColor(0xFFF0FFF0);
/// <summary>
/// Hot Pink <see cref="TiledColor"/> (A: 255, R:255, G:105, B: 180)
/// </summary>
public static TiledColor HotPink => new TiledColor(0xFFFF69B4);
/// <summary>
/// Indian Red <see cref="TiledColor"/> (A: 255, R:205, G:92, B: 92)
/// </summary>
public static TiledColor IndianRed => new TiledColor(0xFFCD5C5C);
/// <summary>
/// Indigo <see cref="TiledColor"/> (A: 255, R:75, G:0, B: 130)
/// </summary>
public static TiledColor Indigo => new TiledColor(0xFF4B0082);
/// <summary>
/// Ivory <see cref="TiledColor"/> (A: 255, R:255, G:255, B: 240)
/// </summary>
public static TiledColor Ivory => new TiledColor(0xFFFFFFF0);
/// <summary>
/// Khaki <see cref="TiledColor"/> (A: 255, R:240, G:230, B: 140)
/// </summary>
public static TiledColor Khaki => new TiledColor(0xFFF0E68C);
/// <summary>
/// Lavender <see cref="TiledColor"/> (A: 255, R:230, G:230, B: 250)
/// </summary>
public static TiledColor Lavender => new TiledColor(0xFFE6E6FA);
/// <summary>
/// Lavender Blush <see cref="TiledColor"/> (A: 255, R:255, G:240, B: 245)
/// </summary>
public static TiledColor LavenderBlush => new TiledColor(0xFFFFF0F5);
/// <summary>
/// Lawn Green <see cref="TiledColor"/> (A: 255, R:124, G:252, B: 0)
/// </summary>
public static TiledColor LawnGreen => new TiledColor(0xFF7CFC00);
/// <summary>
/// Lemon Chiffon <see cref="TiledColor"/> (A: 255, R:255, G:250, B: 205)
/// </summary>
public static TiledColor LemonChiffon => new TiledColor(0xFFFFFACD);
/// <summary>
/// Light Blue <see cref="TiledColor"/> (A: 255, R:173, G:216, B: 230)
/// </summary>
public static TiledColor LightBlue => new TiledColor(0xFFADD8E6);
/// <summary>
/// Light Coral <see cref="TiledColor"/> (A: 255, R:240, G:128, B: 128)
/// </summary>
public static TiledColor LightCoral => new TiledColor(0xFFF08080);
/// <summary>
/// Light Cyan <see cref="TiledColor"/> (A: 255, R:224, G:255, B: 255)
/// </summary>
public static TiledColor LightCyan => new TiledColor(0xFFE0FFFF);
/// <summary>
/// Light Golden Rod Yellow <see cref="TiledColor"/> (A: 255, R:250, G:250, B: 210)
/// </summary>
public static TiledColor LightGoldenRodYellow => new TiledColor(0xFFFAFAD2);
/// <summary>
/// Light Gray <see cref="TiledColor"/> (A: 255, R:211, G:211, B: 211)
/// </summary>
public static TiledColor LightGray => new TiledColor(0xFFD3D3D3);
/// <summary>
/// Light Grey <see cref="TiledColor"/> (A: 255, R:211, G:211, B: 211)
/// </summary>
public static TiledColor LightGrey => new TiledColor(0xFFD3D3D3);
/// <summary>
/// Light Green <see cref="TiledColor"/> (A: 255, R:144, G:238, B: 144)
/// </summary>
public static TiledColor LightGreen => new TiledColor(0xFF90EE90);
/// <summary>
/// Light Pink <see cref="TiledColor"/> (A: 255, R:255, G:182, B: 193)
/// </summary>
public static TiledColor LightPink => new TiledColor(0xFFFFB6C1);
/// <summary>
/// Light Salmon <see cref="TiledColor"/> (A: 255, R:255, G:160, B: 122)
/// </summary>
public static TiledColor LightSalmon => new TiledColor(0xFFFFA07A);
/// <summary>
/// Light Sea Green <see cref="TiledColor"/> (A: 255, R:32, G:178, B: 170)
/// </summary>
public static TiledColor LightSeaGreen => new TiledColor(0xFF20B2AA);
/// <summary>
/// Light Sky Blue <see cref="TiledColor"/> (A: 255, R:135, G:206, B: 250)
/// </summary>
public static TiledColor LightSkyBlue => new TiledColor(0xFF87CEFA);
/// <summary>
/// Light Slate Gray <see cref="TiledColor"/> (A: 255, R:119, G:136, B: 153)
/// </summary>
public static TiledColor LightSlateGray => new TiledColor(0xFF778899);
/// <summary>
/// Light Slate Grey <see cref="TiledColor"/> (A: 255, R:119, G:136, B: 153)
/// </summary>
public static TiledColor LightSlateGrey => new TiledColor(0xFF778899);
/// <summary>
/// Light Steel Blue <see cref="TiledColor"/> (A: 255, R:176, G:196, B: 222)
/// </summary>
public static TiledColor LightSteelBlue => new TiledColor(0xFFB0C4DE);
/// <summary>
/// Light Yellow <see cref="TiledColor"/> (A: 255, R:255, G:255, B: 224)
/// </summary>
public static TiledColor LightYellow => new TiledColor(0xFFFFFFE0);
/// <summary>
/// Lime <see cref="TiledColor"/> (A: 255, R:0, G:255, B: 0)
/// </summary>
public static TiledColor Lime => new TiledColor(0xFF00FF00);
/// <summary>
/// Lime Green <see cref="TiledColor"/> (A: 255, R:50, G:205, B: 50)
/// </summary>
public static TiledColor LimeGreen => new TiledColor(0xFF32CD32);
/// <summary>
/// Linen <see cref="TiledColor"/> (A: 255, R:250, G:240, B: 230)
/// </summary>
public static TiledColor Linen => new TiledColor(0xFFFAF0E6);
/// <summary>
/// Magenta <see cref="TiledColor"/> (A: 255, R:255, G:0, B: 255)
/// </summary>
public static TiledColor Magenta => new TiledColor(0xFFFF00FF);
/// <summary>
/// Maroon <see cref="TiledColor"/> (A: 255, R:128, G:0, B: 0)
/// </summary>
public static TiledColor Maroon => new TiledColor(0xFF800000);
/// <summary>
/// Medium Aqua Marine <see cref="TiledColor"/> (A: 255, R:102, G:205, B: 170)
/// </summary>
public static TiledColor MediumAquaMarine => new TiledColor(0xFF66CDAA);
/// <summary>
/// Medium Blue <see cref="TiledColor"/> (A: 255, R:0, G:0, B: 205)
/// </summary>
public static TiledColor MediumBlue => new TiledColor(0xFF0000CD);
/// <summary>
/// Medium Orchid <see cref="TiledColor"/> (A: 255, R:186, G:85, B: 211)
/// </summary>
public static TiledColor MediumOrchid => new TiledColor(0xFFBA55D3);
/// <summary>
/// Medium Purple <see cref="TiledColor"/> (A: 255, R:147, G:112, B: 219)
/// </summary>
public static TiledColor MediumPurple => new TiledColor(0xFF9370DB);
/// <summary>
/// Medium Sea Green <see cref="TiledColor"/> (A: 255, R:60, G:179, B: 113)
/// </summary>
public static TiledColor MediumSeaGreen => new TiledColor(0xFF3CB371);
/// <summary>
/// Medium Slate Blue <see cref="TiledColor"/> (A: 255, R:123, G:104, B: 238)
/// </summary>
public static TiledColor MediumSlateBlue => new TiledColor(0xFF7B68EE);
/// <summary>
/// Medium Spring Green <see cref="TiledColor"/> (A: 255, R:0, G:250, B: 154)
/// </summary>
public static TiledColor MediumSpringGreen => new TiledColor(0xFF00FA9A);
/// <summary>
/// Medium Turquoise <see cref="TiledColor"/> (A: 255, R:72, G:209, B: 204)
/// </summary>
public static TiledColor MediumTurquoise => new TiledColor(0xFF48D1CC);
/// <summary>
/// Medium Violet Red <see cref="TiledColor"/> (A: 255, R:199, G:21, B: 133)
/// </summary>
public static TiledColor MediumVioletRed => new TiledColor(0xFFC71585);
/// <summary>
/// Midnight Blue <see cref="TiledColor"/> (A: 255, R:25, G:25, B: 112)
/// </summary>
public static TiledColor MidnightBlue => new TiledColor(0xFF191970);
/// <summary>
/// Mint Cream <see cref="TiledColor"/> (A: 255, R:245, G:255, B: 250)
/// </summary>
public static TiledColor MintCream => new TiledColor(0xFFF5FFFA);
/// <summary>
/// Misty Rose <see cref="TiledColor"/> (A: 255, R:255, G:228, B: 225)
/// </summary>
public static TiledColor MistyRose => new TiledColor(0xFFFFE4E1);
/// <summary>
/// Moccasin <see cref="TiledColor"/> (A: 255, R:255, G:228, B: 181)
/// </summary>
public static TiledColor Moccasin => new TiledColor(0xFFFFE4B5);
/// <summary>
/// Navajo White <see cref="TiledColor"/> (A: 255, R:255, G:222, B: 173)
/// </summary>
public static TiledColor NavajoWhite => new TiledColor(0xFFFFDEAD);
/// <summary>
/// Navy <see cref="TiledColor"/> (A: 255, R:0, G:0, B: 128)
/// </summary>
public static TiledColor Navy => new TiledColor(0xFF000080);
/// <summary>
/// Old Lace <see cref="TiledColor"/> (A: 255, R:253, G:245, B: 230)
/// </summary>
public static TiledColor OldLace => new TiledColor(0xFFFDF5E6);
/// <summary>
/// Olive <see cref="TiledColor"/> (A: 255, R:128, G:128, B: 0)
/// </summary>
public static TiledColor Olive => new TiledColor(0xFF808000);
/// <summary>
/// Olive Drab <see cref="TiledColor"/> (A: 255, R:107, G:142, B: 35)
/// </summary>
public static TiledColor OliveDrab => new TiledColor(0xFF6B8E23);
/// <summary>
/// Orange <see cref="TiledColor"/> (A: 255, R:255, G:165, B: 0)
/// </summary>
public static TiledColor Orange => new TiledColor(0xFFFFA500);
/// <summary>
/// Orange Red <see cref="TiledColor"/> (A: 255, R:255, G:69, B: 0)
/// </summary>
public static TiledColor OrangeRed => new TiledColor(0xFFFF4500);
/// <summary>
/// Orchid <see cref="TiledColor"/> (A: 255, R:218, G:112, B: 214)
/// </summary>
public static TiledColor Orchid => new TiledColor(0xFFDA70D6);
/// <summary>
/// Pale Golden Rod <see cref="TiledColor"/> (A: 255, R:238, G:232, B: 170)
/// </summary>
public static TiledColor PaleGoldenRod => new TiledColor(0xFFEEE8AA);
/// <summary>
/// Pale Green <see cref="TiledColor"/> (A: 255, R:152, G:251, B: 152)
/// </summary>
public static TiledColor PaleGreen => new TiledColor(0xFF98FB98);
/// <summary>
/// Pale Turquoise <see cref="TiledColor"/> (A: 255, R:175, G:238, B: 238)
/// </summary>
public static TiledColor PaleTurquoise => new TiledColor(0xFFAFEEEE);
/// <summary>
/// Pale Violet Red <see cref="TiledColor"/> (A: 255, R:219, G:112, B: 147)
/// </summary>
public static TiledColor PaleVioletRed => new TiledColor(0xFFDB7093);
/// <summary>
/// Papaya Whip <see cref="TiledColor"/> (A: 255, R:255, G:239, B: 213)
/// </summary>
public static TiledColor PapayaWhip => new TiledColor(0xFFFFEFD5);
/// <summary>
/// Peach Puff <see cref="TiledColor"/> (A: 255, R:255, G:218, B: 185)
/// </summary>
public static TiledColor PeachPuff => new TiledColor(0xFFFFDAB9);
/// <summary>
/// Peru <see cref="TiledColor"/> (A: 255, R:205, G:133, B: 63)
/// </summary>
public static TiledColor Peru => new TiledColor(0xFFCD853F);
/// <summary>
/// Pink <see cref="TiledColor"/> (A: 255, R:255, G:192, B: 203)
/// </summary>
public static TiledColor Pink => new TiledColor(0xFFFFC0CB);
/// <summary>
/// Plum <see cref="TiledColor"/> (A: 255, R:221, G:160, B: 221)
/// </summary>
public static TiledColor Plum => new TiledColor(0xFFDDA0DD);
/// <summary>
/// Powder Blue <see cref="TiledColor"/> (A: 255, R:176, G:224, B: 230)
/// </summary>
public static TiledColor PowderBlue => new TiledColor(0xFFB0E0E6);
/// <summary>
/// Purple <see cref="TiledColor"/> (A: 255, R:128, G:0, B: 128)
/// </summary>
public static TiledColor Purple => new TiledColor(0xFF800080);
/// <summary>
/// Rebecca Purple <see cref="TiledColor"/> (A: 255, R:102, G:51, B: 153)
/// </summary>
public static TiledColor RebeccaPurple => new TiledColor(0xFF663399);
/// <summary>
/// Red <see cref="TiledColor"/> (A: 255, R:255, G:0, B: 0)
/// </summary>
public static TiledColor Red => new TiledColor(0xFFFF0000);
/// <summary>
/// Rosy Brown <see cref="TiledColor"/> (A: 255, R:188, G:143, B: 143)
/// </summary>
public static TiledColor RosyBrown => new TiledColor(0xFFBC8F8F);
/// <summary>
/// Royal Blue <see cref="TiledColor"/> (A: 255, R:65, G:105, B: 225)
/// </summary>
public static TiledColor RoyalBlue => new TiledColor(0xFF4169E1);
/// <summary>
/// Saddle Brown <see cref="TiledColor"/> (A: 255, R:139, G:69, B: 19)
/// </summary>
public static TiledColor SaddleBrown => new TiledColor(0xFF8B4513);
/// <summary>
/// Salmon <see cref="TiledColor"/> (A: 255, R:250, G:128, B: 114)
/// </summary>
public static TiledColor Salmon => new TiledColor(0xFFFA8072);
/// <summary>
/// Sandy Brown <see cref="TiledColor"/> (A: 255, R:244, G:164, B: 96)
/// </summary>
public static TiledColor SandyBrown => new TiledColor(0xFFF4A460);
/// <summary>
/// Sea Green <see cref="TiledColor"/> (A: 255, R:46, G:139, B: 87)
/// </summary>
public static TiledColor SeaGreen => new TiledColor(0xFF2E8B57);
/// <summary>
/// Sea Shell <see cref="TiledColor"/> (A: 255, R:255, G:245, B: 238)
/// </summary>
public static TiledColor SeaShell => new TiledColor(0xFFFFF5EE);
/// <summary>
/// Sienna <see cref="TiledColor"/> (A: 255, R:160, G:82, B: 45)
/// </summary>
public static TiledColor Sienna => new TiledColor(0xFFA0522D);
/// <summary>
/// Silver <see cref="TiledColor"/> (A: 255, R:192, G:192, B: 192)
/// </summary>
public static TiledColor Silver => new TiledColor(0xFFC0C0C0);
/// <summary>
/// Sky Blue <see cref="TiledColor"/> (A: 255, R:135, G:206, B: 235)
/// </summary>
public static TiledColor SkyBlue => new TiledColor(0xFF87CEEB);
/// <summary>
/// Slate Blue <see cref="TiledColor"/> (A: 255, R:106, G:90, B: 205)
/// </summary>
public static TiledColor SlateBlue => new TiledColor(0xFF6A5ACD);
/// <summary>
/// Slate Gray <see cref="TiledColor"/> (A: 255, R:112, G:128, B: 144)
/// </summary>
public static TiledColor SlateGray => new TiledColor(0xFF708090);
/// <summary>
/// Slate Grey <see cref="TiledColor"/> (A: 255, R:112, G:128, B: 144)
/// </summary>
public static TiledColor SlateGrey => new TiledColor(0xFF708090);
/// <summary>
/// Snow <see cref="TiledColor"/> (A: 255, R:255, G:250, B: 250)
/// </summary>
public static TiledColor Snow => new TiledColor(0xFFFFFAFA);
/// <summary>
/// Spring Green <see cref="TiledColor"/> (A: 255, R:0, G:255, B: 127)
/// </summary>
public static TiledColor SpringGreen => new TiledColor(0xFF00FF7F);
/// <summary>
/// Steel Blue <see cref="TiledColor"/> (A: 255, R:70, G:130, B: 180)
/// </summary>
public static TiledColor SteelBlue => new TiledColor(0xFF4682B4);
/// <summary>
/// Tan <see cref="TiledColor"/> (A: 255, R:210, G:180, B: 140)
/// </summary>
public static TiledColor Tan => new TiledColor(0xFFD2B48C);
/// <summary>
/// Teal <see cref="TiledColor"/> (A: 255, R:0, G:128, B: 128)
/// </summary>
public static TiledColor Teal => new TiledColor(0xFF008080);
/// <summary>
/// Thistle <see cref="TiledColor"/> (A: 255, R:216, G:191, B: 216)
/// </summary>
public static TiledColor Thistle => new TiledColor(0xFFD8BFD8);
/// <summary>
/// Tomato <see cref="TiledColor"/> (A: 255, R:255, G:99, B: 71)
/// </summary>
public static TiledColor Tomato => new TiledColor(0xFFFF6347);
/// <summary>
/// Turquoise <see cref="TiledColor"/> (A: 255, R:64, G:224, B: 208)
/// </summary>
public static TiledColor Turquoise => new TiledColor(0xFF40E0D0);
/// <summary>
/// Violet <see cref="TiledColor"/> (A: 255, R:238, G:130, B: 238)
/// </summary>
public static TiledColor Violet => new TiledColor(0xFFEE82EE);
/// <summary>
/// Wheat <see cref="TiledColor"/> (A: 255, R:245, G:222, B: 179)
/// </summary>
public static TiledColor Wheat => new TiledColor(0xFFF5DEB3);
/// <summary>
/// White <see cref="TiledColor"/> (A: 255, R:255, G:255, B: 255)
/// </summary>
public static TiledColor White => new TiledColor(0xFFFFFFFF);
/// <summary>
/// White Smoke <see cref="TiledColor"/> (A: 255, R:245, G:245, B: 245)
/// </summary>
public static TiledColor WhiteSmoke => new TiledColor(0xFFF5F5F5);
/// <summary>
/// Yellow <see cref="TiledColor"/> (A: 255, R:255, G:255, B: 0)
/// </summary>
public static TiledColor Yellow => new TiledColor(0xFFFFFF00);
/// <summary>
/// Yellow Green <see cref="TiledColor"/> (A: 255, R:154, G:205, B: 50)
/// </summary>
public static TiledColor YellowGreen => new TiledColor(0xFF9ACD32);
#endregion Static TiledColors
// Stored as 32-bit unsigned integert in the following format.
// |-------|-------|-------|-------
// A R G B
private uint _packedValue;
/// <summary>
/// Constructs an ARGB color from a packed value.
/// The value is a 32-bit unsigned integer with B in the least significant octet.
/// </summary>
/// <param name="packedValue">The packed value.</param>
public TiledColor(uint packedValue)
{
_packedValue = packedValue;
}
/// <summary>
/// Constructs an ARGB color from scalars representing red, green, and blue values.
/// </summary>
/// <param name="red"></param>
/// <param name="green"></param>
/// <param name="blue"></param>
public TiledColor(byte red, byte green, byte blue) : this(0xFF, red, green, blue) { }
/// <summary>
/// Constructs an ARGB color from scalars representing alpha, red, green, and blue values.
/// </summary>
/// <param name="alpha"></param>
/// <param name="red"></param>
/// <param name="green"></param>
/// <param name="blue"></param>
public TiledColor(byte alpha, byte red, byte green, byte blue)
{
_packedValue =
((uint)alpha << 24) |
((uint)red << 16) |
((uint)green << 8) |
((uint)blue << 0);
}
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R
{
readonly get => (byte)(_packedValue >> 16);
set => _packedValue = (_packedValue & 0xFF00FFFF) | ((uint)value << 16);
}
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G
{
readonly get => (byte)(_packedValue >> 8);
set => _packedValue = (_packedValue & 0xFFFF00FF) | ((uint)value << 8);
}
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B
{
readonly get => (byte)(_packedValue >> 0);
set => _packedValue = (_packedValue & 0xFFFFFF00) | ((uint)value << 0);
}
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public byte A
{
readonly get => (byte)(_packedValue >> 24);
set => _packedValue = (_packedValue & 0x00FFFFFF) | ((uint)value << 24);
}
/// <summary> /// <summary>
/// Attempts to parse the specified string into a <see cref="TiledColor"/>. Expects strings in the format <c>#RRGGBB</c> or <c>#AARRGGBB</c>. /// Attempts to parse the specified string into a <see cref="TiledColor"/>. Expects strings in the format <c>#RRGGBB</c> or <c>#AARRGGBB</c>.
@ -39,8 +843,10 @@ public class TiledColor : IParsable<TiledColor>, IEquatable<TiledColor>
/// <exception cref="FormatException">Thrown in case the provided string <paramref name="s"/> is not in a valid format.</exception> /// <exception cref="FormatException">Thrown in case the provided string <paramref name="s"/> is not in a valid format.</exception>
public static TiledColor Parse(string s, IFormatProvider provider) public static TiledColor Parse(string s, IFormatProvider provider)
{ {
_ = TryParse(s, provider, out var result); if (TryParse(s, provider, out var result))
return result ?? throw new FormatException($"Invalid format for TiledColor: {s}"); return result;
throw new FormatException($"Invalid format for TiledColor: {s}");
} }
/// <summary> /// <summary>
@ -68,42 +874,56 @@ public class TiledColor : IParsable<TiledColor>, IEquatable<TiledColor>
if (s.Length == 7) if (s.Length == 7)
{ {
result = new TiledColor result = new TiledColor(
{ byte.Parse(s[1..3], NumberStyles.HexNumber, provider),
R = byte.Parse(s[1..3], NumberStyles.HexNumber, provider), byte.Parse(s[3..5], NumberStyles.HexNumber, provider),
G = byte.Parse(s[3..5], NumberStyles.HexNumber, provider), byte.Parse(s[5..7], NumberStyles.HexNumber, provider)
B = byte.Parse(s[5..7], NumberStyles.HexNumber, provider) );
};
} }
else else
{ {
result = new TiledColor result = new TiledColor(
{ byte.Parse(s[1..3], NumberStyles.HexNumber, provider),
A = byte.Parse(s[1..3], NumberStyles.HexNumber, provider), byte.Parse(s[3..5], NumberStyles.HexNumber, provider),
R = byte.Parse(s[3..5], NumberStyles.HexNumber, provider), byte.Parse(s[5..7], NumberStyles.HexNumber, provider),
G = byte.Parse(s[5..7], NumberStyles.HexNumber, provider), byte.Parse(s[7..9], NumberStyles.HexNumber, provider)
B = byte.Parse(s[7..9], NumberStyles.HexNumber, provider) );
};
} }
return true; return true;
} }
/// <inheritdoc/> /// <summary>
public bool Equals(TiledColor other) /// Compares whether two <see cref="TiledColor"/> instances are equal.
/// </summary>
/// <param name="left"><see cref="TiledColor"/> instance on the left of the equal sign.</param>
/// <param name="right"><see cref="TiledColor"/> instance on the right of the equal sign.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public static bool operator ==(TiledColor left, TiledColor right)
{ {
if (other is null) return left._packedValue == right._packedValue;
return false; }
return R == other.R && G == other.G && B == other.B && A == other.A; /// <summary>
/// Compares where two <see cref="TiledColor"/> instances are not equal,
/// </summary>
/// <param name="left"><see cref="TiledColor"/> instance on the left of the not equal sign.</param>
/// <param name="right"><see cref="TiledColor"/> instance on the right of the not equal sign.</param>
/// <returns><c>true</c> if the instances are not equal; <c>false</c> otherwise.</returns>
public static bool operator !=(TiledColor left, TiledColor right)
{
return left._packedValue != right._packedValue;
} }
/// <inheritdoc/> /// <inheritdoc/>
public override bool Equals(object obj) => obj is TiledColor other && Equals(other); public readonly bool Equals(TiledColor other) => _packedValue == other._packedValue;
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() => HashCode.Combine(R, G, B, A); public override readonly bool Equals(object obj) => obj is TiledColor other && Equals(other);
/// <inheritdoc/> /// <inheritdoc/>
public override string ToString() => $"#{A:x2}{R:x2}{G:x2}{B:x2}"; public override readonly int GetHashCode() => _packedValue.GetHashCode();
/// <inheritdoc/>
public override readonly string ToString() => $"#{A:x2}{R:x2}{G:x2}{B:x2}";
} }

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Text.Json; using System.Text.Json;
namespace DotTiled.Serialization.Tmj; namespace DotTiled.Serialization.Tmj;
@ -47,7 +46,7 @@ public abstract partial class TmjReaderBase
}); });
var parallaxOriginX = element.GetOptionalProperty<float>("parallaxoriginx").GetValueOr(0f); var parallaxOriginX = element.GetOptionalProperty<float>("parallaxoriginx").GetValueOr(0f);
var parallaxOriginY = element.GetOptionalProperty<float>("parallaxoriginy").GetValueOr(0f); var parallaxOriginY = element.GetOptionalProperty<float>("parallaxoriginy").GetValueOr(0f);
var backgroundColor = element.GetOptionalPropertyParseable<TiledColor>("backgroundcolor").GetValueOr(TiledColor.Parse("#00000000", CultureInfo.InvariantCulture)); var backgroundColor = element.GetOptionalPropertyParseable<TiledColor>("backgroundcolor").GetValueOr(TiledColor.Transparent);
var nextLayerID = element.GetRequiredProperty<uint>("nextlayerid"); var nextLayerID = element.GetRequiredProperty<uint>("nextlayerid");
var nextObjectID = element.GetRequiredProperty<uint>("nextobjectid"); var nextObjectID = element.GetRequiredProperty<uint>("nextobjectid");
var infinite = element.GetOptionalProperty<bool>("infinite").GetValueOr(false); var infinite = element.GetOptionalProperty<bool>("infinite").GetValueOr(false);

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Text.Json; using System.Text.Json;
@ -257,7 +256,7 @@ public abstract partial class TmjReaderBase
internal static TextObject ReadText(JsonElement element) internal static TextObject ReadText(JsonElement element)
{ {
var bold = element.GetOptionalProperty<bool>("bold").GetValueOr(false); var bold = element.GetOptionalProperty<bool>("bold").GetValueOr(false);
var color = element.GetOptionalPropertyParseable<TiledColor>("color").GetValueOr(TiledColor.Parse("#000000", CultureInfo.InvariantCulture)); var color = element.GetOptionalPropertyParseable<TiledColor>("color").GetValueOr(TiledColor.Black);
var fontfamily = element.GetOptionalProperty<string>("fontfamily").GetValueOr("sans-serif"); var fontfamily = element.GetOptionalProperty<string>("fontfamily").GetValueOr("sans-serif");
var halign = element.GetOptionalPropertyParseable<TextHorizontalAlignment>("halign", s => s switch var halign = element.GetOptionalPropertyParseable<TextHorizontalAlignment>("halign", s => s switch
{ {

View file

@ -36,7 +36,7 @@ public abstract partial class TmjReaderBase
PropertyType.Int => new IntProperty { Name = name, Value = e.GetRequiredProperty<int>("value") }, PropertyType.Int => new IntProperty { Name = name, Value = e.GetRequiredProperty<int>("value") },
PropertyType.Float => new FloatProperty { Name = name, Value = e.GetRequiredProperty<float>("value") }, PropertyType.Float => new FloatProperty { Name = name, Value = e.GetRequiredProperty<float>("value") },
PropertyType.Bool => new BoolProperty { Name = name, Value = e.GetRequiredProperty<bool>("value") }, PropertyType.Bool => new BoolProperty { Name = name, Value = e.GetRequiredProperty<bool>("value") },
PropertyType.Color => new ColorProperty { Name = name, Value = e.GetRequiredPropertyParseable<TiledColor>("value", s => s == "" ? default : TiledColor.Parse(s, CultureInfo.InvariantCulture)) }, PropertyType.Color => new ColorProperty { Name = name, Value = e.GetRequiredPropertyParseable<Optional<TiledColor>>("value", s => s == "" ? new Optional<TiledColor>() : TiledColor.Parse(s, CultureInfo.InvariantCulture)) },
PropertyType.File => new FileProperty { Name = name, Value = e.GetRequiredProperty<string>("value") }, PropertyType.File => new FileProperty { Name = name, Value = e.GetRequiredProperty<string>("value") },
PropertyType.Object => new ObjectProperty { Name = name, Value = e.GetRequiredProperty<uint>("value") }, PropertyType.Object => new ObjectProperty { Name = name, Value = e.GetRequiredProperty<uint>("value") },
PropertyType.Class => throw new JsonException("Class property must have a property type"), PropertyType.Class => throw new JsonException("Class property must have a property type"),

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
namespace DotTiled.Serialization.Tmx; namespace DotTiled.Serialization.Tmx;
@ -51,7 +50,7 @@ public abstract partial class TmxReaderBase
}); });
var parallaxOriginX = _reader.GetOptionalAttributeParseable<float>("parallaxoriginx").GetValueOr(0.0f); var parallaxOriginX = _reader.GetOptionalAttributeParseable<float>("parallaxoriginx").GetValueOr(0.0f);
var parallaxOriginY = _reader.GetOptionalAttributeParseable<float>("parallaxoriginy").GetValueOr(0.0f); var parallaxOriginY = _reader.GetOptionalAttributeParseable<float>("parallaxoriginy").GetValueOr(0.0f);
var backgroundColor = _reader.GetOptionalAttributeClass<TiledColor>("backgroundcolor").GetValueOr(TiledColor.Parse("#00000000", CultureInfo.InvariantCulture)); var backgroundColor = _reader.GetOptionalAttributeParseable<TiledColor>("backgroundcolor").GetValueOr(TiledColor.Transparent);
var nextLayerID = _reader.GetRequiredAttributeParseable<uint>("nextlayerid"); var nextLayerID = _reader.GetRequiredAttributeParseable<uint>("nextlayerid");
var nextObjectID = _reader.GetRequiredAttributeParseable<uint>("nextobjectid"); var nextObjectID = _reader.GetRequiredAttributeParseable<uint>("nextobjectid");
var infinite = _reader.GetOptionalAttributeParseable<uint>("infinite").GetValueOr(0) == 1; var infinite = _reader.GetOptionalAttributeParseable<uint>("infinite").GetValueOr(0) == 1;

View file

@ -20,12 +20,12 @@ public abstract partial class TmxReaderBase
var height = _reader.GetOptionalAttributeParseable<int>("height").GetValueOr(0); var height = _reader.GetOptionalAttributeParseable<int>("height").GetValueOr(0);
var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1.0f); var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1.0f);
var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(1) == 1; var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(1) == 1;
var tintColor = _reader.GetOptionalAttributeClass<TiledColor>("tintcolor"); var tintColor = _reader.GetOptionalAttributeParseable<TiledColor>("tintcolor");
var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0.0f); var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0.0f);
var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0.0f); var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0.0f);
var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1.0f); var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1.0f);
var parallaxY = _reader.GetOptionalAttributeParseable<float>("parallaxy").GetValueOr(1.0f); var parallaxY = _reader.GetOptionalAttributeParseable<float>("parallaxy").GetValueOr(1.0f);
var color = _reader.GetOptionalAttributeClass<TiledColor>("color"); var color = _reader.GetOptionalAttributeParseable<TiledColor>("color");
var drawOrder = _reader.GetOptionalAttributeEnum<DrawOrder>("draworder", s => s switch var drawOrder = _reader.GetOptionalAttributeEnum<DrawOrder>("draworder", s => s switch
{ {
"topdown" => DrawOrder.TopDown, "topdown" => DrawOrder.TopDown,
@ -245,7 +245,7 @@ public abstract partial class TmxReaderBase
var fontFamily = _reader.GetOptionalAttribute("fontfamily").GetValueOr("sans-serif"); var fontFamily = _reader.GetOptionalAttribute("fontfamily").GetValueOr("sans-serif");
var pixelSize = _reader.GetOptionalAttributeParseable<int>("pixelsize").GetValueOr(16); var pixelSize = _reader.GetOptionalAttributeParseable<int>("pixelsize").GetValueOr(16);
var wrap = _reader.GetOptionalAttributeParseable<int>("wrap").GetValueOr(0) == 1; var wrap = _reader.GetOptionalAttributeParseable<int>("wrap").GetValueOr(0) == 1;
var color = _reader.GetOptionalAttributeClass<TiledColor>("color").GetValueOr(TiledColor.Parse("#000000", CultureInfo.InvariantCulture)); var color = _reader.GetOptionalAttributeParseable<TiledColor>("color").GetValueOr(TiledColor.Black);
var bold = _reader.GetOptionalAttributeParseable<int>("bold").GetValueOr(0) == 1; var bold = _reader.GetOptionalAttributeParseable<int>("bold").GetValueOr(0) == 1;
var italic = _reader.GetOptionalAttributeParseable<int>("italic").GetValueOr(0) == 1; var italic = _reader.GetOptionalAttributeParseable<int>("italic").GetValueOr(0) == 1;
var underline = _reader.GetOptionalAttributeParseable<int>("underline").GetValueOr(0) == 1; var underline = _reader.GetOptionalAttributeParseable<int>("underline").GetValueOr(0) == 1;

View file

@ -45,7 +45,7 @@ public abstract partial class TmxReaderBase
PropertyType.Int => new IntProperty { Name = name, Value = r.GetRequiredAttributeParseable<int>("value") }, PropertyType.Int => new IntProperty { Name = name, Value = r.GetRequiredAttributeParseable<int>("value") },
PropertyType.Float => new FloatProperty { Name = name, Value = r.GetRequiredAttributeParseable<float>("value") }, PropertyType.Float => new FloatProperty { Name = name, Value = r.GetRequiredAttributeParseable<float>("value") },
PropertyType.Bool => new BoolProperty { Name = name, Value = r.GetRequiredAttributeParseable<bool>("value") }, PropertyType.Bool => new BoolProperty { Name = name, Value = r.GetRequiredAttributeParseable<bool>("value") },
PropertyType.Color => new ColorProperty { Name = name, Value = r.GetRequiredAttributeParseable<TiledColor>("value", s => s == "" ? default : TiledColor.Parse(s, CultureInfo.InvariantCulture)) }, PropertyType.Color => new ColorProperty { Name = name, Value = r.GetRequiredAttributeParseable<Optional<TiledColor>>("value", s => s == "" ? new Optional<TiledColor>() : TiledColor.Parse(s, CultureInfo.InvariantCulture)) },
PropertyType.File => new FileProperty { Name = name, Value = r.GetRequiredAttribute("value") }, PropertyType.File => new FileProperty { Name = name, Value = r.GetRequiredAttribute("value") },
PropertyType.Object => new ObjectProperty { Name = name, Value = r.GetRequiredAttributeParseable<uint>("value") }, PropertyType.Object => new ObjectProperty { Name = name, Value = r.GetRequiredAttributeParseable<uint>("value") },
PropertyType.Class => throw new XmlException("Class property must have a property type"), PropertyType.Class => throw new XmlException("Class property must have a property type"),

View file

@ -16,7 +16,7 @@ public abstract partial class TmxReaderBase
var height = _reader.GetRequiredAttributeParseable<int>("height"); var height = _reader.GetRequiredAttributeParseable<int>("height");
var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1.0f); var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1.0f);
var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(1) == 1; var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(1) == 1;
var tintColor = _reader.GetOptionalAttributeClass<TiledColor>("tintcolor"); var tintColor = _reader.GetOptionalAttributeParseable<TiledColor>("tintcolor");
var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0.0f); var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0.0f);
var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0.0f); var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0.0f);
var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1.0f); var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1.0f);
@ -63,7 +63,7 @@ public abstract partial class TmxReaderBase
var y = _reader.GetOptionalAttributeParseable<int>("y").GetValueOr(0); var y = _reader.GetOptionalAttributeParseable<int>("y").GetValueOr(0);
var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1f); var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1f);
var visible = _reader.GetOptionalAttributeParseable<bool>("visible").GetValueOr(true); var visible = _reader.GetOptionalAttributeParseable<bool>("visible").GetValueOr(true);
var tintColor = _reader.GetOptionalAttributeClass<TiledColor>("tintcolor"); var tintColor = _reader.GetOptionalAttributeParseable<TiledColor>("tintcolor");
var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0.0f); var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0.0f);
var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0.0f); var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0.0f);
var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1.0f); var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1.0f);
@ -110,7 +110,7 @@ public abstract partial class TmxReaderBase
var @class = _reader.GetOptionalAttribute("class").GetValueOr(""); var @class = _reader.GetOptionalAttribute("class").GetValueOr("");
var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1.0f); var opacity = _reader.GetOptionalAttributeParseable<float>("opacity").GetValueOr(1.0f);
var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(1) == 1; var visible = _reader.GetOptionalAttributeParseable<uint>("visible").GetValueOr(1) == 1;
var tintColor = _reader.GetOptionalAttributeClass<TiledColor>("tintcolor"); var tintColor = _reader.GetOptionalAttributeParseable<TiledColor>("tintcolor");
var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0f); var offsetX = _reader.GetOptionalAttributeParseable<float>("offsetx").GetValueOr(0f);
var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0f); var offsetY = _reader.GetOptionalAttributeParseable<float>("offsety").GetValueOr(0f);
var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1f); var parallaxX = _reader.GetOptionalAttributeParseable<float>("parallaxx").GetValueOr(1f);

View file

@ -125,7 +125,7 @@ public abstract partial class TmxReaderBase
_ => throw new InvalidOperationException($"Unknown image format '{s}'") _ => throw new InvalidOperationException($"Unknown image format '{s}'")
}); });
var source = _reader.GetOptionalAttribute("source"); var source = _reader.GetOptionalAttribute("source");
var transparentColor = _reader.GetOptionalAttributeClass<TiledColor>("trans"); var transparentColor = _reader.GetOptionalAttributeParseable<TiledColor>("trans");
var width = _reader.GetOptionalAttributeParseable<int>("width"); var width = _reader.GetOptionalAttributeParseable<int>("width");
var height = _reader.GetOptionalAttributeParseable<int>("height"); var height = _reader.GetOptionalAttributeParseable<int>("height");