Repository: flame-engine/flame

Issue:
Add key parameter to TiledComponent.load
### What could be improved

The `TiledComponent.load` static method could accept a `key` parameter.

### Why should this be improved

When a key is desired, one must fall back to the normal constructor of `TiledComponent` and manually load the `RenderableTileMap`, and also provide arguments which are already provided with reasonable defaults in the `load` method.

### Risks

No risks

### More information

_No response_

### Other

- [x] Are you interested in working on a PR for this?


Discussion: I'll assign you to the issue since you've indicated that you want to work on it. For one-liners like this you don't have to open an issue first. 😊

Fix patch:
diff --git a/packages/flame_tiled/lib/src/tiled_component.dart b/packages/flame_tiled/lib/src/tiled_component.dart
index 4413935089c..6f08224d9dd 100644
--- a/packages/flame_tiled/lib/src/tiled_component.dart
+++ b/packages/flame_tiled/lib/src/tiled_component.dart
@@ -119,6 +119,7 @@ class TiledComponent<T extends FlameGame> extends PositionComponent
     Paint Function(double opacity)? layerPaintFactory,
     double atlasPackingSpacingX = 0,
     double atlasPackingSpacingY = 0,
+    ComponentKey? key,
   }) async {
     return TiledComponent(
       await RenderableTiledMap.fromFile(
@@ -137,6 +138,7 @@ class TiledComponent<T extends FlameGame> extends PositionComponent
         atlasPackingSpacingY: atlasPackingSpacingY,
       ),
       priority: priority,
+      key: key,
     );
   }
 


Test patch:
diff --git a/packages/flame_tiled/test/tiled_test.dart b/packages/flame_tiled/test/tiled_test.dart
index b300c514721..b6575f86194 100644
--- a/packages/flame_tiled/test/tiled_test.dart
+++ b/packages/flame_tiled/test/tiled_test.dart
@@ -33,7 +33,11 @@ void main() {
         imageNames: ['map-level1.png', 'image1.png'],
         stringNames: ['map.tmx', 'tiles_custom_path/map_custom_path.tmx'],
       );
-      tiled = await TiledComponent.load('map.tmx', Vector2.all(16));
+      tiled = await TiledComponent.load(
+        'map.tmx',
+        Vector2.all(16),
+        key: ComponentKey.named('test'),
+      );
     });
 
     test('correct loads the file', () {
@@ -56,6 +60,10 @@ void main() {
       expect(tiled.tileMap.renderableLayers.length, equals(3));
     });
 
+    test('assigns key', () async {
+      expect(tiled.key, equals(ComponentKey.named('test')));
+    });
+
     group('is positionable', () {
       test('size, width, and height are readable - not writable', () {
         expect(tiled.size, Vector2(512.0, 2048.0));