[oden] Remove native assets module
What's the point?
This commit is contained in:
parent
f3f9988314
commit
96e95e22ce
3 changed files with 1 additions and 66 deletions
|
|
@ -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<graphics::GraphicsCommand>,
|
||||
}
|
||||
|
||||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<GraphicsCommand>,
|
||||
}
|
||||
|
||||
impl AssetsImpl {
|
||||
fn new(sender: Sender<GraphicsCommand>) -> Self {
|
||||
AssetsImpl {
|
||||
gfx_sender: sender,
|
||||
next_texture_id: AtomicU32::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn load_texture(&self, path: &str) -> Result<u32> {
|
||||
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<GraphicsCommand>) -> oden_js::Result<Self> {
|
||||
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 {})
|
||||
}
|
||||
}
|
||||
3
types/asset-core.d.ts
vendored
3
types/asset-core.d.ts
vendored
|
|
@ -1,3 +0,0 @@
|
|||
// These are the functions exposed by the native assets module.
|
||||
//
|
||||
export function load_texture(path: string): number;
|
||||
Loading…
Add table
Add a link
Reference in a new issue