Skip to content

Commit aeef188

Browse files
author
benni-tec
committed
Merge branch 'flame-engine#69-dart-sdk'
2 parents 93d2d81 + 8f38c1c commit aeef188

10 files changed

+37
-19
lines changed
+23-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
part of tiled;
22

33
const _mask = 0xff;
4-
int _sub(int hex, int index) => (hex & (_mask << index * 8)) >> index * 8;
54

6-
class Color extends RgbColor {
5+
int _sub(int hex, int index) {
6+
final value = (hex & (_mask << index * 8)) >> index * 8;
7+
assert(value >= 0 && value < 256);
8+
return value;
9+
}
10+
11+
class Color {
12+
final int red;
13+
final int green;
14+
final int blue;
15+
final int alpha;
16+
717
/// Format: aarrggbb
8-
Color(int hex) : super(_sub(hex, 2), _sub(hex, 1), _sub(hex, 0), _sub(hex, 3));
18+
Color.hex(int hex)
19+
: alpha = _sub(hex, 3),
20+
red = _sub(hex, 2),
21+
green = _sub(hex, 1),
22+
blue = _sub(hex, 0);
23+
24+
const Color.rgb(this.red, this.green, this.blue, [this.alpha = 255])
25+
: assert(red >= 0 && red <= 255),
26+
assert(green >= 0 && green <= 255),
27+
assert(blue >= 0 && blue <= 255),
28+
assert(alpha >= 0 && alpha <= 255);
929
}

packages/tiled/lib/src/common/property.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Property<T> {
3737
case PropertyType.color:
3838
return ColorProperty(
3939
name: name,
40-
value: parser.getColor('value', defaults: Color(0x00000000)),
40+
value: parser.getColor('value', defaults: Color.hex(0x00000000)),
4141
hexValue: parser.getString('value', defaults: '#00000000'),
4242
);
4343

@@ -156,7 +156,7 @@ class ObjectProperty extends Property<int> {
156156
}
157157

158158
/// [value] is the color
159-
class ColorProperty extends Property<ColorModel> {
159+
class ColorProperty extends Property<Color> {
160160
final String hexValue;
161161

162162
ColorProperty({

packages/tiled/lib/src/layer.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ abstract class Layer {
8181
/// child layers (optional).
8282
///
8383
/// Parsed from [tintColorHex], will be null if parsing fails for any reason.
84-
ColorModel? tintColor;
84+
Color? tintColor;
8585

8686
/// The opacity of the layer as a value from 0 to 1. Defaults to 1.
8787
double opacity;
@@ -420,7 +420,7 @@ class TileLayer extends Layer {
420420
}
421421

422422
class ObjectGroup extends Layer {
423-
static const defaultColor = RgbColor(160, 160, 164, 255);
423+
static const defaultColor = Color.rgb(160, 160, 164, 255);
424424
static const defaultColorHex = '%a0a0a4';
425425

426426
/// topdown (default) or index (indexOrder).
@@ -438,7 +438,7 @@ class ObjectGroup extends Layer {
438438
///
439439
/// Parsed from [colorHex], will be fallback to [defaultColor] if parsing
440440
/// fails for any reason.
441-
ColorModel color;
441+
Color color;
442442

443443
ObjectGroup({
444444
super.id,
@@ -478,7 +478,7 @@ class ImageLayer extends Layer {
478478
///
479479
/// Parsed from [transparentColorHex], will be null if parsing fails for any
480480
/// reason.
481-
ColorModel? transparentColor;
481+
Color? transparentColor;
482482

483483
/// Whether or not to repeat the image on the X-axis
484484
bool repeatX;

packages/tiled/lib/src/parser.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ abstract class Parser {
197197
return result;
198198
}
199199

200-
ColorModel? getColorOrNull(String name, {ColorModel? defaults}) {
200+
Color? getColorOrNull(String name, {Color? defaults}) {
201201
final tiledColor = getStringOrNull(name);
202202

203203
// Tiled colors are stored as either ARGB or RGB hex values, so we can
@@ -212,13 +212,13 @@ abstract class Parser {
212212
}
213213

214214
if (colorValue != null) {
215-
return Color(colorValue);
215+
return Color.hex(colorValue);
216216
} else {
217217
return defaults;
218218
}
219219
}
220220

221-
ColorModel getColor(String name, {ColorModel? defaults}) {
221+
Color getColor(String name, {Color? defaults}) {
222222
final result = getColorOrNull(name, defaults: defaults);
223223
if (result == null) {
224224
throw ParsingException(name, null, 'Missing required color field');

packages/tiled/lib/src/tiled_map.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class TiledMap {
7979
///
8080
/// Parsed from [backgroundColorHex], will be null if parsing fails for any
8181
/// reason.
82-
ColorModel? backgroundColor;
82+
Color? backgroundColor;
8383

8484
int compressionLevel;
8585

packages/tiled/lib/tiled.dart

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:typed_data';
77

88
import 'package:archive/archive.dart';
99
import 'package:collection/collection.dart';
10-
import 'package:color_models/color_models.dart';
1110
import 'package:meta/meta.dart';
1211
import 'package:xml/xml.dart';
1312

packages/tiled/pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies:
1010
collection: ^1.16.0
1111
meta: ^1.7.0
1212
xml: ^6.1.0
13-
color_models: ^1.3.3
1413

1514
dev_dependencies:
1615
dartdoc: ^6.0.1

packages/tiled/test/layer_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void main() {
7474
expect(layer.tintColorHex, equals('#ffaabb'));
7575
expect(
7676
layer.tintColor,
77-
equals(Color(int.parse('0xffffaabb'))),
77+
equals(Color.hex(int.parse('0xffffaabb'))),
7878
);
7979
});
8080
});

packages/tiled/test/object_group_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void main() {
3030
expect(objectGroup.colorHex, equals('#555500'));
3131
expect(
3232
objectGroup.color,
33-
equals(Color(int.parse('0xff555500'))),
33+
equals(Color.hex(int.parse('0xff555500'))),
3434
);
3535
});
3636

packages/tiled/test/parser_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void main() {
4343
expect(map.backgroundColorHex, equals('#ccddaaff'));
4444
expect(
4545
map.backgroundColor,
46-
equals(Color(int.parse('0xccddaaff'))),
46+
equals(Color.hex(int.parse('0xccddaaff'))),
4747
);
4848
});
4949

@@ -100,7 +100,7 @@ void main() {
100100
);
101101
expect(
102102
properties.getValue<Color>('color property'),
103-
equals(Color(0x00112233)),
103+
equals(Color.hex(0x00112233)),
104104
);
105105
expect(
106106
properties.getValue<double>('float property'),

0 commit comments

Comments
 (0)