bevy_console_parser

Crates.iobevy_console_parser
lib.rsbevy_console_parser
version0.4.0
sourcesrc
created_at2022-02-27 21:05:43.088093
updated_at2022-12-20 19:20:27.341782
descriptionconsole command parser for bevy_console
homepagehttps://github.com/RichoDemus/bevy-console
repositoryhttps://github.com/RichoDemus/bevy-console
max_upload_size
id540502
size17,492
Richard Tjerngren (RichoDemus)

documentation

README

bevy_console

Check

A simple half-life inspired console with support for argument parsing.

Usage

Add ConsolePlugin and optionally the resource ConsoleConfiguration.

use bevy::prelude::*;
use bevy_console::{ConsoleConfiguration, ConsolePlugin};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(ConsolePlugin)
        .insert_resource(ConsoleConfiguration {
            // override config here
            ..Default::default()
        });
}

Create a console command struct and system and add it to your app with .add_console_command.

Add doc comments to your command to provide help information in the console.

use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsolePlugin};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(ConsolePlugin)
        .add_console_command::<ExampleCommand, _>(example_command);
}

/// Example command
#[derive(ConsoleCommand)]
#[console_command(name = "example")]
struct ExampleCommand {
    /// Some message
    msg: String,
}

fn example_command(mut log: ConsoleCommand<ExampleCommand>) {
    if let Some(ExampleCommand { msg }) = log.take() {
        // handle command
    }
}

Examples can be found in the /examples directory.

cargo run --example log_command

wasm

Should work in wasm, but you need to disable default features.

Commit count: 97

cargo fmt