Skip to content

Commit

Permalink
idx modesl for multiple names
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Oct 31, 2024
1 parent e482b5f commit 83560a0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/wasm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ pub struct Entity(pub HashMap<String, Model>);

impl From<&torii_grpc::types::schema::Entity> for Entity {
fn from(value: &torii_grpc::types::schema::Entity) -> Self {
Self(value.models.iter().map(|m| (m.name.clone(), m.into())).collect())
let mut seen_models = HashMap::new();
Self(value.models.iter().map(|m| {
let count = seen_models.entry(m.name.clone()).or_insert(0);
let name = if *count == 0 {
m.name.clone()
} else {
format!("{}-{}", m.name, count)
};
*count += 1;
(name, m.into())
}).collect())
}
}

Expand Down

0 comments on commit 83560a0

Please sign in to comment.