Skip to content

Commit

Permalink
Add byName for ObjectAlignment
Browse files Browse the repository at this point in the history
  • Loading branch information
ufrshubham committed Nov 3, 2023
1 parent 7e58b48 commit 7290844
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion 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) {
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 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

0 comments on commit 7290844

Please sign in to comment.