From 82a2b34c7d17315baa05a0fff4d3fc068852f6be Mon Sep 17 00:00:00 2001 From: benni-tec Date: Fri, 20 Dec 2024 09:41:13 +0100 Subject: [PATCH] switched color back to using a hex string --- packages/tiled/lib/src/common/color.dart | 33 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/tiled/lib/src/common/color.dart b/packages/tiled/lib/src/common/color.dart index 135bf22..7366d7b 100644 --- a/packages/tiled/lib/src/common/color.dart +++ b/packages/tiled/lib/src/common/color.dart @@ -5,21 +5,32 @@ part of tiled; class ColorData { static int _sub(int hex, int index) => (hex >> index * 8) & 0x000000ff; - final int red; - final int green; - final int blue; - final int alpha; + final int _hex; + + int get alpha => _sub(_hex, 3); + + int get red => _sub(_hex, 2); + + int get green => _sub(_hex, 1); + + int get blue => _sub(_hex, 0); /// Parses the Color from an int using the lower 32-bits and tiled's format: 0xaarrggbb - ColorData.hex(int hex) - : alpha = _sub(hex, 3), - red = _sub(hex, 2), - green = _sub(hex, 1), - blue = _sub(hex, 0); + const ColorData.hex(this._hex); + + const ColorData.rgb(int red, int green, int blue, [int alpha = 255]) + : assert(red >= 0 && red <= 255), + assert(green >= 0 && green <= 255), + assert(blue >= 0 && blue <= 255), + assert(alpha >= 0 && alpha <= 255), + _hex = (alpha << 3 * 8) + (red << 2 * 8) + (green << 1 * 8) + + (blue << 0 * 8); - const ColorData.rgb(this.red, this.green, this.blue, [this.alpha = 255]) + const ColorData.argb(int alpha, int red, int green, int blue) : assert(red >= 0 && red <= 255), assert(green >= 0 && green <= 255), assert(blue >= 0 && blue <= 255), - assert(alpha >= 0 && alpha <= 255); + assert(alpha >= 0 && alpha <= 255), + _hex = (alpha << 3 * 8) + (red << 2 * 8) + (green << 1 * 8) + + (blue << 0 * 8); }