Skip to content

Commit 5ffc8bf

Browse files
benni-tecbenni-tecspydon
authored
feat!: Dart SDK compatibility (#77)
# Description This PR makes this package compatible with the Dart SDK. In order to achieve this I changed 3 things: - Replace `dart:ui`'s Color with a simple ColorData class - Replaced `Rect` from `flame` with `Rectangle` from `dart:math` - Replaced `flutter_test` with `test` package The `ColorData` class is used excatly once for which I prepared a flame_tiled PR (however I need to wait until this is merged right) including conversion extensions. No `Rectangle` attribute is ever read in `flame_tiled`, evenso `flame` already contains conversion extensions! ## Checklist - [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc). - [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs. --> `melos run analyze` fails due to `XmlData.value` however I think this requires another issue/PR - [x] I have updated/added tests for ALL new/updated/fixed functionality. - [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`. - [x] I have updated/added relevant examples in `examples`. --> I don't think there are any exmaples necessary for this ## Breaking Change - [x] Yes, this is a breaking change. - [ ] No, this is *not* a breaking change. I think this should result in a minor version bump to 0.11.0 to indicate these breaking changes! In order to achieve dart comaptibilty only two things changed: - Color: Custom data class --> `flame_tiled` contains a conversion extension - Rect: Instead using `dart:math`'s Rectangle --> Use `flame`'s `toRect()` method to convert ## Related Issues - #69 --------- Co-authored-by: benni-tec <[email protected]> Co-authored-by: Lukas Klingsbo <[email protected]>
1 parent 581391c commit 5ffc8bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+209
-126
lines changed

packages/tiled/lib/src/chunk.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of '../tiled.dart';
1+
import 'package:tiled/tiled.dart';
22

33
/// Below is Tiled's documentation about how this structure is represented
44
/// on XML files:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'package:meta/meta.dart';
2+
3+
/// Basic data class holding a Color in ARGB format.
4+
/// This can be converted to dart:ui's Color using the flame_tiled package
5+
@immutable
6+
class ColorData {
7+
static int _sub(int hex, int index) => (hex >> index * 8) & 0x000000ff;
8+
9+
final int _hex;
10+
11+
int get alpha => _sub(_hex, 3);
12+
13+
int get red => _sub(_hex, 2);
14+
15+
int get green => _sub(_hex, 1);
16+
17+
int get blue => _sub(_hex, 0);
18+
19+
/// Parses the Color from an int using the lower 32-bits and tiled's format:
20+
/// 0xaarrggbb
21+
const ColorData.hex(this._hex);
22+
23+
const ColorData.rgb(int red, int green, int blue, [int alpha = 255])
24+
: assert(red >= 0 && red <= 255),
25+
assert(green >= 0 && green <= 255),
26+
assert(blue >= 0 && blue <= 255),
27+
assert(alpha >= 0 && alpha <= 255),
28+
_hex = (alpha << 3 * 8) +
29+
(red << 2 * 8) +
30+
(green << 1 * 8) +
31+
(blue << 0 * 8);
32+
33+
const ColorData.argb(int alpha, int red, int green, int blue)
34+
: assert(red >= 0 && red <= 255),
35+
assert(green >= 0 && green <= 255),
36+
assert(blue >= 0 && blue <= 255),
37+
assert(alpha >= 0 && alpha <= 255),
38+
_hex = (alpha << 3 * 8) +
39+
(red << 2 * 8) +
40+
(green << 1 * 8) +
41+
(blue << 0 * 8);
42+
43+
@override
44+
bool operator ==(Object other) {
45+
if (other is! ColorData) {
46+
return false;
47+
}
48+
return _hex == other._hex;
49+
}
50+
51+
@override
52+
int get hashCode => _hex.hashCode;
53+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of '../../tiled.dart';
1+
import 'package:tiled/src/parser.dart';
22

33
enum MapOrientation { orthogonal, isometric, staggered, hexagonal }
44

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
part of '../../tiled.dart';
2-
31
class Flips {
42
final bool horizontally;
53
final bool vertically;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of '../../tiled.dart';
1+
import 'package:tiled/src/parser.dart';
22

33
/// Below is Tiled's documentation about how this structure is represented
44
/// on XML files:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of '../../tiled.dart';
1+
import 'package:tiled/tiled.dart';
22

33
/// A [Gid], Global Tile ID is a Tiled concept to represent the tiles inside
44
/// int matrices. This wrapper is used by [Layer] and [Chunk] to provide

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of '../../tiled.dart';
1+
import 'package:tiled/src/parser.dart';
22

33
/// Below is Tiled's documentation about how this structure is represented
44
/// on XML files:

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
part of '../../tiled.dart';
1+
import 'package:collection/collection.dart';
2+
import 'package:tiled/tiled.dart';
3+
import 'package:xml/xml.dart';
24

35
/// Below is Tiled's documentation about how this structure is represented
46
/// on XML files:
@@ -37,7 +39,10 @@ class Property<T> {
3739
case PropertyType.color:
3840
return ColorProperty(
3941
name: name,
40-
value: parser.getColor('value', defaults: const Color(0x00000000)),
42+
value: parser.getColor(
43+
'value',
44+
defaults: const ColorData.hex(0x00000000),
45+
),
4146
hexValue: parser.getString('value', defaults: '#00000000'),
4247
);
4348

@@ -156,7 +161,7 @@ class ObjectProperty extends Property<int> {
156161
}
157162

158163
/// [value] is the color
159-
class ColorProperty extends Property<Color> {
164+
class ColorProperty extends Property<ColorData> {
160165
final String hexValue;
161166

162167
ColorProperty({

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
part of '../../tiled.dart';
1+
import 'package:meta/meta.dart';
2+
import 'package:tiled/src/parser.dart';
23

34
/// Below is Tiled's documentation about how this structure is represented
45
/// on XML files:

packages/tiled/lib/src/editor_setting/chunk_size.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of '../../tiled.dart';
1+
import 'package:tiled/src/parser.dart';
22

33
/// Below is Tiled's documentation about how this structure is represented
44
/// on XML files:

0 commit comments

Comments
 (0)