-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: Add convenience method for getting images in each layer #66
feat: Add convenience method for getting images in each layer #66
Conversation
Seems some dependencies like flame_lint are outdated😅 |
You can do it in the same one if it is not too many changes :) |
As of these issues,
the tests are failing(technically, they could not be loaded). |
Hmm, why is this package even dependant on flutter (and flutter test)? 🤔 |
The test code action uses
Hmm..............🤣 |
After removing flutter from the dependencies, it complains |
Yeah, it will be a much bigger project to get flutter out of there. |
OK, I replaced the |
for (final row in layer.tileData ?? <List<Gid>>[]) { | ||
for (final gid in row) { | ||
final tileGid = gid.tile; | ||
|
||
if (tileGid == emptyTile || inspectedGids.contains(tileGid)) { | ||
continue; | ||
} | ||
inspectedGids.add(tileGid); | ||
usedTilesets.add(tilesetByTileGId(tileGid)); | ||
} | ||
} | ||
|
||
return usedTilesets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be
final rows = layer.tileData ?? <List<Gid>>[];
final gids = rows.expand((row) => row.map((gid) => gid.tile)).where((gid) => gid != emptyTile).toSet();
return gids.map(tilesetByTileGId) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a compact solution it is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to decide whether or not to divide the cascading in the middle.
Would you kindly give some thoughts on this?
return rows
.expand((row) => row.map((gid) => gid.tile))
.where((gid) => gid != emptyTile)
.toSet()
.map(tilesetByTileGId)
.toSet()
.expand(
(tileset) =>
[tileset.image, ...tileset.tiles.map((tile) => tile.image)],
)
.whereNotNull()
.toList();
final gids = rows
.expand((row) => row.map((gid) => gid.tile))
.where((gid) => gid != emptyTile)
.toSet();
return gids
.map(tilesetByTileGId)
.toSet()
.expand(
(tileset) =>
[tileset.image, ...tileset.tiles.map((tile) => tile.image)],
)
.whereNotNull()
.toList();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second one might give slightly more readability.
You shouldn't have to do toSet
again after map(tilesetByTileGId)
, since the gid list already is unique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't have to do toSet again after map(tilesetByTileGId), since the gid list already is unique.
The gid list is unique but they can be nonunique after map(tilesetByTileGId)
because different gid can have the same tileset, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, true :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Description
This PR adds the convenience method to the TiledMap that gets all TiledImage in the specific layer.
If the layer is Group, the method gets all images in the group recursively.
Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change
Related Issues
N/A