Skip to content

Commit

Permalink
feat: Merge pull request #115 from Piturnah/feat/names
Browse files Browse the repository at this point in the history
Insert `Name` component into entities spawned by crate
  • Loading branch information
Trouv authored Sep 2, 2022
2 parents eb27c37 + 9bcfa6a commit 33f2b73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app/ldtk_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ pub trait LdtkEntity {
/// registered to the app.
///
/// Note: whether or not the entity is registered to the app, the plugin will insert [Transform],
/// [GlobalTransform], and [Parent] components to the entity **after** this bundle is inserted.
/// [GlobalTransform], [Name], and [Parent] components to the entity **after** this bundle is
/// inserted.
/// So, any custom implementations of these components within this trait will be overwritten.
fn bundle_entity(
entity_instance: &EntityInstance,
Expand Down
13 changes: 8 additions & 5 deletions src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,12 @@ pub fn spawn_level(
texture_atlases,
);

entity_commands.insert_bundle(SpatialBundle {
transform,
..default()
});
entity_commands
.insert_bundle(SpatialBundle {
transform,
..default()
})
.insert(Name::new(entity_instance.identifier.to_owned()));
}
}
});
Expand Down Expand Up @@ -675,7 +677,8 @@ pub fn spawn_level(
.insert_bundle(SpatialBundle::from_transform(
Transform::from_translation(layer_offset).with_scale(layer_scale),
))
.insert(LayerMetadata::from(layer_instance));
.insert(LayerMetadata::from(layer_instance))
.insert(Name::new(layer_instance.identifier.to_owned()));

commands.entity(ldtk_entity).add_child(layer_entity);

Expand Down
9 changes: 8 additions & 1 deletion src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ fn pre_spawn_level(
.insert_bundle(SpatialBundle {
transform: Transform::from_translation(translation),
..default()
});
})
.insert(Name::new(
ldtk_asset
.get_level(&LevelSelection::Iid(level_iid.to_string()))
.unwrap()
.identifier
.to_owned(),
));
}
}

Expand Down

0 comments on commit 33f2b73

Please sign in to comment.