Skip to content

Commit

Permalink
rebase onto flame-engine#69-dart-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
benni-tec committed Nov 6, 2023
1 parent 69ce91d commit 913b6ee
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 36 deletions.
14 changes: 13 additions & 1 deletion packages/tiled/lib/src/common/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int _sub(int hex, int index) {
return value;
}

class Color {
class Color extends ExportValue<String> {
final int red;
final int green;
final int blue;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/common/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ColorProperty extends Property<Color> {
}) : super(type: PropertyType.color);

@override
ExportValue get exportValue => value.toExport();
ExportValue get exportValue => value;
}

/// [value] is the string text
Expand Down
23 changes: 0 additions & 23 deletions packages/tiled/lib/src/exporter/export_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,6 @@ extension ExportableBool on bool {
ExportValue toExport() => _ExportableBool(this);
}

class _ExportableColor extends ExportValue<String> {
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<List<Map<String, double>>> {
final List<Point> points;

Expand Down
8 changes: 4 additions & 4 deletions packages/tiled/lib/src/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tiled_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions packages/tiled/test/exporter/map.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/test/exporter/properties.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/test/exporter/xml.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 913b6ee

Please sign in to comment.