As part of my rust journey of discovery I am writing a roguelike using the legion ECS library.
I am trying to see if there's a way I can refactor a spawner function so that tuple that is used within that function be called within a system.
In other words, currently have a bunch of functions that look like:
pub fn spawn_giant_rat(ecs: &mut World, pt: Point) {
ecs.push(
(
Actor,
Render{
name: "Giant Rat".to_string(),
tile: tile_index(13, 2),
pt
},
FieldOfView::new(4),
. . .
and ecs.push(
is defined like:
pub fn push<T>(&mut self, components: T) -> Entity
where
Option<T>: IntoComponentSource,
{
Unfortunately, IntoComponentSource
is private in legion.
I'd like to refactor the function that I can return the tuple from one function and use in the existing function. Something like:
// Question: what would T look like here?
pub fn spawn_giant_rat_tuple(pt: Point) -> T {
(
Actor,
Render{ ... },
...
)
}
// So that I can pass it in here?
pub fn spawn_giant_rat(ecs: &mut World, pt: Point) {
ecs.push(spawn_rat_tuble(pt));
}