Skip to content

Commit

Permalink
rename StoreState -> StoreData
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Sep 15, 2024
1 parent a903e64 commit 8a7f0d7
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 171 deletions.
4 changes: 2 additions & 2 deletions crates/unavi-scripting/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use anyhow::Result;
use wasm_bridge::component::Linker;

use super::state::StoreState;
use super::data::StoreData;

pub(crate) mod utils;
pub mod wired;

pub(crate) fn add_host_apis(linker: &mut Linker<StoreState>) -> Result<()> {
pub(crate) fn add_host_apis(linker: &mut Linker<StoreData>) -> Result<()> {
wired::scene::add_to_linker(linker)?;
wired::input::add_to_linker(linker)?;
wired::log::add_to_linker(linker)?;
Expand Down
32 changes: 16 additions & 16 deletions crates/unavi-scripting/src/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,46 @@ pub trait RefResource: RefCount + Send + Sized + 'static {

#[cfg(test)]
pub mod tests {
use crate::{load::DefaultMaterial, state::StoreState};
use crate::{data::StoreData, load::DefaultMaterial};

use super::*;

pub fn init_test_state() -> (World, StoreState) {
pub fn init_test_data() -> (World, StoreData) {
let mut world = World::new();
world.init_resource::<Assets<Mesh>>();

let default_material = Handle::default();
world.insert_resource(DefaultMaterial(default_material.clone()));

let root_ent = world.spawn_empty().id();
let state = StoreState::new("test".to_string(), root_ent, default_material);
let data = StoreData::new("test".to_string(), root_ent, default_material);

(world, state)
(world, data)
}

pub fn test_drop<T: RefResource + Send>(state: &mut StoreState, res_a: Resource<T>) {
let res_b = T::from_res(&res_a, &state.table).unwrap();
pub fn test_drop<T: RefResource + Send>(data: &mut StoreData, res_a: Resource<T>) {
let res_b = T::from_res(&res_a, &data.table).unwrap();

let dummy = Resource::new_own(res_a.rep());
assert!(state.table.get::<T>(&dummy).is_ok());
assert!(data.table.get::<T>(&dummy).is_ok());

T::handle_drop(res_a, &mut state.table).unwrap();
assert!(state.table.get::<T>(&dummy).is_ok());
T::handle_drop(res_a, &mut data.table).unwrap();
assert!(data.table.get::<T>(&dummy).is_ok());

T::handle_drop(res_b, &mut state.table).unwrap();
let err = state.table.get::<T>(&dummy);
T::handle_drop(res_b, &mut data.table).unwrap();
let err = data.table.get::<T>(&dummy);
assert!(err.is_err());
}

pub fn test_new<T: RefResource + Send>(state: &mut StoreState, res_a: Resource<T>) {
let data = state.table.get(&res_a).unwrap();
let res_b = data.new_own(res_a.rep());
pub fn test_new<T: RefResource + Send>(data: &mut StoreData, res_a: Resource<T>) {
let a = data.table.get(&res_a).unwrap();
let res_b = a.new_own(res_a.rep());
assert_eq!(res_a.rep(), res_b.rep());

let res_c = T::from_res(&res_a, &state.table).unwrap();
let res_c = T::from_res(&res_a, &data.table).unwrap();
assert_eq!(res_a.rep(), res_c.rep());

let res_d = T::from_rep(res_a.rep(), &state.table).unwrap();
let res_d = T::from_rep(res_a.rep(), &data.table).unwrap();
assert_eq!(res_a.rep(), res_d.rep());
}
}
18 changes: 9 additions & 9 deletions crates/unavi-scripting/src/api/wired/input/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasm_bridge::component::Resource;

use crate::{
api::utils::{RefCount, RefCountCell, RefResource},
state::StoreState,
data::StoreData,
};

use super::bindings::{
Expand Down Expand Up @@ -58,7 +58,7 @@ impl InputHandler {
}
}

impl HostInputHandler for StoreState {
impl HostInputHandler for StoreData {
fn new(&mut self) -> wasm_bridge::Result<Resource<InputHandler>> {
let handler = InputHandler::new();
let table_res = self.table.push(handler)?;
Expand Down Expand Up @@ -101,27 +101,27 @@ impl HostInputHandler for StoreState {
mod tests {
use tracing_test::traced_test;

use crate::api::utils::tests::init_test_state;
use crate::api::utils::tests::init_test_data;

use super::*;

#[test]
#[traced_test]
fn test_drop() {
let (_, mut state) = init_test_state();
let (_, mut data) = init_test_data();

let res = HostInputHandler::new(&mut state).unwrap();
let res = HostInputHandler::new(&mut data).unwrap();

crate::api::utils::tests::test_drop(&mut state, res);
crate::api::utils::tests::test_drop(&mut data, res);
}

#[test]
#[traced_test]
fn test_new() {
let (_, mut state) = init_test_state();
let (_, mut data) = init_test_data();

let res = HostInputHandler::new(&mut state).unwrap();
let res = HostInputHandler::new(&mut data).unwrap();

crate::api::utils::tests::test_new(&mut state, res);
crate::api::utils::tests::test_new(&mut data, res);
}
}
6 changes: 3 additions & 3 deletions crates/unavi-scripting/src/api/wired/input/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use wasm_bridge::component::Linker;

use crate::state::StoreState;
use crate::data::StoreData;

pub mod input_handler;

Expand All @@ -20,9 +20,9 @@ pub mod bindings {
pub use self::wired::input::*;
}

impl bindings::handler::Host for StoreState {}
impl bindings::handler::Host for StoreData {}

pub(crate) fn add_to_linker(linker: &mut Linker<StoreState>) -> Result<()> {
pub(crate) fn add_to_linker(linker: &mut Linker<StoreData>) -> Result<()> {
bindings::wired::input::handler::add_to_linker(linker, |s| s)?;
Ok(())
}
6 changes: 3 additions & 3 deletions crates/unavi-scripting/src/api/wired/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use bevy::log::{debug, error, info, info_span, warn};
use wasm_bridge::component::Linker;

use crate::state::StoreState;
use crate::data::StoreData;

pub mod bindings {
wasm_bridge::component::bindgen!({
Expand All @@ -14,7 +14,7 @@ pub mod bindings {

use self::bindings::api::LogLevel;

impl bindings::api::Host for StoreState {
impl bindings::api::Host for StoreData {
fn log(&mut self, level: LogLevel, message: String) -> wasm_bridge::Result<()> {
let span = info_span!("Script", name = self.name);
let span = span.enter();
Expand All @@ -32,7 +32,7 @@ impl bindings::api::Host for StoreState {
}
}

pub fn add_to_linker(linker: &mut Linker<StoreState>) -> Result<()> {
pub fn add_to_linker(linker: &mut Linker<StoreData>) -> Result<()> {
bindings::api::add_to_linker(linker, |s| s)?;
Ok(())
}
18 changes: 9 additions & 9 deletions crates/unavi-scripting/src/api/wired/physics/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wasm_bridge::component::Resource;

use crate::{
api::utils::{RefCount, RefCountCell, RefResource},
state::StoreState,
data::StoreData,
};

use super::bindings::{
Expand Down Expand Up @@ -47,7 +47,7 @@ impl Collider {
}
}

impl HostCollider for StoreState {
impl HostCollider for StoreData {
fn new(&mut self, shape: Shape) -> wasm_bridge::Result<Resource<Collider>> {
let collider = Collider::new(shape);
let table_res = self.table.push(collider)?;
Expand Down Expand Up @@ -75,29 +75,29 @@ impl HostCollider for StoreState {
mod tests {
use tracing_test::traced_test;

use crate::api::utils::tests::init_test_state;
use crate::api::utils::tests::init_test_data;

use super::*;

#[test]
#[traced_test]
fn test_drop() {
let (_, mut state) = init_test_state();
let (_, mut data) = init_test_data();

let shape = Shape::Sphere(0.5);
let res = HostCollider::new(&mut state, shape).unwrap();
let res = HostCollider::new(&mut data, shape).unwrap();

crate::api::utils::tests::test_drop(&mut state, res);
crate::api::utils::tests::test_drop(&mut data, res);
}

#[test]
#[traced_test]
fn test_new() {
let (_, mut state) = init_test_state();
let (_, mut data) = init_test_data();

let shape = Shape::Sphere(0.5);
let res = HostCollider::new(&mut state, shape).unwrap();
let res = HostCollider::new(&mut data, shape).unwrap();

crate::api::utils::tests::test_new(&mut state, res);
crate::api::utils::tests::test_new(&mut data, res);
}
}
6 changes: 3 additions & 3 deletions crates/unavi-scripting/src/api/wired/physics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use wasm_bridge::component::Linker;

use crate::state::StoreState;
use crate::data::StoreData;

mod collider;
mod rigid_body;
Expand All @@ -23,9 +23,9 @@ pub mod bindings {
pub use self::wired::physics::*;
}

impl bindings::types::Host for StoreState {}
impl bindings::types::Host for StoreData {}

pub fn add_to_linker(linker: &mut Linker<StoreState>) -> Result<()> {
pub fn add_to_linker(linker: &mut Linker<StoreData>) -> Result<()> {
bindings::wired::physics::types::add_to_linker(linker, |s| s)?;
Ok(())
}
18 changes: 9 additions & 9 deletions crates/unavi-scripting/src/api/wired/physics/rigid_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wasm_bridge::component::Resource;

use crate::{
api::utils::{RefCount, RefCountCell, RefResource},
state::StoreState,
data::StoreData,
};

use super::bindings::{
Expand Down Expand Up @@ -48,7 +48,7 @@ impl RefCount for RigidBody {

impl RefResource for RigidBody {}

impl HostRigidBody for StoreState {
impl HostRigidBody for StoreData {
fn new(&mut self, rigid_body_type: RigidBodyType) -> wasm_bridge::Result<Resource<RigidBody>> {
let rigid_body = RigidBody::new(rigid_body_type);
let table_res = self.table.push(rigid_body)?;
Expand Down Expand Up @@ -103,27 +103,27 @@ mod tests {

use tracing_test::traced_test;

use crate::api::utils::tests::init_test_state;
use crate::api::utils::tests::init_test_data;

use super::*;

#[test]
#[traced_test]
fn test_drop() {
let (_, mut state) = init_test_state();
let (_, mut data) = init_test_data();

let res = HostRigidBody::new(&mut state, RigidBodyType::Dynamic).unwrap();
let res = HostRigidBody::new(&mut data, RigidBodyType::Dynamic).unwrap();

crate::api::utils::tests::test_drop(&mut state, res);
crate::api::utils::tests::test_drop(&mut data, res);
}

#[test]
#[traced_test]
fn test_new() {
let (_, mut state) = init_test_state();
let (_, mut data) = init_test_data();

let res = HostRigidBody::new(&mut state, RigidBodyType::Dynamic).unwrap();
let res = HostRigidBody::new(&mut data, RigidBodyType::Dynamic).unwrap();

crate::api::utils::tests::test_new(&mut state, res);
crate::api::utils::tests::test_new(&mut data, res);
}
}
6 changes: 3 additions & 3 deletions crates/unavi-scripting/src/api/wired/player/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use wasm_bridge::component::{Linker, Resource};

use crate::{api::utils::RefResource, state::StoreState};
use crate::{api::utils::RefResource, data::StoreData};

#[allow(clippy::module_inception)]
mod player;
Expand All @@ -23,12 +23,12 @@ pub mod bindings {
pub use wired::player::*;
}

pub fn add_to_linker(linker: &mut Linker<StoreState>) -> Result<()> {
pub fn add_to_linker(linker: &mut Linker<StoreData>) -> Result<()> {
bindings::api::add_to_linker(linker, |s| s)?;
Ok(())
}

impl bindings::api::Host for StoreState {
impl bindings::api::Host for StoreData {
fn list_players(&mut self) -> wasm_bridge::Result<Vec<Resource<player::Player>>> {
Ok(Vec::default())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/unavi-scripting/src/api/wired/player/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
utils::{RefCount, RefCountCell, RefResource},
wired::scene::bindings::node::HostNode,
},
state::StoreState,
data::StoreData,
};

use super::bindings::api::{HostPlayer, Node, Skeleton};
Expand All @@ -28,7 +28,7 @@ impl RefCount for Player {
impl RefResource for Player {}

impl Player {
pub fn new(data: &mut StoreState) -> anyhow::Result<Resource<Self>> {
pub fn new(data: &mut StoreData) -> anyhow::Result<Resource<Self>> {
let root = data.new()?;

let hips = data.new()?;
Expand Down Expand Up @@ -213,7 +213,7 @@ impl Skeleton {
}
}

impl HostPlayer for StoreState {
impl HostPlayer for StoreData {
fn root(&mut self, self_: Resource<Player>) -> wasm_bridge::Result<Resource<Node>> {
let player = self.table.get(&self_)?;
let root = Node::from_res(&player.root, &self.table)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/unavi-scripting/src/api/wired/scene/gltf/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
utils::{RefCount, RefCountCell, RefResource},
wired::scene::bindings::wired::scene::gltf::{Host, HostGltf},
},
state::StoreState,
data::StoreData,
};

use super::{material::MaterialRes, mesh::MeshRes, node::NodeRes, scene::SceneRes};
Expand All @@ -30,7 +30,7 @@ impl RefCount for GltfDocument {

impl RefResource for GltfDocument {}

impl HostGltf for StoreState {
impl HostGltf for StoreData {
fn new(&mut self) -> wasm_bridge::Result<Resource<GltfDocument>> {
let node = GltfDocument::default();
let table_res = self.table.push(node)?;
Expand Down Expand Up @@ -275,4 +275,4 @@ impl HostGltf for StoreState {
}
}

impl Host for StoreState {}
impl Host for StoreData {}
Loading

0 comments on commit 8a7f0d7

Please sign in to comment.