1pub use yog_abi::ui_flags;
14use yog_abi::YogStr;
15
16use crate::registry::global_api;
17
18pub fn open_ui_flags(ui_id: &str, flags: u32) {
20 let api = global_api();
21 if api.is_null() {
22 return;
23 }
24 unsafe { ((*api).ui_open_flags)((*api).ctx, YogStr::from_str(ui_id), flags) }
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
29pub struct SoundHandle(pub u32);
30
31pub fn play_sound(sound_id: &str, volume: f32, pitch: f32, looping: bool) -> SoundHandle {
35 let api = global_api();
36 if api.is_null() {
37 return SoundHandle(0);
38 }
39 SoundHandle(unsafe {
40 ((*api).client_play_sound)(
41 (*api).ctx,
42 YogStr::from_str(sound_id),
43 volume,
44 pitch,
45 looping,
46 )
47 })
48}
49
50pub fn stop_sound(handle: SoundHandle) {
52 let api = global_api();
53 if api.is_null() || handle.0 == 0 {
54 return;
55 }
56 unsafe { ((*api).client_stop_sound)((*api).ctx, handle.0) }
57}
58
59pub fn held_item(off_hand: bool) -> Option<String> {
62 let api = global_api();
63 if api.is_null() {
64 return None;
65 }
66 let owned = unsafe { ((*api).client_held_item)((*api).ctx, off_hand) };
67 if owned.is_none() {
68 return None;
69 }
70 let s = unsafe {
71 String::from_utf8_lossy(std::slice::from_raw_parts(owned.ptr, owned.len as usize))
72 .into_owned()
73 };
74 unsafe { ((*api).free_str)(owned.ptr, owned.len) };
75 Some(s)
76}
77
78pub mod keys {
80 pub const LEFT_SHIFT: i32 = 340;
81 pub const LEFT_CONTROL: i32 = 341;
82 pub const LEFT_ALT: i32 = 342;
83 pub const RIGHT_SHIFT: i32 = 344;
84 pub const RIGHT_CONTROL: i32 = 345;
85 pub const RIGHT_ALT: i32 = 346;
86}
87
88pub fn key_down(key: i32) -> bool {
90 let api = global_api();
91 if api.is_null() {
92 return false;
93 }
94 unsafe { ((*api).client_key_down)((*api).ctx, key) }
95}
96
97pub fn control_down() -> bool {
100 key_down(keys::LEFT_CONTROL) || key_down(keys::RIGHT_CONTROL)
101}