diff --git a/packages/tiled/lib/src/common/color.dart b/packages/tiled/lib/src/common/color.dart index f1e077c..c8078e6 100644 --- a/packages/tiled/lib/src/common/color.dart +++ b/packages/tiled/lib/src/common/color.dart @@ -8,7 +8,7 @@ int _sub(int hex, int index) { return value; } -class Color { +class Color extends ExportValue { final int red; final int green; final int blue; @@ -26,4 +26,16 @@ class Color { assert(green >= 0 && green <= 255), assert(blue >= 0 && blue <= 255), assert(alpha >= 0 && alpha <= 255); + + static String _hex(int value) { + return value.toRadixString(16).padLeft(2, '0'); + } + + String get export => '#${_hex(alpha)}${_hex(red)}${_hex(green)}${_hex(blue)}'; + + @override + String get json => export; + + @override + String get xml => export; } diff --git a/packages/tiled/lib/src/common/property.dart b/packages/tiled/lib/src/common/property.dart index 7c6f9d8..2f4724b 100644 --- a/packages/tiled/lib/src/common/property.dart +++ b/packages/tiled/lib/src/common/property.dart @@ -174,7 +174,7 @@ class ColorProperty extends Property { }) : super(type: PropertyType.color); @override - ExportValue get exportValue => value.toExport(); + ExportValue get exportValue => value; } /// [value] is the string text diff --git a/packages/tiled/lib/src/exporter/export_value.dart b/packages/tiled/lib/src/exporter/export_value.dart index 7602367..e1566fa 100644 --- a/packages/tiled/lib/src/exporter/export_value.dart +++ b/packages/tiled/lib/src/exporter/export_value.dart @@ -49,29 +49,6 @@ extension ExportableBool on bool { ExportValue toExport() => _ExportableBool(this); } -class _ExportableColor extends ExportValue { - final Color color; - - const _ExportableColor(this.color); - - static String _hex(int value) { - return value.toRadixString(16).padLeft(2, '0'); - } - - String get export => - '#${_hex(color.alpha)}${_hex(color.red)}${_hex(color.green)}${_hex(color.blue)}'; - - @override - String get json => export; - - @override - String get xml => export; -} - -extension ExportableColor on Color { - ExportValue toExport() => _ExportableColor(this); -} - class _ExportablePointList extends ExportValue>> { final List points; diff --git a/packages/tiled/lib/src/layer.dart b/packages/tiled/lib/src/layer.dart index c0a8cc1..6051c1b 100644 --- a/packages/tiled/lib/src/layer.dart +++ b/packages/tiled/lib/src/layer.dart @@ -502,8 +502,8 @@ class ObjectGroup extends Layer { 'type': type.name.toExport(), 'x': x.toExport(), 'y': y.toExport(), - 'color': color.toExport(), - 'tintcolor': tintColor?.toExport(), + 'color': color, + 'tintcolor': tintColor, 'opacity': opacity.toExport(), 'visible': (visible ? 1 : 0).toExport(), 'offsetx': offsetX.toExport(), @@ -574,7 +574,7 @@ class ImageLayer extends Layer { 'type': type.name.toExport(), 'x': x.toExport(), 'y': y.toExport(), - 'tintcolor': tintColor?.toExport(), + 'tintcolor': tintColor, 'opacity': opacity.toExport(), 'visible': (visible ? 1 : 0).toExport(), 'offsetx': offsetX.toExport(), @@ -623,7 +623,7 @@ class Group extends Layer { 'name': name.toExport(), 'class': class_?.toExport(), 'type': type.name.toExport(), - 'tintcolor': tintColor?.toExport(), + 'tintcolor': tintColor, 'opacity': opacity.toExport(), 'visible': (visible ? 1 : 0).toExport(), 'offsetx': offsetX.toExport(), diff --git a/packages/tiled/lib/src/tiled_map.dart b/packages/tiled/lib/src/tiled_map.dart index ff6a301..c5c28b5 100644 --- a/packages/tiled/lib/src/tiled_map.dart +++ b/packages/tiled/lib/src/tiled_map.dart @@ -380,7 +380,7 @@ class TiledMap with Exportable { 'staggerindex': staggerIndex?.name.toExport(), // 'parallaxoriginx': , 'parallaxoriginy': , Not supplied by this class - 'backgroundcolor': backgroundColor?.toExport(), + 'backgroundcolor': backgroundColor, 'nextlayerid': nextLayerId?.toExport(), 'nextobjectid': nextObjectId?.toExport(), 'infinite': infinite.toExport(), diff --git a/packages/tiled/test/exporter/map.dart b/packages/tiled/test/exporter/map.dart index ce2170e..ac0da43 100644 --- a/packages/tiled/test/exporter/map.dart +++ b/packages/tiled/test/exporter/map.dart @@ -1,6 +1,4 @@ -import 'dart:ui'; - -import 'package:flutter_test/flutter_test.dart'; +import 'package:test/test.dart'; import 'package:tiled/tiled.dart'; import 'package:xml/xml.dart'; @@ -16,7 +14,7 @@ void main() { hexSideLength: 24, staggerAxis: StaggerAxis.y, staggerIndex: StaggerIndex.even, - backgroundColor: const Color(0xaa252627), + backgroundColor: Color.hex(0xaa252627), nextLayerId: 24, nextObjectId: 56, infinite: false, diff --git a/packages/tiled/test/exporter/properties.dart b/packages/tiled/test/exporter/properties.dart index bf1307a..c05c62e 100644 --- a/packages/tiled/test/exporter/properties.dart +++ b/packages/tiled/test/exporter/properties.dart @@ -1,5 +1,5 @@ import 'package:collection/collection.dart'; -import 'package:flutter_test/flutter_test.dart'; +import 'package:test/test.dart'; import 'package:tiled/tiled.dart'; import 'package:xml/xml.dart'; diff --git a/packages/tiled/test/exporter/xml.dart b/packages/tiled/test/exporter/xml.dart index be1dba5..5a07039 100644 --- a/packages/tiled/test/exporter/xml.dart +++ b/packages/tiled/test/exporter/xml.dart @@ -1,4 +1,4 @@ -import 'package:flutter_test/flutter_test.dart'; +import 'package:test/test.dart'; import 'package:xml/xml.dart'; class XmlDeepMatcher extends Matcher {