-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More documentation and custom functions example.
- Loading branch information
Showing
10 changed files
with
101 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! A simple exmaple | ||
|
||
use bevy::{ | ||
log::{Level, LogPlugin}, | ||
prelude::*, | ||
}; | ||
use bevy_dev_console::{ | ||
builtin_parser::{Environment, Spanned, Value}, | ||
prelude::*, | ||
register, | ||
}; | ||
|
||
// Declare the functions we want to create: | ||
|
||
// Basic function | ||
fn time_since_epoch() { | ||
let time = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.unwrap(); | ||
info!("The unix epoch was {} seconds ago", time.as_secs()); | ||
} | ||
|
||
// Function with parameters and return value | ||
fn add(num1: f64, num2: f64) -> f64 { | ||
num1 + num2 | ||
} | ||
|
||
// Function with any value + span | ||
fn print_debug_info(value: Spanned<Value>) { | ||
info!( | ||
"Location in command: {:?}, Value: {:?}", | ||
value.span, value.value | ||
) | ||
} | ||
|
||
// For more example take a look at the standard library. | ||
|
||
// Register our functions by creating and inserting our own environment | ||
fn custom_environment() -> Environment { | ||
let mut environment = Environment::default(); | ||
|
||
// The register macro allows us to easily add functions to the environment. | ||
register!(&mut environment => { | ||
fn time_since_epoch; | ||
fn add; | ||
fn print_debug_info; | ||
}); | ||
|
||
environment | ||
} | ||
|
||
fn main() { | ||
App::new() | ||
// Insert our new environment | ||
.insert_non_send_resource(custom_environment()) | ||
.add_plugins(( | ||
ConsoleLogPlugin::default().append_filter(module_path!(), Level::TRACE), | ||
DefaultPlugins.build().disable::<LogPlugin>(), | ||
DevConsolePlugin, | ||
)) | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters