use std::ffi::c_void;
pub mod events;
pub mod functions;
pub use functions::load_functions;
use crate::{players::Player, runtime::queue_api_call, types::vector::Vector3};
pub struct Pickup {
handle: *const c_void,
}
#[deny(non_snake_case)]
impl Pickup {
pub fn get_handle(&self) -> *const c_void {
self.handle
}
pub fn new(handle: *const c_void) -> Self {
Self { handle }
}
pub fn create(
model: i32,
pickup_type: i32,
position: Vector3,
virtual_world: i32,
) -> Option<Pickup> {
let mut _id = -1;
functions::Pickup_Create(
model,
pickup_type,
position.x,
position.y,
position.z,
virtual_world,
&mut _id,
)
}
pub fn create_static(
model: i32,
pickup_type: i32,
position: Vector3,
virtual_world: i32,
) -> bool {
functions::Pickup_AddStatic(
model,
pickup_type,
position.x,
position.y,
position.z,
virtual_world,
)
}
pub fn destroy(&self) -> bool {
functions::Pickup_Destroy(self)
}
pub fn is_streamed_in(&self, player: &Player) -> bool {
functions::Pickup_IsStreamedIn(player, self)
}
pub fn get_pos(&self) -> Vector3 {
let mut pos = Vector3::default();
functions::Pickup_GetPos(self, &mut pos.x, &mut pos.y, &mut pos.z);
pos
}
pub fn get_model(&self) -> i32 {
functions::Pickup_GetModel(self)
}
pub fn get_type(&self) -> i32 {
functions::Pickup_GetType(self)
}
pub fn get_virtual_world(&self) -> i32 {
functions::Pickup_GetVirtualWorld(self)
}
pub fn set_pos(&self, pos: Vector3, update: bool) {
self.defer_api_call(Box::new(move |pickup| {
functions::Pickup_SetPos(&pickup, pos.x, pos.y, pos.z, update);
}));
}
pub fn set_model(&self, model: i32, update: bool) -> bool {
functions::Pickup_SetModel(self, model, update)
}
pub fn set_type(&self, pickup_type: i32, update: bool) -> bool {
functions::Pickup_SetType(self, pickup_type, update)
}
pub fn set_virtual_world(&self, virtualworld: i32) -> bool {
functions::Pickup_SetVirtualWorld(self, virtualworld)
}
pub fn show_for_player(&self, player: &Player) {
let player_id = player.get_id();
self.defer_api_call(Box::new(move |pickup| {
let player = match Player::from_id(player_id) {
Some(player) => player,
None => {
log::error!("player with id={player_id} not found");
return;
}
};
functions::Pickup_ShowForPlayer(&player, &pickup);
}));
}
pub fn hide_for_player(&self, player: &Player) -> bool {
functions::Pickup_HideForPlayer(player, self)
}
pub fn is_hidden_for_player(&self, player: &Player) -> bool {
functions::Pickup_IsHiddenForPlayer(player, self)
}
pub fn get_id(&self) -> i32 {
functions::Pickup_GetID(self)
}
pub fn get_from_id(pickupid: i32) -> Option<Pickup> {
functions::Pickup_FromID(pickupid)
}
fn defer_api_call(&self, callback: Box<dyn FnOnce(Self)>) {
let pickup_id = self.get_id();
queue_api_call(Box::new(move || {
let pickup = match Self::get_from_id(pickup_id) {
Some(pickup) => pickup,
None => {
log::error!("pickup with id={pickup_id} not found");
return;
}
};
callback(pickup);
}));
}
}