You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
use bevy::input::mouse::MouseMotion;
|
|
use games::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.init_resource::<Thing>()
|
|
.add_plugins(BaseGamePlugin { camera: CameraType::Camera3d })
|
|
.add_systems(Startup, init_ui)
|
|
.add_systems(Update, (
|
|
sync_resource_to_ui::<Thing>.run_if(resource_changed::<Thing>),
|
|
update_foo.run_if(on_event::<MouseMotion>)
|
|
))
|
|
.run();
|
|
}
|
|
|
|
#[derive(Resource, Debug, Default)]
|
|
struct Thing(u8);
|
|
|
|
impl Display for Thing {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
write!(f, "{}", self.0)
|
|
}
|
|
}
|
|
|
|
fn init_ui(
|
|
mut commands: Commands
|
|
) {
|
|
commands.spawn((
|
|
Node {
|
|
align_self: AlignSelf::Start,
|
|
justify_self: JustifySelf::Center,
|
|
..default()
|
|
},
|
|
Text("Displays a sync'd resource tracking the number of mouse events (mod 256)".into()),
|
|
));
|
|
commands.spawn((Node {
|
|
align_self: AlignSelf::Center,
|
|
justify_self: JustifySelf::Center,
|
|
..default()
|
|
}, Text("Placeholder".into()), SyncResource::<Thing>::default()));
|
|
}
|
|
|
|
fn update_foo(
|
|
mut events: EventReader<MouseMotion>,
|
|
mut thing: ResMut<Thing>,
|
|
) {
|
|
events.read().for_each(|_| {
|
|
thing.0 = thing.0.overflowing_add(1).0;
|
|
});
|
|
}
|