use yog_abi::YogStr;
pub use yog_abi::ui_flags;
use crate::registry::global_api;
pub fn open_ui_flags(ui_id: &str, flags: u32) {
let api = global_api();
if api.is_null() {
return;
}
unsafe { ((*api).ui_open_flags)((*api).ctx, YogStr::from_str(ui_id), flags) }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct SoundHandle(pub u32);
pub fn play_sound(sound_id: &str, volume: f32, pitch: f32, looping: bool) -> SoundHandle {
let api = global_api();
if api.is_null() {
return SoundHandle(0);
}
SoundHandle(unsafe {
((*api).client_play_sound)(
(*api).ctx,
YogStr::from_str(sound_id),
volume,
pitch,
looping,
)
})
}
pub fn stop_sound(handle: SoundHandle) {
let api = global_api();
if api.is_null() || handle.0 == 0 {
return;
}
unsafe { ((*api).client_stop_sound)((*api).ctx, handle.0) }
}
pub fn held_item(off_hand: bool) -> Option<String> {
let api = global_api();
if api.is_null() {
return None;
}
let owned = unsafe { ((*api).client_held_item)((*api).ctx, off_hand) };
crate::registry::take_owned(unsafe { (*api).free_str }, owned)
}
pub fn set_block_tint(dimension: &str, pos: yog_core::BlockPos, color: Option<u32>) {
let api = global_api();
if api.is_null() {
return;
}
let p = yog_abi::YogBlockPos { x: pos.x, y: pos.y, z: pos.z };
let c = color.map_or(-1, |c| (c & 0xFF_FFFF) as i64);
unsafe { ((*api).client_set_block_tint)((*api).ctx, YogStr::from_str(dimension), p, c) }
}
pub mod keys {
pub const LEFT_SHIFT: i32 = 340;
pub const LEFT_CONTROL: i32 = 341;
pub const LEFT_ALT: i32 = 342;
pub const RIGHT_SHIFT: i32 = 344;
pub const RIGHT_CONTROL: i32 = 345;
pub const RIGHT_ALT: i32 = 346;
}
pub fn key_down(key: i32) -> bool {
let api = global_api();
if api.is_null() {
return false;
}
unsafe { ((*api).client_key_down)((*api).ctx, key) }
}
pub fn control_down() -> bool {
key_down(keys::LEFT_CONTROL) || key_down(keys::RIGHT_CONTROL)
}