Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ObjectAlignment enum names #74

Merged
merged 10 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/tiled/lib/src/common/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,19 @@ enum ObjectAlignment {
right,
bottomLeft,
bottom,
bottomRight,
bottomRight;

/// Returns the [ObjectAlignment] based on given [name].
///
/// Throws an [ArgumentError] if no match is found.
static ObjectAlignment byName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static ObjectAlignment byName(String name) {
static ObjectAlignment fromName(String name) {

Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to fromName

for (final value in ObjectAlignment.values) {
if (value.name == name) {
return value;
}
}
throw ArgumentError.value(name, 'name', 'No enum value with that name');
}
}

extension ObjectAlignmentExtension on ObjectAlignment {
Expand All @@ -390,23 +402,23 @@ extension ObjectAlignmentExtension on ObjectAlignment {
case ObjectAlignment.unspecified:
return 'unspecified';
case ObjectAlignment.topLeft:
return 'topLeft';
return 'topleft';
case ObjectAlignment.top:
return 'top';
case ObjectAlignment.topRight:
return 'topRight';
return 'topright';
case ObjectAlignment.left:
return 'left';
case ObjectAlignment.center:
return 'center';
case ObjectAlignment.right:
return 'right';
case ObjectAlignment.bottomLeft:
return 'bottomLeft';
return 'bottomleft';
case ObjectAlignment.bottom:
return 'bottom';
case ObjectAlignment.bottomRight:
return 'bottomRight';
return 'bottomright';
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions packages/tiled/lib/src/common/flips.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ class Flips {
final bool diagonally;
final bool antiDiagonally;

const Flips(
this.horizontally,
this.vertically,
this.diagonally,
this.antiDiagonally,
);
const Flips({
required this.horizontally,
required this.vertically,
required this.diagonally,
required this.antiDiagonally,
});

const Flips.defaults() : this(false, false, false, false);
const Flips.defaults()
: this(
horizontally: false,
vertically: false,
diagonally: false,
antiDiagonally: false,
);

Flips copyWith({
bool? horizontally,
Expand All @@ -22,10 +28,10 @@ class Flips {
bool? antiDiagonally,
}) {
return Flips(
horizontally ?? this.horizontally,
vertically ?? this.vertically,
diagonally ?? this.diagonally,
antiDiagonally ?? this.antiDiagonally,
horizontally: horizontally ?? this.horizontally,
vertically: vertically ?? this.vertically,
diagonally: diagonally ?? this.diagonally,
antiDiagonally: antiDiagonally ?? this.antiDiagonally,
);
}
}
8 changes: 4 additions & 4 deletions packages/tiled/lib/src/common/gid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class Gid {
flippedDiagonallyFlag |
flippedAntiDiagonallyFlag);
final flip = Flips(
flippedHorizontally,
flippedVertically,
flippedDiagonally,
flippedAntiDiagonally,
horizontally: flippedHorizontally,
vertically: flippedVertically,
diagonally: flippedDiagonally,
antiDiagonally: flippedAntiDiagonally,
);
return Gid(tileId, flip);
}
Expand Down
26 changes: 13 additions & 13 deletions packages/tiled/lib/src/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ abstract class Layer {
CustomProperties properties;

Layer({
this.id,
required this.name,
required this.type,
this.id,
this.class_,
this.x = 0,
this.y = 0,
Expand Down Expand Up @@ -298,7 +298,7 @@ abstract class Layer {
}
final text = xml.element.children.first;
if (text is XmlText) {
return text.text;
return text.value;
}
return null;
},
Expand Down Expand Up @@ -380,8 +380,10 @@ class TileLayer extends Layer {
List<List<Gid>>? tileData;

TileLayer({
super.id,
required super.name,
required this.width,
required this.height,
super.id,
super.class_,
super.x,
super.y,
Expand All @@ -396,8 +398,6 @@ class TileLayer extends Layer {
super.opacity,
super.visible,
super.properties,
required this.width,
required this.height,
this.compression,
this.encoding = FileEncoding.csv,
this.chunks,
Expand Down Expand Up @@ -441,8 +441,9 @@ class ObjectGroup extends Layer {
Color color;

ObjectGroup({
super.id,
required super.name,
required this.objects,
super.id,
super.class_,
super.x,
super.y,
Expand All @@ -458,7 +459,6 @@ class ObjectGroup extends Layer {
super.visible,
super.properties,
this.drawOrder = DrawOrder.topDown,
required this.objects,
this.colorHex = defaultColorHex,
this.color = defaultColor,
}) : super(
Expand Down Expand Up @@ -487,8 +487,11 @@ class ImageLayer extends Layer {
bool repeatY;

ImageLayer({
super.id,
required super.name,
required this.image,
required this.repeatX,
required this.repeatY,
super.id,
super.class_,
super.x,
super.y,
Expand All @@ -503,9 +506,6 @@ class ImageLayer extends Layer {
super.opacity,
super.visible,
super.properties,
required this.image,
required this.repeatX,
required this.repeatY,
this.transparentColorHex,
this.transparentColor,
}) : super(
Expand All @@ -518,8 +518,9 @@ class Group extends Layer {
List<Layer> layers;

Group({
super.id,
required super.name,
required this.layers,
super.id,
super.class_,
super.x,
super.y,
Expand All @@ -534,7 +535,6 @@ class Group extends Layer {
super.opacity,
super.visible,
super.properties,
required this.layers,
}) : super(
type: LayerType.imageLayer,
);
Expand Down
8 changes: 4 additions & 4 deletions packages/tiled/lib/src/tiled_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ class TiledMap {
StaggerIndex? staggerIndex;

TiledMap({
this.type = TileMapType.map,
this.version = '1.0',
this.tiledVersion,
required this.width,
required this.height,
this.infinite = false,
required this.tileWidth,
required this.tileHeight,
this.type = TileMapType.map,
this.version = '1.0',
this.tiledVersion,
this.infinite = false,
this.tilesets = const [],
this.layers = const [],
this.backgroundColorHex,
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/lib/src/tileset/tileset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Tileset {
final firstGid = parser.getIntOrNull('firstgid');
final margin = parser.getInt('margin', defaults: 0);
final name = parser.getStringOrNull('name');
final objectAlignment = ObjectAlignment.values.byName(
final objectAlignment = ObjectAlignment.byName(
parser.getString('objectalignment', defaults: 'unspecified'),
);
final source = parser.getStringOrNull('source');
Expand Down
2 changes: 1 addition & 1 deletion packages/tiled/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ dependencies:

dev_dependencies:
dartdoc: ^6.0.1
flame_lint: ^0.2.0
flame_lint: ^1.1.1
flutter_test:
sdk: flutter
2 changes: 1 addition & 1 deletion packages/tiled/test/map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void main() {
image: const TiledImage(),
),
],
)
),
],
);
});
Expand Down
25 changes: 25 additions & 0 deletions packages/tiled/test/object_alignment_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:tiled/tiled.dart';

void main() {
group('ObjectAlignment', () {
test('ObjectAlignment.byName', () {
expect(
ObjectAlignment.byName('unspecified'),
ObjectAlignment.unspecified,
);
expect(ObjectAlignment.byName('topleft'), ObjectAlignment.topLeft);
expect(ObjectAlignment.byName('top'), ObjectAlignment.top);
expect(ObjectAlignment.byName('topright'), ObjectAlignment.topRight);
expect(ObjectAlignment.byName('left'), ObjectAlignment.left);
expect(ObjectAlignment.byName('center'), ObjectAlignment.center);
expect(ObjectAlignment.byName('right'), ObjectAlignment.right);
expect(ObjectAlignment.byName('bottomleft'), ObjectAlignment.bottomLeft);
expect(ObjectAlignment.byName('bottom'), ObjectAlignment.bottom);
expect(
ObjectAlignment.byName('bottomright'),
ObjectAlignment.bottomRight,
);
});
});
}
4 changes: 3 additions & 1 deletion packages/tiled/test/tileset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ void main() {
test(
'first objectgroup object = ellipsis',
() => expect(
((tileset.tiles.first.objectGroup as ObjectGroup?)!.objects.first)
(tileset.tiles.first.objectGroup as ObjectGroup?)!
.objects
.first
.isEllipse,
true,
),
Expand Down
7 changes: 7 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: tiled_workspace

environment:
sdk: ">=3.0.0 <4.0.0"

dev_dependencies:
melos: ^3.0.0
Loading