-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcur.rs
69 lines (60 loc) · 1.63 KB
/
cur.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use bevy::{prelude::*, winit::cursor::CursorIcon};
use bevy_cursor_kit::prelude::*;
use flip::FlipPlugin;
use ui::UiPlugin;
#[path = "./helpers/flip.rs"]
mod flip;
#[path = "./helpers/ui.rs"]
mod ui;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(CursorAssetPlugin)
.add_plugins(UiPlugin)
.add_plugins(FlipPlugin)
.add_systems(Startup, (setup_cursor, setup_instructions))
.add_systems(Update, insert_cursor)
.run();
}
#[derive(Debug, Resource, Reflect)]
#[reflect(Debug, Resource)]
struct Cursors {
cursor: Handle<StaticCursor>,
}
fn setup_cursor(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(Cursors {
cursor: asset_server.load("Master Sword.CUR"),
});
}
fn insert_cursor(
mut commands: Commands,
static_cursors: Res<Assets<StaticCursor>>,
cursors: Res<Cursors>,
window: Single<Entity, With<Window>>,
mut setup: Local<bool>,
) {
if *setup {
return;
}
let Some(c) = static_cursors.get(&cursors.cursor.clone()) else {
return;
};
commands.entity(*window).insert(CursorIcon::Custom(
CustomCursorImageBuilder::from_static_cursor(c, None).build(),
));
*setup = true;
}
fn setup_instructions(mut commands: Commands) {
commands.spawn((
Text::new(
"Press X to toggle the cursor's `flip_x` setting\n
Press Y to toggle the cursor's `flip_y` setting",
),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
},
));
}