Skip to content

Commit

Permalink
finish (?) script refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Jun 16, 2024
1 parent 23a7423 commit bbc894b
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 556 deletions.
26 changes: 23 additions & 3 deletions crates/unavi-scripting/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mod tests {
ScriptBundle,
};

const UPDATES: usize = 5;

pub async fn test_script(name: &str) {
let mut app = App::new();

Expand Down Expand Up @@ -58,7 +60,7 @@ mod tests {
let asset_server = app.world.get_resource::<AssetServer>().unwrap();
app.world.spawn(ScriptBundle::load(name, asset_server));

for _ in 0..5 {
for _ in 0..UPDATES {
tokio::time::sleep(Duration::from_secs_f32(0.2)).await;
app.update();
}
Expand All @@ -74,8 +76,26 @@ mod tests {
test_script("test:wired-gltf").await;
assert!(!logs_contain("ERROR"));
assert!(!logs_contain("error"));
assert!(logs_contain("Called script init"));
assert!(logs_contain("Called script update"));

logs_assert(|logs| {
let mut found_constructs = 0;
let mut found_updates = 0;

for log in logs {
if log.contains("Called script construct") {
found_constructs += 1;
}

if log.contains("Called script update") {
found_updates += 1;
}
}

assert_eq!(found_constructs, 1);
assert_eq!(found_updates, UPDATES - 1);

Ok(())
});
}

#[tokio::test]
Expand Down
14 changes: 13 additions & 1 deletion crates/unavi-scripting/src/host/wired_gltf/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::utils::HashSet;

use self::wired::{
gltf::node::Transform,
gltf::{material::Color, node::Transform},
math::types::{Quat, Vec3},
};

Expand All @@ -19,6 +19,18 @@ wasm_bridge::component::bindgen!({
#[derive(Default)]
pub struct Material {
pub name: String,
pub color: Color,
}

impl Default for Color {
fn default() -> Self {
Self {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
}
}
}

#[derive(Default)]
Expand Down
Loading

0 comments on commit bbc894b

Please sign in to comment.