diff --git a/src/script.rs b/src/script.rs index fe03f228..3eecfd58 100644 --- a/src/script.rs +++ b/src/script.rs @@ -12,8 +12,7 @@ use graphics::GraphicsCommand; mod typescript; use typescript::transpile_to_javascript; -pub mod assets; -pub mod io; +mod io; struct Loader {} @@ -45,7 +44,6 @@ pub struct ScriptContext { draw: Value, gfx: graphics::GraphicsAPI, - _assets: assets::AssetsAPI, gfx_receive: Receiver, } @@ -62,8 +60,6 @@ impl ScriptContext { let gfx = graphics::GraphicsAPI::define(&context, gfx_send.clone()) .expect("Graphics module should load without error"); - let assets = assets::AssetsAPI::define(&context, gfx_send.clone()) - .expect("Assets module should load without error"); let _io = io::IoAPI::define(&context).expect("IO module should load without error"); let module = context @@ -89,8 +85,6 @@ impl ScriptContext { gfx, gfx_receive, - - _assets: assets, } } diff --git a/src/script/assets.rs b/src/script/assets.rs deleted file mode 100644 index f6bcbaec..00000000 --- a/src/script/assets.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::script::graphics::{CreateTextureCommand, GraphicsCommand}; -use oden_js::{module::native::NativeModuleBuilder, ContextRef, Error, Result}; -use std::sync::atomic::{AtomicU32, Ordering}; -use std::sync::mpsc::Sender; -use std::sync::Arc; - -struct AssetsImpl { - next_texture_id: AtomicU32, - gfx_sender: Sender, -} - -impl AssetsImpl { - fn new(sender: Sender) -> Self { - AssetsImpl { - gfx_sender: sender, - next_texture_id: AtomicU32::new(0), - } - } - - fn load_texture(&self, path: &str) -> Result { - let bytes = std::fs::read(path)?; - let image = match image::load_from_memory(&bytes) { - Ok(i) => i, - Err(e) => return Err(Error::RustFunctionError(format!("{e}"))), - }; - - let id = self.next_texture_id.fetch_add(1, Ordering::SeqCst); - let _ = self - .gfx_sender - .send(GraphicsCommand::CreateTexture(CreateTextureCommand { - id, - image, - label: Some(path.into()), - })); - - Ok(id) - } -} - -pub struct AssetsAPI {} - -impl AssetsAPI { - pub fn define(ctx: &ContextRef, sender: Sender) -> oden_js::Result { - let assets = Arc::new(AssetsImpl::new(sender)); - let mut builder = NativeModuleBuilder::new(ctx); - { - let assets = assets.clone(); - builder.export( - "load_texture", - ctx.new_fn(move |_ctx: &ContextRef, p: String| assets.load_texture(&p))?, - )?; - } - builder.build("asset-core")?; - Ok(AssetsAPI {}) - } -} diff --git a/types/asset-core.d.ts b/types/asset-core.d.ts deleted file mode 100644 index 87680547..00000000 --- a/types/asset-core.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -// These are the functions exposed by the native assets module. -// -export function load_texture(path: string): number;