Skip to content

Commit

Permalink
Fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Jul 12, 2024
1 parent 3a2b77e commit b47e959
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions bevy_nannou/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub mod prelude {

#[cfg(feature = "isf")]
pub use bevy_nannou_isf::prelude::*;
#[cfg(feature = "video")]
pub use bevy_nannou_video::prelude::*;
#[cfg(feature = "script_js")]
pub use bevy_nannou_script_js::prelude::*;
#[cfg(feature = "video")]
pub use bevy_nannou_video::prelude::*;
}

pub struct NannouPlugin;
Expand Down
12 changes: 6 additions & 6 deletions bevy_nannou_script_js/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bevy::prelude::info;
// NOTE: this example requires the `console` feature to run correctly.
use boa_engine::object::builtins::JsArray;
use boa_engine::value::Numeric;
use boa_engine::{
class::{Class, ClassBuilder},
error::JsNativeError,
Expand All @@ -8,8 +10,6 @@ use boa_engine::{
property::Attribute,
Context, JsArgs, JsData, JsResult, JsString, JsValue, Source,
};
use boa_engine::object::builtins::JsArray;
use boa_engine::value::Numeric;
use boa_gc::{Finalize, Trace};
use boa_runtime::Console;

Expand All @@ -24,7 +24,7 @@ impl JsApp {
fn elapsed_seconds(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
if let Some(object) = this.as_object() {
if let Some(app) = object.downcast_ref::<JsApp>() {
return Ok(JsValue::from(Numeric::from(app.elapsed_seconds)))
return Ok(JsValue::from(Numeric::from(app.elapsed_seconds)));
}
}
Err(JsNativeError::typ()
Expand All @@ -38,7 +38,7 @@ impl JsApp {
let array = JsArray::new(ctx);
array.push(JsValue::from(app.mouse.0), ctx)?;
array.push(JsValue::from(app.mouse.1), ctx)?;
return Ok(JsValue::from(array))
return Ok(JsValue::from(array));
}
}
Err(JsNativeError::typ()
Expand All @@ -52,7 +52,7 @@ impl JsApp {
let array = JsArray::new(ctx);
array.push(JsValue::from(app.window_rect.0), ctx)?;
array.push(JsValue::from(app.window_rect.1), ctx)?;
return Ok(JsValue::from(array))
return Ok(JsValue::from(array));
}
}
Err(JsNativeError::typ()
Expand Down Expand Up @@ -94,4 +94,4 @@ impl Class for JsApp {

Ok(())
}
}
}
22 changes: 12 additions & 10 deletions bevy_nannou_script_js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::any::{Any, TypeId};
use std::collections::HashMap;

use crate::app::JsApp;
use anyhow::{anyhow, Context as AnyhowContext};
use bevy::ecs::world::unsafe_world_cell::UnsafeWorldCell;
use bevy::prelude::*;
Expand All @@ -19,17 +20,16 @@ use boa_engine::{
};
use boa_gc::{Finalize, Trace};
use boa_runtime::Console;
use crate::app::JsApp;

use crate::asset::{Script, ScriptAssetPlugin};

mod asset;
mod app;
mod asset;

pub mod prelude {
pub use crate::app::JsApp;
pub use crate::asset::Script;
pub use crate::run_script;
pub use crate::app::JsApp;
pub use crate::RegisterScriptTypeExt;
pub use crate::UpdateScript;
pub use crate::UpdateScriptAssetLocation;
Expand Down Expand Up @@ -62,7 +62,9 @@ macro_rules! register_numeric_type {
$type_registry,
|v| JsValue::from(*v.downcast_ref::<$type>().expect("Unable to downcast")),
|v, ctx| {
let numeric = v.to_numeric(ctx).expect("Could not convert value to numeric");
let numeric = v
.to_numeric(ctx)
.expect("Could not convert value to numeric");
match numeric {
boa_engine::value::Numeric::Number(f) => Box::new(f as $type),
_ => panic!("Unsupported numeric type"),
Expand Down Expand Up @@ -118,8 +120,7 @@ pub struct ScriptJsPlugin;

impl Plugin for ScriptJsPlugin {
fn build(&self, app: &mut App) {
app
.add_systems(Startup, setup)
app.add_systems(Startup, setup)
.add_plugins(ScriptAssetPlugin);
}

Expand Down Expand Up @@ -299,13 +300,15 @@ pub fn run_script(world: &mut World, js_app: JsApp, model: &mut dyn Reflect) {
.set(JsString::from("model"), js_model, true, &mut ctx)
.expect("Unable to set model in global object");

let prototype = ctx.realm().get_class::<JsApp>().expect("Unable to get app class");
let prototype = ctx
.realm()
.get_class::<JsApp>()
.expect("Unable to get app class");
let js_app = JsObject::from_proto_and_data(Some(prototype.prototype()), js_app);
ctx.global_object()
.set(JsString::from("app"), JsValue::from(js_app), true, &mut ctx)
.expect("Unable to set app in global object");
let result = ctx
.eval(Source::from_bytes(&script));
let result = ctx.eval(Source::from_bytes(&script));
if let Ok(result) = result {
match write_js_model(model.reflect_mut(), result, &type_registry, &mut ctx) {
Ok(_) => {}
Expand All @@ -316,7 +319,6 @@ pub fn run_script(world: &mut World, js_app: JsApp, model: &mut dyn Reflect) {
} else {
error!("Error running update script: {:?}", result);
};

}
world.insert_non_send_resource(ctx);
}
Expand Down
8 changes: 2 additions & 6 deletions examples/script/script_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ fn model(app: &App) -> Model {
.view(view) // The function that will be called for presenting graphics to a frame.
.build();

Model {
radius: 40f32,
}
Model { radius: 40f32 }
}

// Draw the state of your `Model` into the given `Frame` here.
Expand All @@ -32,7 +30,5 @@ fn view(app: &App, model: &Model) {

draw.background().color(BLACK);

draw.ellipse()
.x_y(100.0, 100.0)
.radius(model.radius);
draw.ellipse().x_y(100.0, 100.0).radius(model.radius);
}
16 changes: 9 additions & 7 deletions nannou/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::prelude::bevy_asset::io::AssetSource;
use crate::prelude::bevy_ecs::system::SystemState;
use crate::prelude::bevy_render::extract_resource::extract_resource;
use crate::prelude::render::{NannouMesh, NannouPersistentMesh};
use crate::prelude::{NannouMaterialPlugin};
use crate::prelude::NannouMaterialPlugin;
use crate::render::RenderApp;
use crate::window::WindowUserFunctions;
use crate::{camera, geom, light, window};
Expand Down Expand Up @@ -431,11 +431,16 @@ where

#[cfg(feature = "script_js")]
pub fn update_script(mut self, script_asset: &'static str) -> Self {
self.app.insert_resource(bevy_nannou::prelude::UpdateScriptAssetLocation(script_asset.to_string()));
self.app
.insert_resource(bevy_nannou::prelude::UpdateScriptAssetLocation(
script_asset.to_string(),
));
self.update_script = Some(|app, model| {
let world = app.world_mut();
if !world.contains_resource::<bevy_nannou::prelude::UpdateScript>() {
let script_asset = world.get_resource::<bevy_nannou::prelude::UpdateScriptAssetLocation>().unwrap();
let script_asset = world
.get_resource::<bevy_nannou::prelude::UpdateScriptAssetLocation>()
.unwrap();
let script = world.load_asset(&script_asset.0);
world.insert_resource(bevy_nannou::prelude::UpdateScript(script));
}
Expand Down Expand Up @@ -899,10 +904,7 @@ impl<'w> App<'w> {
None => self.window_id(),
};

let draw = self
.world_mut()
.entity(window_id)
.get::<DrawHolder>();
let draw = self.world_mut().entity(window_id).get::<DrawHolder>();
draw.unwrap().0.clone()
}

Expand Down

0 comments on commit b47e959

Please sign in to comment.