reorganize a bit

This commit is contained in:
OMGeeky
2025-04-18 20:08:15 +02:00
parent 8c3b29719e
commit 79445c7157
2 changed files with 30 additions and 25 deletions

View File

@@ -6,6 +6,8 @@ impl Plugin for BlockLabelPlugin {
} }
} }
#[derive(Component, Debug)]
pub struct CanvasText;
#[derive(Bundle, Debug)] #[derive(Bundle, Debug)]
pub struct BlockLabelBundle { pub struct BlockLabelBundle {
text: Text2d, text: Text2d,

View File

@@ -54,8 +54,6 @@ pub struct BlockBundle {
block_visuals: BlockVisuals, block_visuals: BlockVisuals,
} }
#[derive(Component, Debug)]
pub struct CanvasText;
#[derive(Component, Debug)] #[derive(Component, Debug)]
pub struct BlockVisuals { pub struct BlockVisuals {
size: IVec2, size: IVec2,
@@ -390,13 +388,13 @@ fn spawn_block_definition_from_asset(
if let Some(e) = spawned_block { if let Some(e) = spawned_block {
commands.entity(e).despawn_recursive(); commands.entity(e).despawn_recursive();
} }
spawn_block_definition(commands, asset_server, block); spawn_block_definition(&mut commands, &asset_server, block);
state.set(AppState::Running) state.set(AppState::Running)
} }
} }
fn spawn_block_definition( fn spawn_block_definition(
mut commands: Commands, mut commands: &mut Commands,
asset_server: Res<AssetServer>, asset_server: &Res<AssetServer>,
block: BlockDefinition, block: BlockDefinition,
) { ) {
let font = asset_server.load("fonts/arcane_nine.otf"); 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()))) .map(|(id, con)| (id, ConnectionReference(commands.spawn(con).id())))
.collect(); .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| { let wires = block.wires.iter().map(|wire| {
wire.connections.iter().flat_map(|con| { wire.connections
if (con.parent_block != block.id) { .iter()
warn!("get connections from sub blocks is not implemented yet"); .flat_map(|con| {
// todo!("get connections from sub blocks (not blocks outside the one containing the wire and only one level deep)"); if (con.parent_block != block.id) {
None warn!("get connections from sub blocks is not implemented yet");
} else if let Some((_, connection)) = inputs.iter().find(|(id, _)| *id == con.id) { // todo!("get connections from sub blocks (not blocks outside the one containing the wire and only one level deep)");
Some(*connection) None
} else if let Some((_, connection)) = outputs.iter().find(|(id, _)| *id == con.id) { } else if let Some((_, connection)) = inputs.iter().find(|(id, _)| *id == con.id) {
Some(*connection) Some(*connection)
} else { } else if let Some((_, connection)) = outputs.iter().find(|(id, _)| *id == con.id) {
warn!( Some(*connection)
"could not find connection with id '{}' in block '{}", } else {
con.id, block.id warn!(
); "could not find connection with id '{}' in block '{}",
None con.id, block.id
} );
}) None
}
})
.collect()
}); });
for wire in wires { for wire in wires {
commands.spawn(Wire { commands.spawn(Wire { connections: wire });
connections: wire.collect(),
});
} }
commands commands