{"id":15137962,"url":"https://github.com/cuppachino/bevy_logic","last_synced_at":"2025-10-23T13:31:02.084Z","repository":{"id":232483007,"uuid":"784476942","full_name":"cuppachino/bevy_logic","owner":"cuppachino","description":"Simulate logic gates and signals in bevy","archived":false,"fork":false,"pushed_at":"2024-12-02T21:36:38.000Z","size":210,"stargazers_count":21,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T18:48:23.547Z","etag":null,"topics":["bevy","logic-gates","simulation"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/bevy_logic","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/cuppachino.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-09T23:34:49.000Z","updated_at":"2024-11-12T10:44:53.000Z","dependencies_parsed_at":"2024-05-03T21:26:19.226Z","dependency_job_id":null,"html_url":"https://github.com/cuppachino/bevy_logic","commit_stats":null,"previous_names":["cuppachino/logic_tools","cuppachino/bevy_logic"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuppachino%2Fbevy_logic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuppachino%2Fbevy_logic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuppachino%2Fbevy_logic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuppachino%2Fbevy_logic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cuppachino","download_url":"https://codeload.github.com/cuppachino/bevy_logic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237834692,"owners_count":19373773,"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","logic-gates","simulation"],"created_at":"2024-09-26T07:03:50.792Z","updated_at":"2025-10-23T13:31:01.378Z","avatar_url":"https://github.com/cuppachino.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `bevy_logic`\n\n[![Crates.io](https://img.shields.io/crates/v/bevy_logic)](https://crates.io/crates/bevy_logic)\n[![docs](https://docs.rs/bevy_logic/badge.svg)](https://docs.rs/bevy_logic/)\n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cuppachino/bevy_logic/blob/main/LICENSE)\n[![Crates.io](https://img.shields.io/crates/d/bevy_logic)](https://crates.io/crates/bevy_logic)\n\nA logic gate simulation plugin for [`bevy`](https://bevyengine.org/).\n\n## Features\n\n- A `LogicGraph` resource for sorting (potentially cyclic) logic gate circuits.\n- A fixed timestep `LogicUpdate` schedule that works just like bevy's `FixedUpdate`.\n- A ternary approach to [`Signal`](src/logic/signal.rs), enabling non-boolean circuits and analog machines.\n- [`LogicGate`](src/logic/mod.rs) trait queries.\n- Builder traits for `World` and `Commands` that ease gate hierarchy construction.\n- `Command`s for synchronizing a graph with the game world.\n- Modular plugin design. Pick and choose which features you need.\n\n### Running examples\n\n```cmd\ncargo run --release --example cycles\n```\n\n### Quickstart\n\nAdd the `LogicSimulationPlugin` to your app, and configure the `Time\u003cLogicStep\u003e` resource\nto tick at the desired speed.\n\n```rust\nconst STEPS_PER_SECOND: f64 = 30.0;\napp.add_plugins(LogicSimulationPlugin)\n    .insert_resource(Time::\u003cLogicStep\u003e::from_hz(STEPS_PER_SECOND));\n```\n\n### Custom logic gates\n\nYou can create your own logic gates by implementing the `LogicGate` trait...\n\n```rust\nuse bevy_logic::prelude::*;\n\n/// The XOR gate emits a signal if the number of \"truthy\" inputs is odd.\n#[derive(Component, Clone, Copy, Debug, Default, Reflect)]\npub struct XorGate;\n\nimpl LogicGate for XorGate {\n    fn evaluate(\u0026mut self, inputs: \u0026[Signal], outputs: \u0026mut [Signal]) {\n        let signal: Signal = inputs\n            .iter()\n            .filter(|s| s.is_truthy())\n            .count()\n            .is_odd()\n            .into();\n\n        outputs.set_all(signal);\n    }\n}\n```\n\nAnd then registering the component with `bevy_trait_query`...\n\n```rust\nstruct CustomLogicPlugin;\n\nimpl Plugin for CustomLogicPlugin {\n    fn build(\u0026self, app: \u0026mut App) {\n        app.register_logic_gate::\u003cXorGate\u003e();\n    }\n}\n```\n\nYou can use the `logic::commands` module to spawn gates and fans,\nand then connect fans with wires. Make sure to `compile()` the logic graph.\n\n```rust\nfn spawn_custom_gate(mut commands: Commands, mut sim: ResMut\u003cLogicGraph\u003e) {\n    let xor_gate = commands\n        .spawn_gate((Name::new(\"XOR\"), XorGate))\n        .with_inputs(2)\n        .with_outputs(1)\n        .build();\n\n    let not_gate = commands\n        .spawn_gate((Name::new(\"NOT\"), NotGate))\n        .with_inputs(1)\n        .with_outputs(1)\n        .build();\n\n    let wire = commands.spawn_wire(\u0026not_gate, 0, \u0026xor_gate, 0).downgrade();\n\n    sim.add_data(vec![xor_gate, not_gate]).add_data(wire).compile();\n}\n```\n\n## Bevy Compatibility\n\n| `bevy` | `bevy_logic` |\n| ------ | ------------ |\n| 0.14   | 0.7.x        |\n| 0.13.2 | 0.6.x        |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuppachino%2Fbevy_logic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuppachino%2Fbevy_logic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuppachino%2Fbevy_logic/lists"}