forked from StrafesNET/roblox-bot-player
surface errors in setup_graphics
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsValue;
|
||||
use wasm_bindgen::JsError;
|
||||
use strafesnet_roblox_bot_file::v0;
|
||||
use strafesnet_roblox_bot_player::{bot,head,time,graphics};
|
||||
use strafesnet_graphics::setup;
|
||||
@@ -25,18 +25,18 @@ pub struct Graphics{
|
||||
surface:wgpu::Surface<'static>,
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Graphics{
|
||||
pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Result<Graphics,JsError>{
|
||||
let size=(canvas.width(),canvas.height());
|
||||
|
||||
let instance=setup::step1::create_instance();
|
||||
let surface=setup::step2::create_surface(&instance,ToSurfaceTarget(canvas)).unwrap();
|
||||
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
|
||||
let (device,queue)=setup::step4::request_device(&adapter).await;
|
||||
let config=setup::step5::configure_surface(&adapter,&device,&surface,size);
|
||||
Graphics{
|
||||
let surface=setup::step2::create_surface(&instance,ToSurfaceTarget(canvas)).map_err(|e|JsError::new(&e.to_string()))?;
|
||||
let adapter=setup::step3::pick_adapter(&instance,&surface).await.ok_or_else(||JsError::new("No suitable GPU adapters found on the system!"))?;
|
||||
let (device,queue)=setup::step4::request_device(&adapter).await.map_err(|e|JsError::new(&e.to_string()))?;
|
||||
let config=setup::step5::configure_surface(&adapter,&device,&surface,size).map_err(|e|JsError::new(&e.to_string()))?;
|
||||
Ok(Graphics{
|
||||
graphics:graphics::Graphics::new(device,queue,config),
|
||||
surface:surface,
|
||||
}
|
||||
})
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
impl Graphics{
|
||||
@@ -63,8 +63,8 @@ pub struct CompleteBot{
|
||||
#[wasm_bindgen]
|
||||
impl CompleteBot{
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(data:&[u8])->Result<Self,JsValue>{
|
||||
let timelines=v0::read_all_to_block(std::io::Cursor::new(data)).map_err(|e|JsValue::from_str(&e.to_string()))?;
|
||||
pub fn new(data:&[u8])->Result<Self,JsError>{
|
||||
let timelines=v0::read_all_to_block(std::io::Cursor::new(data)).map_err(|e|JsError::new(&e.to_string()))?;
|
||||
Ok(Self{
|
||||
bot:bot::CompleteBot::new(timelines),
|
||||
})
|
||||
@@ -87,11 +87,11 @@ pub struct CompleteMap{
|
||||
#[wasm_bindgen]
|
||||
impl CompleteMap{
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(data:&[u8])->Result<Self,JsValue>{
|
||||
pub fn new(data:&[u8])->Result<Self,JsError>{
|
||||
let map=strafesnet_snf::read_map(std::io::Cursor::new(data))
|
||||
.map_err(|e|JsValue::from_str(&e.to_string()))?
|
||||
.map_err(|e|JsError::new(&e.to_string()))?
|
||||
.into_complete_map()
|
||||
.map_err(|e|JsValue::from_str(&e.to_string()))?;
|
||||
.map_err(|e|JsError::new(&e.to_string()))?;
|
||||
Ok(Self{
|
||||
map,
|
||||
})
|
||||
@@ -105,11 +105,11 @@ pub struct PlaybackHead{
|
||||
#[wasm_bindgen]
|
||||
impl PlaybackHead{
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(bot:&CompleteBot,time:f64)->Result<Self,JsValue>{
|
||||
pub fn new(bot:&CompleteBot,time:f64)->Self{
|
||||
let time=time::from_float(time).unwrap();
|
||||
Ok(Self{
|
||||
Self{
|
||||
head:head::PlaybackHead::new(&bot.bot,time),
|
||||
})
|
||||
}
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn advance_time(&mut self,bot:&CompleteBot,time:f64){
|
||||
|
||||
Reference in New Issue
Block a user