This commit is contained in:
2026-02-17 07:30:49 -08:00
parent 29744b9f6a
commit ad8e9bdbe9

View File

@@ -0,0 +1,54 @@
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use strafesnet_roblox_bot_player::{bot,graphics,head};
use strafesnet_common::session::Time as SessionTime;
#[wasm_bindgen]
pub struct Graphics<'a>{
graphics:graphics::Graphics<'a>,
}
#[wasm_bindgen]
impl<'a> Graphics<'a>{
#[wasm_bindgen(constructor)]
pub fn new(
data:&[u8],
device:wgpu::Device,
queue:wgpu::Queue,
surface:wgpu::Surface<'a>,
config:wgpu::SurfaceConfiguration,
)->Result<Self,JsValue>{
Ok(Self{
graphics:graphics::Graphics::new(data,device,queue,surface,config).map_err(|e|JsValue::from_str(&e.to_string()))?,
})
}
}
#[wasm_bindgen]
pub struct Bot{
bot:bot::Bot,
}
#[wasm_bindgen]
impl Bot{
#[wasm_bindgen(constructor)]
pub fn new(data:&[u8])->Result<Self,JsValue>{
Ok(Self{
bot:bot::Bot::new(data).map_err(|e|JsValue::from_str(&e.to_string()))?,
})
}
}
#[wasm_bindgen]
pub struct PlaybackHead{
head:head::PlaybackHead,
}
#[wasm_bindgen]
impl PlaybackHead{
#[wasm_bindgen(constructor)]
pub fn new(time:f64)->Result<Self,JsValue>{
// TODO: check f64 range
let time=SessionTime::raw((time*SessionTime::ONE_SECOND.get() as f64) as i64);
Ok(Self{
head:head::PlaybackHead::new(time),
})
}
}