{"id":21985550,"url":"https://github.com/ickshonpe/flat_commands","last_synced_at":"2025-07-04T20:35:51.361Z","repository":{"id":44601995,"uuid":"455865529","full_name":"ickshonpe/flat_commands","owner":"ickshonpe","description":"Spawn entity hierarchies without nesting or collecting the ids.","archived":false,"fork":false,"pushed_at":"2022-08-23T08:26:47.000Z","size":121,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-17T18:57:27.233Z","etag":null,"topics":["bevy","ecs","ergonomics"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ickshonpe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-05T12:36:42.000Z","updated_at":"2023-09-10T00:54:51.000Z","dependencies_parsed_at":"2022-09-26T20:11:26.000Z","dependency_job_id":null,"html_url":"https://github.com/ickshonpe/flat_commands","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickshonpe%2Fflat_commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickshonpe%2Fflat_commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickshonpe%2Fflat_commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickshonpe%2Fflat_commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ickshonpe","download_url":"https://codeload.github.com/ickshonpe/flat_commands/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227185421,"owners_count":17744371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bevy","ecs","ergonomics"],"created_at":"2024-11-29T18:14:01.297Z","updated_at":"2024-11-29T18:14:02.044Z","avatar_url":"https://github.com/ickshonpe.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flat Commands\n\nSpawn entity hierarchies without nesting or collecting the ids.\n\n## Examples\n\n### Before\n```rust\nfn setup(mut commands: Commands) {\n    commands\n        .spawn_bundle(PbrBundle {\n            transform: Transform::from_xyz(1.0, 1.0, 1.0),\n            ..Default::default()\n        })\n        .with_children(|parent| {\n            parent\n                .spawn_bundle(PbrBundle {\n                    transform: Transform::from_xyz(1.0, 1.0, 1.0),\n                    ..Default::default()\n                })\n                .spawn_bundle(PbrBundle {\n                    transform: Transform::from_xyz(2.0, 2.0, 2.0),\n                    ..Default::default()\n                })\n        });\n}\n```\n### or\n```rust\nfn setup(mut commands: Commands) {\n    let child_1 = commands\n        .spawn_bundle(PbrBundle {\n            transform: Transform::from_xyz(1.0, 1.0, 1.0),\n            ..Default::default()\n        })\n        .id();\n    let child_2 = commands\n        .spawn_bundle(PbrBundle {\n            transform: Transform::from_xyz(2.0, 2.0, 2.0),\n            ..Default::default()\n        })\n        .id();\n    commands\n        .spawn_bundle(PbrBundle {\n            transform: Transform::from_xyz(1.0, 1.0, 1.0),\n            ..Default::default()\n        })\n        .push_children(\u0026[child_1, child_2]);\n}\n```\n### after\n```rust\nuse flat_commands::*;\n\nfn setup(mut commands: Commands) {\n    commands\n        .spawn_root(PbrBundle {\n            transform: Transform::from_xyz(1.0, 1.0, 1.0),\n            ..Default::default()\n        })\n        .with_child(PbrBundle {\n            transform: Transform::from_xyz(1.0, 1.0, 1.0),\n            ..Default::default()\n        })\n        .with_sibling(PbrBundle {\n            transform: Transform::from_xyz(2.0, 2.0, 2.0),\n            ..Default::default()\n        });\n}\n```\n#\n### Before\n```rust\nfn spawn_text_box(\n    mut commands: Commands,\n    asset_server: Res\u003cAssetServer\u003e,\n) {\n \n    commands.spawn_bundle(NodeBundle {\n        style: Style {\n            position_type: PositionType::Absolute,\n            position: UiRect { left: Val::Px(100.0), bottom: Val::Px(100.0), ..Default::default() },\n            padding: UiRect::all(Val::Px(2.0)),\n            ..Default::default()\n        },\n        ..Default::default()\n    })\n    .with_children(|builder| {\n        builder.spawn_bundle(NodeBundle {\n                color: UiColor (Color::DARK_GRAY),\n                style: Style {\n                    padding: UiRect::all(Val::Px(4.0)),\n                    ..Default::default()\n                },\n                ..Default::default()\n            }\n        )\n        .with_children(|builder| {\n            builder.spawn_bundle(TextBundle {\n                text: Text::from_section(\n                    \"Hello, world!\",\n                    TextStyle {\n                        font: asset_server.load(\"FiraMono-Regular.ttf\"),\n                        font_size: 16.0,\n                        color: Color::ANTIQUE_WHITE,\n                    },\n                ),\n                 ..Default::default()\n            });\n        });\n    });\n}\n```\n### after\n```rust\nuse flat_commands::*;\n\nfn spawn_text_box(\n    mut commands: Commands,\n    asset_server: Res\u003cAssetServer\u003e,\n) {\n    commands.spawn_root(NodeBundle {\n        style: Style {\n            position_type: PositionType::Absolute,\n            position: UiRect { left: Val::Px(100.0), bottom: Val::Px(100.0), ..Default::default() },\n            padding: UiRect::all(Val::Px(2.0)),\n            ..Default::default()\n        },\n        ..Default::default()\n    })\n    .with_child(NodeBundle {\n        color: UiColor (Color::DARK_GRAY),\n        style: Style {\n            padding: UiRect::all(Val::Px(4.0)),\n            ..Default::default()\n        },\n        ..Default::default()\n    })\n    .with_child(TextBundle {\n        text: Text::from_section(\n            \"Hello, world!\",\n            TextStyle {\n                font: asset_server.load(\"FiraMono-Regular.ttf\"),\n                font_size: 16.0,\n                color: Color::ANTIQUE_WHITE,\n            }\n        ),\n        ..Default::default()\n    });\n}\n```\n#\n### Before\n```rust\nfn spawn_branching_hierachy(\n    commands: \u0026mut Commands\n) -\u003e Entity {\n    let id = commands.spawn().id();\n\n    commands.entity(id)\n    .with_children(|builder| {\n        builder\n        .spawn()\n        .with_children(|builder| {\n            builder\n            .spawn()\n            .with_children(|builder| {\n                builder\n                .spawn();\n\n                builder\n                .spawn();\n            });\n        });\n\n        builder\n        .spawn()\n        .with_children(|builder| {\n            builder\n            .spawn()\n            .with_children(|builder| {\n                builder\n                .spawn();\n\n                builder\n                .spawn();\n            });\n        });\n\n        builder\n        .spawn()\n        .with_children(|builder| {\n            builder\n            .spawn()\n            .with_children(|builder| {\n                builder\n                .spawn();\n\n                builder\n                .spawn();\n            });\n        });\n    });\n\n    id\n}\n```\n### after\n```rust\nuse flat_commands::*;\n\nfn spawn_branching_hierachy(\n    commands: \u0026mut Commands\n) -\u003e Entity {\n    commands\n    .spawn_empty_root()\n    .with_descendants(|local_root| {\n        local_root\n        .with_empty_child()\n        .with_empty_child()\n        .with_empty_sibling()\n    })\n    .with_descendants(|local_root| {\n        local_root\n        .with_empty_child()\n        .with_empty_child()\n        .with_empty_sibling()\n    })\n    .with_descendants(|local_root| {\n        local_root\n        .with_empty_child()\n        .with_empty_child()\n        .with_empty_sibling()\n    })\n    .root_id()\n}\n```\n### or\n```rust\nuse flat_commands::*;\n\nfn spawn_hierachy(\n    mut commands: Commands\n) -\u003e Entity {\n    let root = commands\n    .spawn_empty_root();\n\n    root\n    .with_empty_child()\n    .with_empty_child()\n    .with_empty_sibling();\n    \n    root\n    .with_empty_child()\n    .with_empty_child()\n    .with_empty_sibling();\n    \n    root\n    .with_empty_child()\n    .with_empty_child()\n    .with_empty_sibling()\n    .root_id()\n}\n```\n#\n### EntityCommands also implements the extension traits\n```rust\nuse flat_commands::*;\n\nfn spawn_hierachy(\n    mut commands: Commands\n) {\n    let entity_commands = commands.spawn();\n    entity_commands\n    .insert(MyComponent)\n    .with_empty_child()\n    .with_empty_sibling();\n}\n\n```\n#\n### Batched child spawning\n```rust\nuse flat_commands::*;\n\nfn spawn_brood(\n    mut commands: Commands,\n    asset_server: Res\u003cAssetServer\u003e,\n) {\n    let font = asset_server.load(\"fonts/FiraSans-Bold.ttf\");\n    commands.spawn_root(NodeBundle { ..Default::default() })\n    .with_child_batch((0..30).map(move |i| {\n        TextBundle {\n            text: Text::with_section(\n                format!(\"Item {}\", i),\n                TextStyle {\n                    font: font.clone(),\n                    font_size: 20.,\n                    color: Color::RED,\n                },\n                Default::default(),\n            ),\n            ..Default::default()\n        }\n    );\n}\n```\n#\n## Examples\nThere is a minimal example of spawning a text box in the /examples folder. To run use:\n```\ncargo run --example text_box\n```\n\n## Other Info\n* Unoptimized, will be slower than with_children and push_children.\n* Doesn't do any despawning or component removal (use regular commands).\n* Doesn't use any unsafe code or macros.\n* version 3.0 supports Bevy 0.8, 2.2 supports Bevy 0.7, \u003e 2.2 supports Bevy 0.6\n* Todo: Automatic marker component insertion.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fickshonpe%2Fflat_commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fickshonpe%2Fflat_commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fickshonpe%2Fflat_commands/lists"}