Skip to content

Commit c37b7cf

Browse files
author
benni-tec
committed
removed need for flutter sdk (dart:ui)
--> replaced dart:ui Color with color_model package --> custom Rect instead of dart:ui --> replaced flutter_test with test package
1 parent 41c9439 commit c37b7cf

22 files changed

+66
-41
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:color_models/color_models.dart';
2+
3+
const _mask = 0xff;
4+
int _sub(int hex, int index) => (hex & (_mask << index * 8)) >> index * 8;
5+
6+
class Color extends RgbColor {
7+
/// Format: aarrggbb
8+
Color(int hex) : super(_sub(hex, 2), _sub(hex, 1), _sub(hex, 0), _sub(hex, 3));
9+
}

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

Lines changed: 2 additions & 2 deletions
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: const Color(0x00000000)),
40+
value: parser.getColor('value', defaults: Color(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<Color> {
159+
class ColorProperty extends Property<ColorModel> {
160160
final String hexValue;
161161

162162
ColorProperty({
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Rect {
2+
final double x;
3+
final double y;
4+
final double width;
5+
final double height;
6+
7+
Rect.fromLTWH(this.x, this.y, this.width, this.height);
8+
9+
@override
10+
bool operator ==(Object other) {
11+
if (other is! Rect) return false;
12+
return x == other.x && y == other.y && width == other.width && height == other.height;
13+
}
14+
15+
@override
16+
int get hashCode => Object.hash(x, y, width, height);
17+
}

packages/tiled/lib/src/layer.dart

Lines changed: 4 additions & 4 deletions
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-
Color? tintColor;
84+
ColorModel? 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 = Color.fromARGB(255, 160, 160, 164);
423+
static const defaultColor = RgbColor(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-
Color color;
441+
ColorModel 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-
Color? transparentColor;
481+
ColorModel? transparentColor;
482482

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

packages/tiled/lib/src/parser.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ abstract class Parser {
197197
return result;
198198
}
199199

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

203203
// Tiled colors are stored as either ARGB or RGB hex values, so we can
@@ -218,7 +218,7 @@ abstract class Parser {
218218
}
219219
}
220220

221-
Color getColor(String name, {Color? defaults}) {
221+
ColorModel getColor(String name, {ColorModel? 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

Lines changed: 1 addition & 1 deletion
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-
Color? backgroundColor;
82+
ColorModel? backgroundColor;
8383

8484
int compressionLevel;
8585

packages/tiled/lib/tiled.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import 'dart:collection';
44
import 'dart:convert';
55
import 'dart:math' show Rectangle;
66
import 'dart:typed_data';
7-
import 'dart:ui';
87

98
import 'package:archive/archive.dart';
109
import 'package:collection/collection.dart';
10+
import 'package:color_models/color_models.dart';
1111
import 'package:meta/meta.dart';
12+
import 'package:tiled/src/common/color.dart';
13+
import 'package:tiled/src/common/rect.dart';
1214
import 'package:xml/xml.dart';
1315

1416
part 'src/chunk.dart';

packages/tiled/pubspec.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ environment:
88
dependencies:
99
archive: ^3.3.0
1010
collection: ^1.16.0
11-
flutter:
12-
sdk: flutter
1311
meta: ^1.7.0
1412
xml: ^6.1.0
13+
color_models: ^1.3.3
1514

1615
dev_dependencies:
1716
dartdoc: ^6.0.1
18-
flame_lint: ^0.2.0
19-
flutter_test:
20-
sdk: flutter
17+
test: ^1.24.8

packages/tiled/test/complexmap_infinite_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:io';
22

3-
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:test/test.dart';
44
import 'package:tiled/tiled.dart';
55

66
void main() {

packages/tiled/test/image_layer_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:io';
22

3-
import 'package:flutter_test/flutter_test.dart';
43
import 'package:tiled/tiled.dart';
4+
import 'package:test/test.dart';
55

66
void main() {
77
late TiledMap map;

0 commit comments

Comments
 (0)