use bevy::prelude::*;
use bevy_enhanced_input::prelude::{Press, *};
use jackdaw::prelude::*;
fn main() -> AppExit {
App::new()
.set_error_handler(bevy::ecs::error::error)
.add_plugins((
DefaultPlugins,
EditorPlugins::default()
.set(ExtensionPlugin::default().with_extension::<KeybindingExampleExtension>()),
))
.run()
}
#[derive(Default)]
pub struct KeybindingExampleExtension;
impl JackdawExtension for KeybindingExampleExtension {
fn id(&self) -> String {
"keybinding_example".to_string()
}
fn label(&self) -> String {
"Keybinding Example".to_string()
}
fn description(&self) -> String {
"Adds an operator that logs the elapsed seconds since Jackdaw started that can be called by pressing the F10 key.".to_string()
}
fn register_input_context(&self, app: &mut App) {
app.add_input_context::<KeybindingExampleInputContext>();
}
fn register(&self, ctx: &mut ExtensionContext) {
ctx.register_operator::<ElapsedSecondsOp>().spawn((
KeybindingExampleInputContext,
actions!(
KeybindingExampleInputContext[(
Action::<ElapsedSecondsOp>::new(),
bindings![(KeyCode::F10, Press::default())]
)]
),
));
}
}
#[derive(Component)]
struct KeybindingExampleInputContext;
#[operator(
id = "keybinding_example.elapsed_seconds",
label = "Log Elapsed Seconds",
description = "Logs the elapsed seconds since Jackdaw started."
)]
fn elapsed_seconds(_: In<OperatorParameters>, time: Res<Time>) -> OperatorResult {
info!("Elapsed seconds: {}", time.elapsed_secs());
OperatorResult::Finished
}