From 79445c715787d2805165821d285007f26e730c9e Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Fri, 18 Apr 2025 20:08:15 +0200 Subject: [PATCH] reorganize a bit --- src/logic_sim/block_label.rs | 2 ++ src/logic_sim/mod.rs | 53 +++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/logic_sim/block_label.rs b/src/logic_sim/block_label.rs index 6757bc3..7f0e070 100644 --- a/src/logic_sim/block_label.rs +++ b/src/logic_sim/block_label.rs @@ -6,6 +6,8 @@ impl Plugin for BlockLabelPlugin { } } +#[derive(Component, Debug)] +pub struct CanvasText; #[derive(Bundle, Debug)] pub struct BlockLabelBundle { text: Text2d, diff --git a/src/logic_sim/mod.rs b/src/logic_sim/mod.rs index 10e5055..613fd50 100644 --- a/src/logic_sim/mod.rs +++ b/src/logic_sim/mod.rs @@ -54,8 +54,6 @@ pub struct BlockBundle { block_visuals: BlockVisuals, } -#[derive(Component, Debug)] -pub struct CanvasText; #[derive(Component, Debug)] pub struct BlockVisuals { size: IVec2, @@ -390,13 +388,13 @@ fn spawn_block_definition_from_asset( if let Some(e) = spawned_block { commands.entity(e).despawn_recursive(); } - spawn_block_definition(commands, asset_server, block); + spawn_block_definition(&mut commands, &asset_server, block); state.set(AppState::Running) } } fn spawn_block_definition( - mut commands: Commands, - asset_server: Res, + mut commands: &mut Commands, + asset_server: &Res, block: BlockDefinition, ) { let font = asset_server.load("fonts/arcane_nine.otf"); @@ -435,29 +433,34 @@ fn spawn_block_definition( .map(|(id, con)| (id, ConnectionReference(commands.spawn(con).id()))) .collect(); + // let child_blocks = block.inner_blocks.iter().map(|block| { + // spawn_block_definition(commands, asset_server, block.clone()); + // }); + let wires = block.wires.iter().map(|wire| { - wire.connections.iter().flat_map(|con| { - if (con.parent_block != block.id) { - warn!("get connections from sub blocks is not implemented yet"); - // todo!("get connections from sub blocks (not blocks outside the one containing the wire and only one level deep)"); - None - } else if let Some((_, connection)) = inputs.iter().find(|(id, _)| *id == con.id) { - Some(*connection) - } else if let Some((_, connection)) = outputs.iter().find(|(id, _)| *id == con.id) { - Some(*connection) - } else { - warn!( - "could not find connection with id '{}' in block '{}", - con.id, block.id - ); - None - } - }) + wire.connections + .iter() + .flat_map(|con| { + if (con.parent_block != block.id) { + warn!("get connections from sub blocks is not implemented yet"); + // todo!("get connections from sub blocks (not blocks outside the one containing the wire and only one level deep)"); + None + } else if let Some((_, connection)) = inputs.iter().find(|(id, _)| *id == con.id) { + Some(*connection) + } else if let Some((_, connection)) = outputs.iter().find(|(id, _)| *id == con.id) { + Some(*connection) + } else { + warn!( + "could not find connection with id '{}' in block '{}", + con.id, block.id + ); + None + } + }) + .collect() }); for wire in wires { - commands.spawn(Wire { - connections: wire.collect(), - }); + commands.spawn(Wire { connections: wire }); } commands