diff options
| author | HampusM <hampus@hampusmat.com> | 2025-04-02 19:08:24 +0200 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2025-04-02 19:09:05 +0200 | 
| commit | efa8f9af3a3c16c0ecbfefd479d69fc431ede834 (patch) | |
| tree | be0d2e914f5f33ceb6d993b07338b30c6a474e20 | |
| parent | d00ce85c591f7fa8385ef7e99b44db6a14788cd4 (diff) | |
fix(ecs): create nonexistant add edge archetypes when needed
| -rw-r--r-- | ecs/src/component/storage.rs | 21 | 
1 files changed, 18 insertions, 3 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 4a00510..40909fb 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -192,10 +192,24 @@ impl Storage              });          } -        let add_edge_archetype_id = archetype_node +        let add_edge_archetype_id = match archetype_node              .get_or_insert_edges(component_id, ArchetypeEdges::default)              .add -            .unwrap_or_else(|| { +        { +            Some(add_edge_id) => { +                if !self.graph.contains_archetype(add_edge_id) { +                    let (_, add_edge_comp_ids) = self +                        .graph +                        .get_node_by_id(archetype_id) +                        .expect("Archetype should exist") +                        .make_add_edge(component_id); + +                    self.graph.create_node(add_edge_id, &add_edge_comp_ids); +                } + +                add_edge_id +            } +            None => {                  let archetype_node = self                      .graph                      .get_node_by_id_mut(archetype_id) @@ -214,7 +228,8 @@ impl Storage                  }                  add_edge_id -            }); +            } +        };          {              let add_edge_archetype_node = self  | 
