From 17cf228d06b0023f0a6d42e80069499f2e831ba6 Mon Sep 17 00:00:00 2001 From: LaserWitch <128329371+LaserWitch@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:07:26 -0500 Subject: [PATCH] Bevy 0.12 migration (#93) * Game of life lua example builds and runs on bevy 0.12 now. It doesn't work, but it does run! * Basic lua scripts may now be working at least aprt of the time. * migrate rhai parts, formatting etc * formatting * migrate rune * format * revert some changes * fix lint --------- Co-authored-by: makspll --- Cargo.toml | 27 +- api_gen_config.toml | 46 +- bevy_api_gen/Cargo.toml | 2 +- bevy_api_gen/src/main.rs | 5 +- bevy_event_priority/Cargo.toml | 4 +- bevy_mod_scripting_common/Cargo.toml | 2 +- bevy_mod_scripting_core/Cargo.toml | 8 +- bevy_mod_scripting_core/src/systems.rs | 12 +- bevy_mod_scripting_derive/Cargo.toml | 4 +- bevy_script_api/Cargo.toml | 26 +- bevy_script_api/src/common/bevy/mod.rs | 12 +- bevy_script_api/src/generated.rs | 770 +++++++++++------- bevy_script_api/src/lua/bevy/mod.rs | 4 +- bevy_script_api/src/lua/mod.rs | 2 +- bevy_script_api/src/lua/std.rs | 8 +- bevy_script_api/src/rhai/mod.rs | 4 +- bevy_script_api/src/rhai/std.rs | 8 +- bevy_script_api/src/script_ref.rs | 2 +- examples/lua/complex_game_loop.rs | 12 +- examples/lua/console_integration.rs | 39 +- examples/lua/coroutines.rs | 27 +- examples/lua/documentation_gen.rs | 33 +- examples/lua/event_recipients.rs | 27 +- examples/lua/game_of_life.rs | 42 +- examples/rhai/console_integration.rs | 39 +- examples/rhai/game_of_life.rs | 48 +- examples/rhai/multiple_events_rhai.rs | 2 +- languages/bevy_mod_scripting_lua/Cargo.toml | 10 +- .../bevy_mod_scripting_lua/src/assets.rs | 221 ++--- languages/bevy_mod_scripting_lua/src/docs.rs | 10 +- languages/bevy_mod_scripting_lua/src/lib.rs | 2 +- .../bevy_mod_scripting_lua_derive/Cargo.toml | 4 +- languages/bevy_mod_scripting_rhai/Cargo.toml | 15 +- .../bevy_mod_scripting_rhai/src/assets.rs | 33 +- languages/bevy_mod_scripting_rhai/src/lib.rs | 2 +- .../bevy_mod_scripting_rhai_derive/Cargo.toml | 4 +- languages/bevy_mod_scripting_rune/Cargo.toml | 7 +- .../bevy_mod_scripting_rune/src/assests.rs | 44 - .../bevy_mod_scripting_rune/src/assets.rs | 46 ++ languages/bevy_mod_scripting_rune/src/lib.rs | 6 +- makefile | 36 +- 41 files changed, 906 insertions(+), 749 deletions(-) delete mode 100644 languages/bevy_mod_scripting_rune/src/assests.rs create mode 100644 languages/bevy_mod_scripting_rune/src/assets.rs diff --git a/Cargo.toml b/Cargo.toml index e65bcbd0..132fbbfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -63,18 +63,19 @@ rhai_script_api = ["bevy_script_api/rhai"] rune = ["bevy_mod_scripting_rune"] [dependencies] -bevy = { version = "0.11", default-features = false } -bevy_mod_scripting_core = { path = "bevy_mod_scripting_core", version = "0.3.0" } -bevy_mod_scripting_lua = { path = "languages/bevy_mod_scripting_lua", version = "0.3.0", optional = true } -bevy_mod_scripting_rhai = { path = "languages/bevy_mod_scripting_rhai", version = "0.3.0", optional = true } -bevy_mod_scripting_rune = { path = "languages/bevy_mod_scripting_rune", version = "0.3.0", optional = true } -bevy_script_api = { path = "bevy_script_api", version = "0.3.0", optional = true } +bevy = { version = "0.12", default-features = false } +bevy_mod_scripting_core = { path = "bevy_mod_scripting_core", version = "0.4.0" } +bevy_mod_scripting_lua = { path = "languages/bevy_mod_scripting_lua", version = "0.4.0", optional = true } +bevy_mod_scripting_rhai = { path = "languages/bevy_mod_scripting_rhai", version = "0.4.0", optional = true } +bevy_mod_scripting_rune = { path = "languages/bevy_mod_scripting_rune", version = "0.4.0", optional = true } +bevy_script_api = { path = "bevy_script_api", version = "0.4.0", optional = true } + [dev-dependencies] -bevy = { version = "0.11" } +bevy = { version = "0.12" } clap = { version = "4.1", features = ["derive"] } rand = "0.8.5" -bevy_console = "0.8.0" +bevy_console = "0.10.1" rhai-rand = "0.1" [workspace] @@ -108,12 +109,12 @@ codegen-units = 8 [[example]] name = "console_integration_lua" path = "examples/lua/console_integration.rs" -required-features = ["lua54", "lua_script_api"] +required-features = ["lua54", "lua_script_api", "bevy/file_watcher"] [[example]] name = "console_integration_rhai" path = "examples/rhai/console_integration.rs" -required-features = ["rhai", "rhai_script_api"] +required-features = ["rhai", "rhai_script_api", "bevy/file_watcher"] [[example]] name = "complex_game_loop_lua" @@ -123,12 +124,12 @@ required-features = ["lua54"] [[example]] name = "game_of_life_lua" path = "examples/lua/game_of_life.rs" -required-features = ["lua54", "teal", "lua_script_api"] +required-features = ["lua54", "teal", "lua_script_api", "bevy/file_watcher"] [[example]] name = "game_of_life_rhai" path = "examples/rhai/game_of_life.rs" -required-features = ["rhai", "rhai_script_api"] +required-features = ["rhai", "rhai_script_api", "bevy/file_watcher"] [[example]] name = "event_recipients_lua" diff --git a/api_gen_config.toml b/api_gen_config.toml index 7c017f55..502f32f9 100644 --- a/api_gen_config.toml +++ b/api_gen_config.toml @@ -390,7 +390,11 @@ type="VisibleEntities" source="bevy_render" [[types]] -type="ComputedVisibility" +type="InheritedVisibility" +source="bevy_render" + +[[types]] +type="ViewVisibility" source="bevy_render" [[types]] @@ -469,20 +473,26 @@ source="bevy_render" ## BEVY_ASSET [[types]] -type="AssetPathId" +type="AssetIndex" source="bevy_asset" -[[types]] -type="LabelId" -source="bevy_asset" +#Needs manual implementation? it's generic. +#[[types]] +#type="AssetId" +#source="bevy_asset" -[[types]] -type="SourcePathId" -source="bevy_asset" +#Not handled by reflection +#[[types]] +#type="StrongHandle" +#source="bevy_asset" -[[types]] -type="HandleId" -source="bevy_asset" +#[[types]] +#type="Label" +#source="bevy_asset" + +#[[types]] +#type="Handle" +#source="bevy_asset" ## BEVY_MATH [[types]] @@ -648,7 +658,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) } } }) @@ -679,7 +689,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat2".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat2".into()}) } } }) @@ -711,7 +721,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3A".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3A".into()}) } } }) @@ -742,7 +752,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat4".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat4".into()}) } } }) @@ -774,7 +784,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat2".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"DMat2".into()}) } } }) @@ -805,7 +815,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat3".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"DMat3".into()}) } } }) @@ -836,7 +846,7 @@ lua_methods=[ .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat4".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"DMat4".into()}) } } }) diff --git a/bevy_api_gen/Cargo.toml b/bevy_api_gen/Cargo.toml index b215f154..8a973ad6 100644 --- a/bevy_api_gen/Cargo.toml +++ b/bevy_api_gen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_api_gen" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" diff --git a/bevy_api_gen/src/main.rs b/bevy_api_gen/src/main.rs index e47e1f50..94370d51 100644 --- a/bevy_api_gen/src/main.rs +++ b/bevy_api_gen/src/main.rs @@ -97,9 +97,7 @@ pub(crate) fn generate_macros( let path_components = get_path(id, source).unwrap_or_else(|| { panic!("path not found for {:?} in {:?}", id, source.root) }); - //eprintln!("{:?}", path_components); let path_components = path_to_import(path_components, source); - //eprintln!("{:?}", path_components); let wrapper_name = format!("{WRAPPER_PREFIX}{}", item.name.as_ref().unwrap()); let wrapped_type = item.name.as_ref().unwrap(); @@ -125,7 +123,8 @@ pub(crate) fn generate_macros( }); if !unmatched_types.is_empty() { - panic!("Some types were not found in the given crates: {unmatched_types:#?}") + //panic!("Some types were not found in the given crates: {unmatched_types:#?}") + eprintln!("Some types were not found in the given crates: {unmatched_types:#?}") } let mut writer = PrettyWriter::new(); diff --git a/bevy_event_priority/Cargo.toml b/bevy_event_priority/Cargo.toml index cc76f9da..d36cc05d 100644 --- a/bevy_event_priority/Cargo.toml +++ b/bevy_event_priority/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_event_priority" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -21,5 +21,5 @@ name = "bevy_event_priority" path = "src/lib.rs" [dependencies] -bevy = { version = "0.11", default-features = false} +bevy = { version = "0.12", default-features = false} diff --git a/bevy_mod_scripting_common/Cargo.toml b/bevy_mod_scripting_common/Cargo.toml index e1d08e48..51bfa6cf 100644 --- a/bevy_mod_scripting_common/Cargo.toml +++ b/bevy_mod_scripting_common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_common" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" diff --git a/bevy_mod_scripting_core/Cargo.toml b/bevy_mod_scripting_core/Cargo.toml index 3641e840..4a52cbe0 100644 --- a/bevy_mod_scripting_core/Cargo.toml +++ b/bevy_mod_scripting_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_core" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -29,10 +29,10 @@ doc_always = [] [dependencies] -bevy = { version = "0.11", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite","filesystem_watcher"]} -bevy_event_priority = {path = "../bevy_event_priority", version = "0.3.0" } +bevy = { version = "0.12", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite"]} +bevy_event_priority = {path = "../bevy_event_priority", version = "0.4.0" } thiserror = "1.0.31" paste = "1.0.7" parking_lot = "0.12.1" - +anyhow ="1.0.75" diff --git a/bevy_mod_scripting_core/src/systems.rs b/bevy_mod_scripting_core/src/systems.rs index 000f9ecd..10dca529 100644 --- a/bevy_mod_scripting_core/src/systems.rs +++ b/bevy_mod_scripting_core/src/systems.rs @@ -95,7 +95,7 @@ pub fn script_remove_synchronizer( mut query: RemovedComponents>, mut contexts: ResMut>, ) { - for v in query.iter() { + for v in query.read() { // we know that this entity used to have a script component // ergo a script context must exist in ctxts, remove all scripts on the entity let script_ids = contexts @@ -121,10 +121,10 @@ pub fn script_hot_reload_handler( mut contexts: ResMut>, mut event_writer: EventWriter, ) { - for e in events.iter() { + for e in events.read() { let (handle, created) = match e { - AssetEvent::Modified { handle } => (handle, false), - AssetEvent::Created { handle } => (handle, true), + AssetEvent::Modified { id } => (id, false), + AssetEvent::Added { id } => (id, true), _ => continue, }; @@ -137,7 +137,9 @@ pub fn script_hot_reload_handler( for script in &scripts.scripts { // the script could have well loaded in the same frame that it was added // in that case it will have a context attached and we do not want to reload it - if script.handle() == handle && !(contexts.has_context(script.id()) && created) { + if script.handle().id() == *handle + && !(contexts.has_context(script.id()) && created) + { Script::::reload_script::( &mut host, script, diff --git a/bevy_mod_scripting_derive/Cargo.toml b/bevy_mod_scripting_derive/Cargo.toml index 568846f8..b0706c70 100644 --- a/bevy_mod_scripting_derive/Cargo.toml +++ b/bevy_mod_scripting_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_derive" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -24,7 +24,7 @@ path = "src/lib.rs" [dependencies] -bevy_mod_scripting_common = {path = "../bevy_mod_scripting_common", version = "0.3.0" } +bevy_mod_scripting_common = {path = "../bevy_mod_scripting_common", version = "0.4.0" } paste = "1.0.7" syn = {version="1.0.57",features=["full","fold","extra-traits"]} quote = "1.0.8" diff --git a/bevy_script_api/Cargo.toml b/bevy_script_api/Cargo.toml index 978c4075..a7c44f01 100644 --- a/bevy_script_api/Cargo.toml +++ b/bevy_script_api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_script_api" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -13,12 +13,12 @@ readme = "readme.md" [package.metadata.release] pre-release-replacements = [ - {file="Cargo.toml", search='^version\s*=\s*.*$', replace="version = \"{{version}}\"", exactly=1}, - {file="Cargo.toml", search='^(?Pbevy_mod_scripting_derive\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, - {file="Cargo.toml", search='^(?Pbevy_mod_scripting_core\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, - {file="Cargo.toml", search='^(?Pbevy_mod_scripting_lua\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, - {file="Cargo.toml", search='^(?Pbevy_mod_scripting_lua_derive\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, - {file="Cargo.toml", search='^(?Pbevy_mod_scripting_rhai\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, + { file = "Cargo.toml", search='^version\s*=\s*.*$', replace="version = \"{{version}}\"", exactly=1}, + { file = "Cargo.toml", search='^(?Pbevy_mod_scripting_derive\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, + { file = "Cargo.toml", search='^(?Pbevy_mod_scripting_core\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, + { file = "Cargo.toml", search='^(?Pbevy_mod_scripting_lua\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, + { file = "Cargo.toml", search='^(?Pbevy_mod_scripting_lua_derive\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, + { file = "Cargo.toml", search='^(?Pbevy_mod_scripting_rhai\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, ] [features] @@ -26,13 +26,13 @@ lua = ["bevy_mod_scripting_lua","bevy_mod_scripting_lua_derive"] rhai = ["bevy_mod_scripting_rhai"] [dependencies] -bevy = { version = "0.11", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite","filesystem_watcher"]} -bevy_mod_scripting_derive = { path="../bevy_mod_scripting_derive", version = "0.3.0" } -bevy_mod_scripting_core = { path="../bevy_mod_scripting_core", version = "0.3.0" } +bevy = { version = "0.12", default-features = false, features=["bevy_asset","bevy_gltf","bevy_animation","bevy_core_pipeline","bevy_ui","bevy_pbr","bevy_render","bevy_text","bevy_sprite"]} +bevy_mod_scripting_derive = { path="../bevy_mod_scripting_derive", version = "0.4.0" } +bevy_mod_scripting_core = { path="../bevy_mod_scripting_core", version = "0.4.0" } parking_lot="0.12.1" paste="1.0.7" thiserror="1.0.32" # lua -bevy_mod_scripting_lua={path="../languages/bevy_mod_scripting_lua", version = "0.3.0", optional=true} -bevy_mod_scripting_lua_derive={path="../languages/bevy_mod_scripting_lua_derive", version = "0.3.0", optional=true} -bevy_mod_scripting_rhai={path="../languages/bevy_mod_scripting_rhai", version = "0.3.0", optional=true} +bevy_mod_scripting_lua={path="../languages/bevy_mod_scripting_lua", version = "0.4.0", optional=true} +bevy_mod_scripting_lua_derive={path="../languages/bevy_mod_scripting_lua_derive", version = "0.4.0", optional=true} +bevy_mod_scripting_rhai={path="../languages/bevy_mod_scripting_rhai", version = "0.4.0", optional=true} diff --git a/bevy_script_api/src/common/bevy/mod.rs b/bevy_script_api/src/common/bevy/mod.rs index 7528784c..b4c39917 100644 --- a/bevy_script_api/src/common/bevy/mod.rs +++ b/bevy_script_api/src/common/bevy/mod.rs @@ -34,26 +34,26 @@ impl ScriptTypeRegistration { #[inline(always)] pub fn short_name(&self) -> &str { - self.0.short_name() + self.0.type_info().type_path_table().short_path() } #[inline(always)] pub fn type_name(&self) -> &'static str { - self.0.type_name() + self.0.type_info().type_path_table().path() } } impl std::fmt::Debug for ScriptTypeRegistration { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("ScriptTypeRegistration") - .field(&self.0.type_name()) + .field(&self.0.type_info().type_path()) .finish() } } impl std::fmt::Display for ScriptTypeRegistration { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(self.0.short_name()) + f.write_str(self.0.type_info().type_path()) } } @@ -157,8 +157,8 @@ impl ScriptWorld { let registry = registry.read(); registry - .get_with_short_name(type_name) - .or_else(|| registry.get_with_name(type_name)) + .get_with_short_type_path(type_name) + .or_else(|| registry.get_with_type_path(type_name)) .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) } diff --git a/bevy_script_api/src/generated.rs b/bevy_script_api/src/generated.rs index 72ff7394..01c14062 100644 --- a/bevy_script_api/src/generated.rs +++ b/bevy_script_api/src/generated.rs @@ -7,10 +7,7 @@ use crate::{ sub_reflect::ReflectPathElem, }; use bevy::animation::AnimationPlayer; -use bevy::asset::AssetPathId; -use bevy::asset::HandleId; -use bevy::asset::LabelId; -use bevy::asset::SourcePathId; +use bevy::asset::AssetIndex; use bevy::core::Name; use bevy::core_pipeline::clear_color::ClearColor; use bevy::core_pipeline::clear_color::ClearColorConfig; @@ -81,8 +78,9 @@ use bevy::render::mesh::skinning::SkinnedMesh; use bevy::render::primitives::Aabb; use bevy::render::primitives::CubemapFrusta; use bevy::render::primitives::Frustum; -use bevy::render::view::visibility::ComputedVisibility; +use bevy::render::view::visibility::InheritedVisibility; use bevy::render::view::visibility::RenderLayers; +use bevy::render::view::visibility::ViewVisibility; use bevy::render::view::visibility::Visibility; use bevy::render::view::visibility::VisibleEntities; use bevy::render::view::Msaa; @@ -132,9 +130,11 @@ use { }; impl_script_newtype! { #[languages(on_feature(lua))] - ///Defines how each line is aligned within the flexbox. + ///Used to control how items are distributed. + ///- For Flexbox containers, controls alignment of lines if `flex_wrap` is set to [`FlexWrap::Wrap`] and there are multiple lines of items. + ///- For CSS Grid containers, controls alignment of grid rows. /// - ///It only applies if [`FlexWrap::Wrap`] is present and if there are multiple lines of items. + /// bevy_ui::AlignContent : Clone + Debug + @@ -156,7 +156,11 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///How items are aligned according to the cross axis + ///Used to control how each individual item is aligned by default within the space they're given. + ///- For Flexbox containers, sets default cross axis alignment of the child items. + ///- For CSS Grid containers, controls block (vertical) axis alignment of children of this grid container within their grid areas. + /// + /// bevy_ui::AlignItems : Clone + Debug + @@ -178,8 +182,11 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///How this item is aligned according to the cross axis. - ///Overrides [`AlignItems`]. + ///Used to control how the specified item is aligned within the space it's given. + ///- For Flexbox items, controls cross axis alignment of the item. + ///- For CSS Grid items, controls block (vertical) axis alignment of a grid item within its grid area. + /// + /// bevy_ui::AlignSelf : Clone + Debug + @@ -201,9 +208,9 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///Defines the text direction + ///Defines the text direction. /// - ///For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). + ///For example, English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). bevy_ui::Direction : Clone + Debug + @@ -297,9 +304,9 @@ impl_script_newtype! { /// ///Updated in [`ui_focus_system`]. /// - ///If a UI node has both [`Interaction`] and [`ComputedVisibility`] components, + ///If a UI node has both [`Interaction`] and [`ViewVisibility`] components, ///[`Interaction`] will always be [`Interaction::None`] - ///when [`ComputedVisibility::is_visible()`] is false. + ///when [`ViewVisibility::get()`] is false. ///This ensures that hidden UI nodes are not interactable, ///and do not end up stuck in an active state if hidden at the wrong time. /// @@ -326,7 +333,11 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///Defines how items are aligned according to the main axis + ///Used to control how items are distributed. + ///- For Flexbox containers, controls alignment of items in the main axis. + ///- For CSS Grid containers, controls alignment of grid columns. + /// + /// bevy_ui::JustifyContent : Clone + Debug + @@ -413,7 +424,7 @@ impl_script_newtype! { #[languages(on_feature(lua))] ///Represents the possible value types for layout properties. /// - ///This enum allows specifying values for various [`Style`] properties in different units, + ///This enum allows specifying values for various [`Style`](crate::Style) properties in different units, ///such as logical pixels, percentages, or automatically determined values. bevy_ui::Val : Clone + @@ -431,6 +442,7 @@ impl_script_newtype! { ) + UnaryOps ( + Neg self -> self ) lua impl { @@ -468,10 +480,20 @@ impl_script_newtype! { Debug + Methods ( - ///The calculated node size as width and height in logical pixels - ///automatically calculated by [`super::layout::ui_layout_system`] + ///The calculated node size as width and height in logical pixels. + /// + ///Automatically calculated by [`super::layout::ui_layout_system`]. size(&self:) -> Wrapped(Vec2), + ///The order of the node in the UI layout. + ///Nodes with a higher stack index are drawn on top of and recieve interactions before nodes with lower stack indices. + stack_index(&self:) -> Raw(u32), + + ///The calculated node size as width and height in logical pixels before rounding. + /// + ///Automatically calculated by [`super::layout::ui_layout_system`]. + unrounded_size(&self:) -> Wrapped(Vec2), + ///Returns the size of the node in physical pixels based on the given scale factor and `UiScale`. physical_size(&self:Raw(f64),Raw(f64)) -> Wrapped(Vec2), @@ -481,6 +503,10 @@ impl_script_newtype! { ///Returns the physical pixel coordinates of the UI node, based on its [`GlobalTransform`] and the scale factor. physical_rect(&self:Wrapped(&GlobalTransform),Raw(f64),Raw(f64)) -> Wrapped(Rect), + ///Returns the thickness of the UI node's outline. + ///If this value is negative or `0.` then no outline will be rendered. + outline_width(&self:) -> Raw(f32), + ) + Fields ( @@ -499,19 +525,20 @@ impl_script_newtype! { #[languages(on_feature(lua))] ///Describes the style of a UI container node /// - ///Node's can be laid out using either Flexbox or CSS Grid Layout.
+ ///Nodes can be laid out using either Flexbox or CSS Grid Layout. + /// ///See below for general learning resources and for documentation on the individual style properties. /// ///### Flexbox /// - ///- [MDN: Basic Concepts of Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout) - ///- [A Complete Guide To Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) by CSS Tricks. This is detailed guide with illustrations and comphrehensive written explanation of the different Flexbox properties and how they work. - ///- [Flexbox Froggy](https://flexboxfroggy.com/). An interactive tutorial/game that teaches the essential parts of Flebox in a fun engaging way. + ///- [MDN: Basic Concepts of Flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox) + ///- [A Complete Guide To Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) by CSS Tricks. This is detailed guide with illustrations and comprehensive written explanation of the different Flexbox properties and how they work. + ///- [Flexbox Froggy](https://flexboxfroggy.com/). An interactive tutorial/game that teaches the essential parts of Flexbox in a fun engaging way. /// ///### CSS Grid /// - ///- [MDN: Basic Concepts of Flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox) - ///- [A Complete Guide To CSS Grid](https://css-tricks.com/snippets/css/complete-guide-grid/) by CSS Tricks. This is detailed guide with illustrations and comphrehensive written explanation of the different CSS Grid properties and how they work. + ///- [MDN: Basic Concepts of Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout) + ///- [A Complete Guide To CSS Grid](https://css-tricks.com/snippets/css/complete-guide-grid/) by CSS Tricks. This is detailed guide with illustrations and comprehensive written explanation of the different CSS Grid properties and how they work. ///- [CSS Grid Garden](https://cssgridgarden.com/). An interactive tutorial/game that teaches the essential parts of CSS Grid in a fun engaging way. bevy_ui::Style : Clone + @@ -528,7 +555,7 @@ impl_script_newtype! { /// /// display: Wrapped(Display), - /// Whether a node should be laid out in-flow with, or independently of it's siblings: + /// Whether a node should be laid out in-flow with, or independently of its siblings: /// - [`PositionType::Relative`]: Layout this node in-flow with other nodes using the usual (flexbox/grid) layout algorithm. /// - [`PositionType::Absolute`]: Layout this node on top and independently of other nodes. /// @@ -538,9 +565,10 @@ impl_script_newtype! { /// /// overflow: Wrapped(Overflow), - /// Defines the text direction. For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). + /// Defines the text direction. For example, English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). + /// + /// Note: the corresponding CSS property also affects box layout order, but this isn't yet implemented in Bevy. /// - /// Note: the corresponding CSS property also affects box layout order, but this isn't yet implemented in bevy. /// direction: Wrapped(Direction), /// The horizontal position of the left edge of the node. @@ -575,11 +603,11 @@ impl_script_newtype! { /// /// height: Wrapped(Val), - /// The minimum width of the node. `min_width` is used if it is greater than either `width` and/or `max_width`. + /// The minimum width of the node. `min_width` is used if it is greater than `width` and/or `max_width`. /// /// min_width: Wrapped(Val), - /// The minimum height of the node. `min_height` is used if it is greater than either `height` and/or `max_height`. + /// The minimum height of the node. `min_height` is used if it is greater than `height` and/or `max_height`. /// /// min_height: Wrapped(Val), @@ -595,53 +623,47 @@ impl_script_newtype! { /// /// aspect_ratio: Raw(ReflectedValue), - /// For Flexbox containers: - /// - Sets default cross-axis alignment of the child items. - /// For CSS Grid containers: - /// - Controls block (vertical) axis alignment of children of this grid container within their grid areas + /// Used to control how each individual item is aligned by default within the space they're given. + /// - For Flexbox containers, sets default cross axis alignment of the child items. + /// - For CSS Grid containers, controls block (vertical) axis alignment of children of this grid container within their grid areas. /// - /// This value is overriden [`JustifySelf`] on the child node is set. + /// This value is overridden if [`AlignSelf`] on the child node is set. /// /// align_items: Wrapped(AlignItems), - /// For Flexbox containers: - /// - This property has no effect. See `justify_content` for main-axis alignment of flex items. - /// For CSS Grid containers: - /// - Sets default inline (horizontal) axis alignment of child items within their grid areas + /// Used to control how each individual item is aligned by default within the space they're given. + /// - For Flexbox containers, this property has no effect. See `justify_content` for main axis alignment of flex items. + /// - For CSS Grid containers, sets default inline (horizontal) axis alignment of child items within their grid areas. /// - /// This value is overriden [`JustifySelf`] on the child node is set. + /// This value is overridden if [`JustifySelf`] on the child node is set. /// /// justify_items: Raw(ReflectedValue), - /// For Flexbox items: - /// - Controls cross-axis alignment of the item. - /// For CSS Grid items: - /// - Controls block (vertical) axis alignment of a grid item within it's grid area + /// Used to control how the specified item is aligned within the space it's given. + /// - For Flexbox items, controls cross axis alignment of the item. + /// - For CSS Grid items, controls block (vertical) axis alignment of a grid item within its grid area. /// /// If set to `Auto`, alignment is inherited from the value of [`AlignItems`] set on the parent node. /// /// align_self: Wrapped(AlignSelf), - /// For Flexbox items: - /// - This property has no effect. See `justify_content` for main-axis alignment of flex items. - /// For CSS Grid items: - /// - Controls inline (horizontal) axis alignment of a grid item within it's grid area. + /// Used to control how the specified item is aligned within the space it's given. + /// - For Flexbox items, this property has no effect. See `justify_content` for main axis alignment of flex items. + /// - For CSS Grid items, controls inline (horizontal) axis alignment of a grid item within its grid area. /// /// If set to `Auto`, alignment is inherited from the value of [`JustifyItems`] set on the parent node. /// - /// + /// justify_self: Raw(ReflectedValue), - /// For Flexbox containers: - /// - Controls alignment of lines if flex_wrap is set to [`FlexWrap::Wrap`] and there are multiple lines of items - /// For CSS Grid container: - /// - Controls alignment of grid rows + /// Used to control how items are distributed. + /// - For Flexbox containers, controls alignment of lines if `flex_wrap` is set to [`FlexWrap::Wrap`] and there are multiple lines of items. + /// - For CSS Grid containers, controls alignment of grid rows. /// /// align_content: Wrapped(AlignContent), - /// For Flexbox containers: - /// - Controls alignment of items in the main axis - /// For CSS Grid containers: - /// - Controls alignment of grid columns + /// Used to control how items are distributed. + /// - For Flexbox containers, controls alignment of items in the main axis. + /// - For CSS Grid containers, controls alignment of grid columns. /// /// justify_content: Wrapped(JustifyContent), @@ -662,7 +684,7 @@ impl_script_newtype! { /// ..Default::default() /// }; /// ``` - /// A node with this style and a parent with dimensions of 100px by 300px, will have calculated margins of 10px on both left and right edges, and 15px on both top and bottom edges. + /// A node with this style and a parent with dimensions of 100px by 300px will have calculated margins of 10px on both left and right edges, and 15px on both top and bottom edges. /// /// margin: Raw(ReflectedValue), @@ -683,7 +705,7 @@ impl_script_newtype! { /// ..Default::default() /// }; /// ``` - /// A node with this style and a parent with dimensions of 300px by 100px, will have calculated padding of 3px on the left, 6px on the right, 9px on the top and 12px on the bottom. + /// A node with this style and a parent with dimensions of 300px by 100px will have calculated padding of 3px on the left, 6px on the right, 9px on the top and 12px on the bottom. /// /// padding: Raw(ReflectedValue), @@ -693,15 +715,13 @@ impl_script_newtype! { /// /// The size of the node will be expanded if there are constraints that prevent the layout algorithm from placing the border within the existing node boundary. /// - /// Rendering for borders is not yet implemented. - /// /// border: Raw(ReflectedValue), - /// Whether a Flexbox container should be a row or a column. This property has no effect of Grid nodes. + /// Whether a Flexbox container should be a row or a column. This property has no effect on Grid nodes. /// /// flex_direction: Wrapped(FlexDirection), - /// Whether a Flexbox container should wrap it's contents onto multiple line wrap if they overflow. This property has no effect of Grid nodes. + /// Whether a Flexbox container should wrap its contents onto multiple lines if they overflow. This property has no effect on Grid nodes. /// /// flex_wrap: Wrapped(FlexWrap), @@ -715,24 +735,24 @@ impl_script_newtype! { flex_shrink: Raw(f32), /// The initial length of a flexbox in the main axis, before flex growing/shrinking properties are applied. /// - /// `flex_basis` overrides `size` on the main axis if both are set, but it obeys the bounds defined by `min_size` and `max_size`. + /// `flex_basis` overrides `size` on the main axis if both are set, but it obeys the bounds defined by `min_size` and `max_size`. /// /// flex_basis: Wrapped(Val), - /// The size of the gutters between items in a vertical flexbox layout or between rows in a grid layout + /// The size of the gutters between items in a vertical flexbox layout or between rows in a grid layout. /// /// Note: Values of `Val::Auto` are not valid and are treated as zero. /// /// row_gap: Wrapped(Val), - /// The size of the gutters between items in a horizontal flexbox layout or between column in a grid layout + /// The size of the gutters between items in a horizontal flexbox layout or between column in a grid layout. /// /// Note: Values of `Val::Auto` are not valid and are treated as zero. /// /// column_gap: Wrapped(Val), - /// Controls whether automatically placed grid items are placed row-wise or column-wise. And whether the sparse or dense packing algorithm is used. - /// Only affect Grid layouts + /// Controls whether automatically placed grid items are placed row-wise or column-wise as well as whether the sparse or dense packing algorithm is used. + /// Only affects Grid layouts. /// /// grid_auto_flow: Raw(ReflectedValue), @@ -752,9 +772,9 @@ impl_script_newtype! { /// grid_auto_rows: Raw(ReflectedValue), /// Defines the size of implicitly created columns. Columns are created implicitly when grid items are given explicit placements that are out of bounds - /// of the columns explicitly created using `grid_template_columms`. + /// of the columns explicitly created using `grid_template_columns`. /// - /// + /// grid_auto_columns: Raw(ReflectedValue), /// The row in which a grid item starts and how many rows it spans. /// @@ -783,10 +803,10 @@ impl_script_newtype! { Debug + Methods ( - ///flip the image along its x-axis + ///Flip the image along its x-axis with_flip_x(self:) -> self, - ///flip the image along its y-axis + ///Flip the image along its y-axis with_flip_y(self:) -> self, ) @@ -833,7 +853,7 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///Whether to use a Flexbox layout model. + ///Defines the layout model used by this node. /// ///Part of the [`Style`] component. bevy_ui::Display : @@ -861,6 +881,15 @@ impl_script_newtype! { bevy_animation::AnimationPlayer : Methods ( + ///Check if the playing animation has finished, according to the repetition behavior. + is_finished(&self:) -> Raw(bool), + + ///Number of times the animation has completed. + completions(&self:) -> Raw(u32), + + ///Check if the animation is playing in reverse. + is_playback_reversed(&self:) -> Raw(bool), + ///Pause the animation pause(&mut self:), @@ -876,6 +905,12 @@ impl_script_newtype! { ///Time elapsed playing the animation elapsed(&self:) -> Raw(f32), + ///Seek time inside of the animation. Always within the range [0.0, clip duration]. + seek_time(&self:) -> Raw(f32), + + ///Reset the animation to its initial state, as if no time has elapsed. + replay(&mut self:), + ) + Fields ( @@ -920,6 +955,9 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] + ///Additional untyped data that can be present on most glTF types. + /// + ///See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-extras). bevy_gltf::GltfExtras : Clone + Debug + @@ -928,6 +966,7 @@ impl_script_newtype! { ) + Fields ( + /// Content of the extra data. value: Raw(String), ) + BinOps @@ -1016,6 +1055,7 @@ impl_script_newtype! { ) + Fields ( + /// The maximum width and height of text in logical pixels. size: Wrapped(Vec2), ) + BinOps @@ -1120,7 +1160,18 @@ impl_script_newtype! { ) + Fields ( + /// If this is not specified, then + /// * if `default_font` feature is enabled (enabled by default in `bevy` crate), + /// `FiraMono-subset.ttf` compiled into the library is used. + /// * otherwise no text will be rendered. font: Raw(ReflectedValue), + /// The vertical height of rasterized glyphs in the font atlas in pixels. + /// + /// This is multiplied by the window scale factor and `UiScale`, but not the text entity + /// transform or camera projection. + /// + /// A new font atlas is generated for every combination of font handle and scaled font size + /// which can have a strong performance impact. font_size: Raw(f32), color: Wrapped(Color), ) @@ -1286,18 +1337,28 @@ impl_script_newtype! { Debug + Methods ( - ///Returns `true` if the timer has reached its duration at least once. - ///See also [`Timer::just_finished`](Timer::just_finished). + ///Returns `true` if the timer has reached its duration. + /// + ///For repeating timers, this method behaves identically to [`Timer::just_finished`]. /// ///# Examples ///``` ///# use bevy_time::*; ///use std::time::Duration; - ///let mut timer = Timer::from_seconds(1.0, TimerMode::Once); - ///timer.tick(Duration::from_secs_f32(1.5)); - ///assert!(timer.finished()); - ///timer.tick(Duration::from_secs_f32(0.5)); - ///assert!(timer.finished()); + /// + ///let mut timer_once = Timer::from_seconds(1.0, TimerMode::Once); + ///timer_once.tick(Duration::from_secs_f32(1.5)); + ///assert!(timer_once.finished()); + ///timer_once.tick(Duration::from_secs_f32(0.5)); + ///assert!(timer_once.finished()); + /// + ///let mut timer_repeating = Timer::from_seconds(1.0, TimerMode::Repeating); + ///timer_repeating.tick(Duration::from_secs_f32(1.1)); + ///assert!(timer_repeating.finished()); + ///timer_repeating.tick(Duration::from_secs_f32(0.8)); + ///assert!(!timer_repeating.finished()); + ///timer_repeating.tick(Duration::from_secs_f32(0.6)); + ///assert!(timer_repeating.finished()); ///``` finished(&self:) -> Raw(bool), @@ -1471,7 +1532,7 @@ impl_script_newtype! { ///# Usage /// ///This data type is returned by iterating a `Query` that has `Entity` as part of its query fetch type parameter ([learn more]). - ///It can also be obtained by calling [`EntityCommands::id`] or [`EntityMut::id`]. + ///It can also be obtained by calling [`EntityCommands::id`] or [`EntityWorldMut::id`]. /// ///``` ///# use bevy_ecs::prelude::*; @@ -1483,7 +1544,7 @@ impl_script_newtype! { ///} /// ///fn exclusive_system(world: &mut World) { - /// // Calling `spawn` returns `EntityMut`. + /// // Calling `spawn` returns `EntityWorldMut`. /// let entity = world.spawn(SomeComponent).id(); ///} ///# @@ -1510,7 +1571,7 @@ impl_script_newtype! { /// ///[learn more]: crate::system::Query#entity-id-access ///[`EntityCommands::id`]: crate::system::EntityCommands::id - ///[`EntityMut::id`]: crate::world::EntityMut::id + ///[`EntityWorldMut::id`]: crate::world::EntityWorldMut::id ///[`EntityCommands`]: crate::system::EntityCommands ///[`Query::get`]: crate::system::Query::get ///[`World`]: crate::world::World @@ -1754,7 +1815,7 @@ impl_script_newtype! { ///and [`Transform::up`] points towards `up`. /// ///In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: - ///* if `target` is the same as the transtorm translation, `Vec3::Z` is used instead + ///* if `target` is the same as the transform translation, `Vec3::Z` is used instead ///* if `up` is zero, `Vec3::Y` is used instead ///* if the resulting forward direction is parallel with `up`, an orthogonal vector is used as the "right" direction look_at(&mut self:Wrapped(Vec3),Wrapped(Vec3)), @@ -1808,6 +1869,7 @@ impl_script_newtype! { ) + BinOps ( + self Mul Wrapped(GlobalTransform) -> Wrapped(GlobalTransform), self Mul Wrapped(Transform) -> Wrapped(Transform), self Mul Wrapped(Vec3) -> Wrapped(Vec3), ) @@ -1942,9 +2004,9 @@ impl_script_newtype! { ) + BinOps ( - self Mul Wrapped(Transform) -> Wrapped(GlobalTransform), - self Mul Wrapped(GlobalTransform) -> Wrapped(GlobalTransform), self Mul Wrapped(Vec3) -> Wrapped(Vec3), + self Mul Wrapped(GlobalTransform) -> Wrapped(GlobalTransform), + self Mul Wrapped(Transform) -> Wrapped(GlobalTransform), ) + UnaryOps ( @@ -2121,6 +2183,10 @@ impl_script_newtype! { impl_script_newtype! { #[languages(on_feature(lua))] ///Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not receive shadows. + /// + ///**Note:** If you're using diffuse transmission, setting [`NotShadowReceiver`] will + ///cause both “regular” shadows as well as diffusely transmitted shadows to be disabled, + ///even when [`TransmittedShadowReceiver`] is being used. bevy_pbr::NotShadowReceiver : Methods ( @@ -2166,6 +2232,7 @@ impl_script_newtype! { + Fields ( color: Wrapped(Color), + /// Luminous power in lumens intensity: Raw(f32), range: Raw(f32), radius: Raw(f32), @@ -2232,7 +2299,10 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///Controls whether an entity should rendered in wireframe-mode if the [`WireframePlugin`] is enabled + ///Enables wireframe rendering for any entity it is attached to. + ///It will ignore the [`WireframeConfig`] global setting. + /// + ///This requires the [`WireframePlugin`] to be enabled. bevy_pbr::wireframe::Wireframe : Clone + Debug + @@ -2262,8 +2332,13 @@ impl_script_newtype! { ) + Fields ( - /// Whether to show wireframes for all meshes. If `false`, only meshes with a [Wireframe] component will be rendered. + /// Whether to show wireframes for all meshes. + /// Can be overridden for individual meshes by adding a [`Wireframe`] or [`NoWireframe`] component. global: Raw(bool), + /// If [`Self::global`] is set, any [`Entity`] that does not have a [`Wireframe`] component attached to it will have + /// wireframes using this color. Otherwise, this will be the fallback color for any entity that has a [`Wireframe`], + /// but no [`WireframeColor`]. + default_color: Wrapped(Color), ) + BinOps ( @@ -2324,6 +2399,7 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] + ///For a camera, specifies the color used to clear the viewport before rendering. bevy_core_pipeline::clear_color::ClearColorConfig : Clone + Debug + @@ -2380,6 +2456,31 @@ impl_script_newtype! { depth_load_op: Wrapped(Camera3dDepthLoadOp), /// The texture usages for the depth texture created for the main 3d pass. depth_texture_usages: Raw(ReflectedValue), + /// How many individual steps should be performed in the [`Transmissive3d`](crate::core_3d::Transmissive3d) pass. + /// + /// Roughly corresponds to how many “layers of transparency” are rendered for screen space + /// specular transmissive objects. Each step requires making one additional + /// texture copy, so it's recommended to keep this number to a resonably low value. Defaults to `1`. + /// + /// ### Notes + /// + /// - No copies will be performed if there are no transmissive materials currently being rendered, + /// regardless of this setting. + /// - Setting this to `0` disables the screen-space refraction effect entirely, and falls + /// back to refracting only the environment map light's texture. + /// - If set to more than `0`, any opaque [`clear_color`](Camera3d::clear_color) will obscure the environment + /// map light's texture, preventing it from being visible “through” transmissive materials. If you'd like + /// to still have the environment map show up in your refractions, you can set the clear color's alpha to `0.0`. + /// Keep in mind that depending on the platform and your window settings, this may cause the window to become + /// transparent. + screen_space_specular_transmission_steps: Raw(usize), + /// The quality of the screen space specular transmission blur effect, applied to whatever's “behind” transmissive + /// objects when their `roughness` is greater than `0.0`. + /// + /// Higher qualities are more GPU-intensive. + /// + /// **Note:** You can get better-looking results at any quality level by enabling TAA. See: [`TemporalAntiAliasPlugin`](crate::experimental::taa::TemporalAntiAliasPlugin). + screen_space_specular_transmission_quality: Raw(ReflectedValue), ) + BinOps ( @@ -2569,7 +2670,7 @@ impl_script_newtype! { ///are set to [`Inherited`](Self::Inherited) will also be hidden. /// ///This is done by the `visibility_propagate_system` which uses the entity hierarchy and - ///`Visibility` to set the values of each entity's [`ComputedVisibility`] component. + ///`Visibility` to set the values of each entity's [`InheritedVisibility`] component. bevy_render::view::visibility::Visibility : Clone + Debug + @@ -2594,15 +2695,12 @@ impl_script_newtype! { ///Collection of entities visible from the current view. /// ///This component contains all entities which are visible from the currently - ///rendered view. The collection is updated automatically by the [`check_visibility()`] - ///system, and renderers can use it to optimize rendering of a particular view, to + ///rendered view. The collection is updated automatically by the [`VisibilitySystems::CheckVisibility`] + ///system set, and renderers can use it to optimize rendering of a particular view, to ///prevent drawing items not visible from that view. /// ///This component is intended to be attached to the same entity as the [`Camera`] and ///the [`Frustum`] defining the view. - /// - ///Currently this component is ignored by the sprite renderer, so sprite rendering - ///is not optimized per view. bevy_render::view::visibility::VisibleEntities : Clone + Debug + @@ -2628,37 +2726,69 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering - bevy_render::view::visibility::ComputedVisibility : + ///Whether or not an entity is visible in the hierarchy. + ///This will not be accurate until [`VisibilityPropagate`] runs in the [`PostUpdate`] schedule. + /// + ///If this is false, then [`ViewVisibility`] should also be false. + /// + ///[`VisibilityPropagate`]: VisibilitySystems::VisibilityPropagate + bevy_render::view::visibility::InheritedVisibility : Clone + Debug + Methods ( - ///Whether this entity is visible to something this frame. This is true if and only if [`Self::is_visible_in_hierarchy`] and [`Self::is_visible_in_view`] - ///are true. This is the canonical method to call to determine if an entity should be drawn. - ///This value is updated in [`PostUpdate`] by the [`VisibilitySystems::CheckVisibility`] system set. - ///Reading it during [`Update`](bevy_app::Update) will yield the value from the previous frame. - is_visible(&self:) -> Raw(bool), + ///Returns `true` if the entity is visible in the hierarchy. + ///Otherwise, returns `false`. + get(self:) -> Raw(bool), - ///Whether this entity is visible in the entity hierarchy, which is determined by the [`Visibility`] component. - ///This takes into account "visibility inheritance". If any of this entity's ancestors (see [`Parent`]) are hidden, this entity - ///will be hidden as well. This value is updated in the [`VisibilitySystems::VisibilityPropagate`], which lives in the [`PostUpdate`] schedule. - is_visible_in_hierarchy(&self:) -> Raw(bool), + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + lua impl + { + } +} +impl_script_newtype! { + #[languages(on_feature(lua))] + ///Algorithmically-computed indication or whether an entity is visible and should be extracted for rendering. + /// + ///Each frame, this will be reset to `false` during [`VisibilityPropagate`] systems in [`PostUpdate`]. + ///Later in the frame, systems in [`CheckVisibility`] will mark any visible entities using [`ViewVisibility::set`]. + ///Because of this, values of this type will be marked as changed every frame, even when they do not change. + /// + ///If you wish to add custom visibility system that sets this value, make sure you add it to the [`CheckVisibility`] set. + /// + ///[`VisibilityPropagate`]: VisibilitySystems::VisibilityPropagate + ///[`CheckVisibility`]: VisibilitySystems::CheckVisibility + bevy_render::view::visibility::ViewVisibility : + Clone + + Debug + + Methods + ( + ///Returns `true` if the entity is visible in any view. + ///Otherwise, returns `false`. + get(self:) -> Raw(bool), - ///Whether this entity is visible in _any_ view (Cameras, Lights, etc). Each entity type (and view type) should choose how to set this - ///value. For cameras and drawn entities, this will take into account [`RenderLayers`]. + ///Sets the visibility to `true`. This should not be considered reversible for a given frame, + ///as this component tracks whether or not the entity visible in _any_ view. /// - ///This value is reset to `false` every frame in [`VisibilitySystems::VisibilityPropagate`] during [`PostUpdate`]. - ///Each entity type then chooses how to set this field in the [`VisibilitySystems::CheckVisibility`] system set, in [`PostUpdate`]. - ///Meshes might use frustum culling to decide if they are visible in a view. - ///Other entities might just set this to `true` every frame. - is_visible_in_view(&self:) -> Raw(bool), - - ///Sets `is_visible_in_view` to `true`. This is not reversible for a given frame, as it encodes whether or not this is visible in - ///_any_ view. This will be automatically reset to `false` every frame in [`VisibilitySystems::VisibilityPropagate`] and then set - ///to the proper value in [`VisibilitySystems::CheckVisibility`]. This should _only_ be set in systems with the [`VisibilitySystems::CheckVisibility`] - ///label. Don't call this unless you are defining a custom visibility system. For normal user-defined entity visibility, see [`Visibility`]. - set_visible_in_view(&mut self:), + ///This will be automatically reset to `false` every frame in [`VisibilityPropagate`] and then set + ///to the proper value in [`CheckVisibility`]. + /// + ///You should only manually set this if you are defining a custom visibility system, + ///in which case the system should be placed in the [`CheckVisibility`] set. + ///For normal user-defined entity visibility, see [`Visibility`]. + /// + ///[`VisibilityPropagate`]: VisibilitySystems::VisibilityPropagate + ///[`CheckVisibility`]: VisibilitySystems::CheckVisibility + set(&mut self:), ) + Fields @@ -2840,30 +2970,64 @@ impl_script_newtype! { ///See also [`Color::rgba`], [`Color::rgb_u8`], [`Color::hex`]. rgba_u8(Raw(u8),Raw(u8),Raw(u8),Raw(u8)) -> Wrapped(Color), - ///Get red in sRGB colorspace. + ///Converts a Color to variant [`Color::Rgba`] and return red in sRGB colorspace r(&self:) -> Raw(f32), - ///Get green in sRGB colorspace. + ///Converts a Color to variant [`Color::Rgba`] and return green in sRGB colorspace g(&self:) -> Raw(f32), - ///Get blue in sRGB colorspace. + ///Converts a Color to variant [`Color::Rgba`] and return blue in sRGB colorspace b(&self:) -> Raw(f32), - ///Returns this color with red set to a new value in sRGB colorspace. + ///Converts a Color to variant [`Color::Rgba`] and return this color with red set to a new value with_r(self:Raw(f32)) -> self, - ///Returns this color with green set to a new value in sRGB colorspace. + ///Converts a Color to variant [`Color::Rgba`] and return this color with green set to a new value with_g(self:Raw(f32)) -> self, - ///Returns this color with blue set to a new value in sRGB colorspace. + ///Converts a Color to variant [`Color::Rgba`] and return this color with blue set to a new value with_b(self:Raw(f32)) -> self, + ///Converts a Color to variant [`Color::Hsla`] and return hue + h(&self:) -> Raw(f32), + + ///Converts a Color to variant [`Color::Hsla`] and return saturation + s(&self:) -> Raw(f32), + + ///Converts a Color to variant [`Color::Hsla`] and return lightness + l(&self:) -> Raw(f32), + + ///Converts a Color to variant [`Color::Hsla`] and return this color with hue set to a new value + with_h(self:Raw(f32)) -> self, + + ///Converts a Color to variant [`Color::Hsla`] and return this color with saturation set to a new value + with_s(self:Raw(f32)) -> self, + + ///Converts a Color to variant [`Color::Hsla`] and return this color with lightness set to a new value + with_l(self:Raw(f32)) -> self, + ///Get alpha. a(&self:) -> Raw(f32), ///Returns this color with a new alpha value. with_a(self:Raw(f32)) -> self, + ///Determine if the color is fully transparent, i.e. if the alpha is 0. + /// + ///# Examples + /// + ///``` + ///# use bevy_render::color::Color; + ///// Fully transparent colors + ///assert!(Color::NONE.is_fully_transparent()); + ///assert!(Color::rgba(1.0, 0.5, 0.5, 0.0).is_fully_transparent()); + /// + ///// (Partially) opaque colors + ///assert!(!Color::BLACK.is_fully_transparent()); + ///assert!(!Color::rgba(1.0, 0.5, 0.5, 0.2).is_fully_transparent()); + ///``` + is_fully_transparent(&self:) -> Raw(bool), + ///Converts a `Color` to variant `Color::Rgba` as_rgba(Wrapped(&Color):) -> Wrapped(Color), @@ -2894,11 +3058,11 @@ impl_script_newtype! { ) + BinOps ( - self Add Wrapped(Vec4) -> Wrapped(Color), self Add Wrapped(Color) -> Wrapped(Color), + self Add Wrapped(Vec4) -> Wrapped(Color), + self Mul Wrapped(Vec4) -> Wrapped(Color), self Mul Wrapped(Vec3) -> Wrapped(Color), self Mul Raw(f32) -> Wrapped(Color), - self Mul Wrapped(Vec4) -> Wrapped(Color), ) + UnaryOps ( @@ -2909,7 +3073,32 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///An axis-aligned bounding box. + ///An axis-aligned bounding box, defined by: + ///- a center, + ///- the distances from the center to each faces along the axis, + ///the faces are orthogonal to the axis. + /// + ///It is typically used as a component on an entity to represent the local space + ///occupied by this entity, with faces orthogonal to its local axis. + /// + ///This component is notably used during "frustum culling", a process to determine + ///if an entity should be rendered by a [`Camera`] if its bounding box intersects + ///with the camera's [`Frustum`]. + /// + ///It will be added automatically by the systems in [`CalculateBounds`] to entities that: + ///- could be subject to frustum culling, for example with a [`Handle`] + ///or `Sprite` component, + ///- don't have the [`NoFrustumCulling`] component. + /// + ///It won't be updated automatically if the space occupied by the entity changes, + ///for example if the vertex positions of a [`Mesh`] inside a `Handle` are + ///updated. + /// + ///[`Camera`]: crate::camera::Camera + ///[`NoFrustumCulling`]: crate::view::visibility::NoFrustumCulling + ///[`CalculateBounds`]: crate::view::visibility::VisibilitySystems::CalculateBounds + ///[`Mesh`]: crate::mesh::Mesh + ///[`Handle`]: crate::mesh::Mesh bevy_render::primitives::Aabb : Clone + Debug + @@ -2917,6 +3106,9 @@ impl_script_newtype! { ( from_min_max(Wrapped(Vec3),Wrapped(Vec3)) -> self, + ///Calculate the relative radius of the AABB with respect to a plane + relative_radius(&self:Wrapped(&Vec3A),Wrapped(&Mat3A)) -> Raw(f32), + min(&self:) -> Wrapped(Vec3A), max(&self:) -> Wrapped(Vec3A), @@ -2959,9 +3151,31 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///A frustum made up of the 6 defining half spaces. - ///Half spaces are ordered left, right, top, bottom, near, far. - ///The normal vectors of the half spaces point towards the interior of the frustum. + ///A region of 3D space defined by the intersection of 6 [`HalfSpace`]s. + /// + ///Frustums are typically an apex-truncated square pyramid (a pyramid without the top) or a cuboid. + /// + ///Half spaces are ordered left, right, top, bottom, near, far. The normal vectors + ///of the half-spaces point towards the interior of the frustum. + /// + ///A frustum component is used on an entity with a [`Camera`] component to + ///determine which entities will be considered for rendering by this camera. + ///All entities with an [`Aabb`] component that are not contained by (or crossing + ///the boundary of) the frustum will not be rendered, and not be used in rendering computations. + /// + ///This process is called frustum culling, and entities can opt out of it using + ///the [`NoFrustumCulling`] component. + /// + ///The frustum component is typically added from a bundle, either the `Camera2dBundle` + ///or the `Camera3dBundle`. + ///It is usually updated automatically by [`update_frusta`] from the + ///[`CameraProjection`] component and [`GlobalTransform`] of the camera entity. + /// + ///[`Camera`]: crate::camera::Camera + ///[`NoFrustumCulling`]: crate::view::visibility::NoFrustumCulling + ///[`update_frusta`]: crate::view::visibility::update_frusta + ///[`CameraProjection`]: crate::camera::CameraProjection + ///[`GlobalTransform`]: bevy_transform::components::GlobalTransform bevy_render::primitives::Frustum : Clone + Debug + @@ -2975,7 +3189,7 @@ impl_script_newtype! { from_view_projection_custom_far(Wrapped(&Mat4),Wrapped(&Vec3),Wrapped(&Vec3),Raw(f32)) -> self, ///Checks if an Oriented Bounding Box (obb) intersects the frustum. - intersects_obb(&self:Wrapped(&Aabb),Wrapped(&Mat4),Raw(bool),Raw(bool)) -> Raw(bool), + intersects_obb(&self:Wrapped(&Aabb),Wrapped(&Affine3A),Raw(bool),Raw(bool)) -> Raw(bool), ) + Fields @@ -3083,7 +3297,7 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///The "target" that a [`Camera`] will render to. For example, this could be a [`Window`](bevy_window::Window) + ///The "target" that a [`Camera`] will render to. For example, this could be a [`Window`] ///swapchain or an [`Image`]. bevy_render::camera::RenderTarget : Clone + @@ -3218,7 +3432,7 @@ impl_script_newtype! { viewport_origin: Wrapped(Vec2), /// How the projection will scale when the viewport is resized. /// - /// Defaults to `ScalingMode::WindowScale(1.0)` + /// Defaults to `ScalingMode::WindowSize(1.0)` scaling_mode: Wrapped(ScalingMode), /// Scales the projection in world units. /// @@ -3319,80 +3533,9 @@ impl_script_newtype! { } impl_script_newtype! { #[languages(on_feature(lua))] - ///An unique identifier to an asset path. - bevy_asset::AssetPathId : - Clone + - Debug + - Methods - ( - ///Gets the id of the source path. - source_path_id(&self:) -> Wrapped(SourcePathId), - - ///Gets the id of the sub-asset label. - label_id(&self:) -> Wrapped(LabelId), - - ) - + Fields - ( - ) - + BinOps - ( - ) - + UnaryOps - ( - ) - lua impl - { - } -} -impl_script_newtype! { - #[languages(on_feature(lua))] - ///An unique identifier to a sub-asset label. - bevy_asset::LabelId : - Clone + - Debug + - Methods - ( - ) - + Fields - ( - ) - + BinOps - ( - ) - + UnaryOps - ( - ) - lua impl - { - } -} -impl_script_newtype! { - #[languages(on_feature(lua))] - ///An unique identifier to the source path of an asset. - bevy_asset::SourcePathId : - Clone + - Debug + - Methods - ( - ) - + Fields - ( - ) - + BinOps - ( - ) - + UnaryOps - ( - ) - lua impl - { - } -} -impl_script_newtype! { - #[languages(on_feature(lua))] - ///A unique, stable asset id. - bevy_asset::HandleId : + ///A generational runtime-only identifier for a specific [`Asset`] stored in [`Assets`]. This is optimized for efficient runtime + ///usage and is not suitable for identifying assets across app runs. + bevy_asset::AssetIndex : Clone + Debug + Methods @@ -3740,21 +3883,21 @@ impl_script_newtype! { ) + BinOps ( - self Add Raw(f32) -> Wrapped(Vec2), - self Add Wrapped(Vec2) -> Wrapped(Vec2), self Add self -> Wrapped(Vec2), + self Add Wrapped(Vec2) -> Wrapped(Vec2), + self Add Raw(f32) -> Wrapped(Vec2), self Sub Wrapped(Vec2) -> Wrapped(Vec2), - self Sub Raw(f32) -> Wrapped(Vec2), self Sub self -> Wrapped(Vec2), + self Sub Raw(f32) -> Wrapped(Vec2), + self Div self -> Wrapped(Vec2), self Div Wrapped(Vec2) -> Wrapped(Vec2), self Div Raw(f32) -> Wrapped(Vec2), - self Div self -> Wrapped(Vec2), - self Mul Raw(f32) -> Wrapped(Vec2), self Mul Wrapped(Vec2) -> Wrapped(Vec2), + self Mul Raw(f32) -> Wrapped(Vec2), self Mul self -> Wrapped(Vec2), + self Rem Wrapped(Vec2) -> Wrapped(Vec2), self Rem self -> Wrapped(Vec2), self Rem Raw(f32) -> Wrapped(Vec2), - self Rem Wrapped(Vec2) -> Wrapped(Vec2), ) + UnaryOps ( @@ -4103,21 +4246,21 @@ impl_script_newtype! { ) + BinOps ( - self Add self -> Wrapped(Vec3), - self Add Wrapped(Vec3) -> Wrapped(Vec3), self Add Raw(f32) -> Wrapped(Vec3), + self Add Wrapped(Vec3) -> Wrapped(Vec3), + self Add self -> Wrapped(Vec3), self Sub Raw(f32) -> Wrapped(Vec3), self Sub self -> Wrapped(Vec3), self Sub Wrapped(Vec3) -> Wrapped(Vec3), self Div Wrapped(Vec3) -> Wrapped(Vec3), self Div Raw(f32) -> Wrapped(Vec3), self Div self -> Wrapped(Vec3), - self Mul self -> Wrapped(Vec3), self Mul Wrapped(Vec3) -> Wrapped(Vec3), self Mul Raw(f32) -> Wrapped(Vec3), + self Mul self -> Wrapped(Vec3), self Rem self -> Wrapped(Vec3), - self Rem Wrapped(Vec3) -> Wrapped(Vec3), self Rem Raw(f32) -> Wrapped(Vec3), + self Rem Wrapped(Vec3) -> Wrapped(Vec3), ) + UnaryOps ( @@ -4471,15 +4614,15 @@ impl_script_newtype! { ) + BinOps ( + self Add self -> Wrapped(Vec3A), self Add Wrapped(Vec3A) -> Wrapped(Vec3A), self Add Raw(f32) -> Wrapped(Vec3A), - self Add self -> Wrapped(Vec3A), self Sub Wrapped(Vec3A) -> Wrapped(Vec3A), self Sub self -> Wrapped(Vec3A), self Sub Raw(f32) -> Wrapped(Vec3A), - self Div Raw(f32) -> Wrapped(Vec3A), self Div self -> Wrapped(Vec3A), self Div Wrapped(Vec3A) -> Wrapped(Vec3A), + self Div Raw(f32) -> Wrapped(Vec3A), self Mul self -> Wrapped(Vec3A), self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), self Mul Raw(f32) -> Wrapped(Vec3A), @@ -4809,21 +4952,21 @@ impl_script_newtype! { ) + BinOps ( + self Add self -> Wrapped(Vec4), self Add Raw(f32) -> Wrapped(Vec4), self Add Wrapped(Vec4) -> Wrapped(Vec4), - self Add self -> Wrapped(Vec4), - self Sub Raw(f32) -> Wrapped(Vec4), - self Sub self -> Wrapped(Vec4), self Sub Wrapped(Vec4) -> Wrapped(Vec4), + self Sub self -> Wrapped(Vec4), + self Sub Raw(f32) -> Wrapped(Vec4), + self Div Wrapped(Vec4) -> Wrapped(Vec4), self Div Raw(f32) -> Wrapped(Vec4), self Div self -> Wrapped(Vec4), - self Div Wrapped(Vec4) -> Wrapped(Vec4), - self Mul Raw(f32) -> Wrapped(Vec4), self Mul self -> Wrapped(Vec4), + self Mul Raw(f32) -> Wrapped(Vec4), self Mul Wrapped(Vec4) -> Wrapped(Vec4), - self Rem self -> Wrapped(Vec4), self Rem Wrapped(Vec4) -> Wrapped(Vec4), self Rem Raw(f32) -> Wrapped(Vec4), + self Rem self -> Wrapped(Vec4), ) + UnaryOps ( @@ -5427,20 +5570,20 @@ impl_script_newtype! { ) + BinOps ( + self Add Wrapped(DVec2) -> Wrapped(DVec2), self Add self -> Wrapped(DVec2), self Add Raw(f64) -> Wrapped(DVec2), - self Add Wrapped(DVec2) -> Wrapped(DVec2), + self Sub self -> Wrapped(DVec2), self Sub Raw(f64) -> Wrapped(DVec2), self Sub Wrapped(DVec2) -> Wrapped(DVec2), - self Sub self -> Wrapped(DVec2), + self Div Raw(f64) -> Wrapped(DVec2), self Div self -> Wrapped(DVec2), self Div Wrapped(DVec2) -> Wrapped(DVec2), - self Div Raw(f64) -> Wrapped(DVec2), + self Mul Raw(f64) -> Wrapped(DVec2), self Mul Wrapped(DVec2) -> Wrapped(DVec2), self Mul self -> Wrapped(DVec2), - self Mul Raw(f64) -> Wrapped(DVec2), - self Rem self -> Wrapped(DVec2), self Rem Raw(f64) -> Wrapped(DVec2), + self Rem self -> Wrapped(DVec2), self Rem Wrapped(DVec2) -> Wrapped(DVec2), ) + UnaryOps @@ -5796,18 +5939,18 @@ impl_script_newtype! { self Add Raw(f64) -> Wrapped(DVec3), self Add Wrapped(DVec3) -> Wrapped(DVec3), self Add self -> Wrapped(DVec3), - self Sub Wrapped(DVec3) -> Wrapped(DVec3), - self Sub self -> Wrapped(DVec3), self Sub Raw(f64) -> Wrapped(DVec3), - self Div Raw(f64) -> Wrapped(DVec3), + self Sub self -> Wrapped(DVec3), + self Sub Wrapped(DVec3) -> Wrapped(DVec3), self Div Wrapped(DVec3) -> Wrapped(DVec3), self Div self -> Wrapped(DVec3), - self Mul Raw(f64) -> Wrapped(DVec3), + self Div Raw(f64) -> Wrapped(DVec3), self Mul self -> Wrapped(DVec3), + self Mul Raw(f64) -> Wrapped(DVec3), self Mul Wrapped(DVec3) -> Wrapped(DVec3), self Rem Raw(f64) -> Wrapped(DVec3), - self Rem self -> Wrapped(DVec3), self Rem Wrapped(DVec3) -> Wrapped(DVec3), + self Rem self -> Wrapped(DVec3), ) + UnaryOps ( @@ -6129,18 +6272,18 @@ impl_script_newtype! { ) + BinOps ( - self Add Raw(f64) -> Wrapped(DVec4), self Add self -> Wrapped(DVec4), self Add Wrapped(DVec4) -> Wrapped(DVec4), + self Add Raw(f64) -> Wrapped(DVec4), self Sub Raw(f64) -> Wrapped(DVec4), self Sub Wrapped(DVec4) -> Wrapped(DVec4), self Sub self -> Wrapped(DVec4), - self Div Wrapped(DVec4) -> Wrapped(DVec4), self Div self -> Wrapped(DVec4), + self Div Wrapped(DVec4) -> Wrapped(DVec4), self Div Raw(f64) -> Wrapped(DVec4), - self Mul Wrapped(DVec4) -> Wrapped(DVec4), - self Mul Raw(f64) -> Wrapped(DVec4), self Mul self -> Wrapped(DVec4), + self Mul Raw(f64) -> Wrapped(DVec4), + self Mul Wrapped(DVec4) -> Wrapped(DVec4), self Rem Raw(f64) -> Wrapped(DVec4), self Rem self -> Wrapped(DVec4), self Rem Wrapped(DVec4) -> Wrapped(DVec4), @@ -6308,19 +6451,19 @@ impl_script_newtype! { + BinOps ( self Add self -> Wrapped(IVec2), - self Add Wrapped(IVec2) -> Wrapped(IVec2), self Add Raw(i32) -> Wrapped(IVec2), + self Add Wrapped(IVec2) -> Wrapped(IVec2), + self Sub self -> Wrapped(IVec2), self Sub Wrapped(IVec2) -> Wrapped(IVec2), self Sub Raw(i32) -> Wrapped(IVec2), - self Sub self -> Wrapped(IVec2), - self Div Raw(i32) -> Wrapped(IVec2), self Div Wrapped(IVec2) -> Wrapped(IVec2), self Div self -> Wrapped(IVec2), + self Div Raw(i32) -> Wrapped(IVec2), + self Mul Raw(i32) -> Wrapped(IVec2), self Mul self -> Wrapped(IVec2), self Mul Wrapped(IVec2) -> Wrapped(IVec2), - self Mul Raw(i32) -> Wrapped(IVec2), - self Rem self -> Wrapped(IVec2), self Rem Raw(i32) -> Wrapped(IVec2), + self Rem self -> Wrapped(IVec2), self Rem Wrapped(IVec2) -> Wrapped(IVec2), ) + UnaryOps @@ -6485,21 +6628,21 @@ impl_script_newtype! { ) + BinOps ( - self Add Raw(i32) -> Wrapped(IVec3), - self Add Wrapped(IVec3) -> Wrapped(IVec3), self Add self -> Wrapped(IVec3), + self Add Wrapped(IVec3) -> Wrapped(IVec3), + self Add Raw(i32) -> Wrapped(IVec3), self Sub Raw(i32) -> Wrapped(IVec3), - self Sub self -> Wrapped(IVec3), self Sub Wrapped(IVec3) -> Wrapped(IVec3), + self Sub self -> Wrapped(IVec3), self Div Raw(i32) -> Wrapped(IVec3), - self Div self -> Wrapped(IVec3), self Div Wrapped(IVec3) -> Wrapped(IVec3), - self Mul Wrapped(IVec3) -> Wrapped(IVec3), - self Mul self -> Wrapped(IVec3), + self Div self -> Wrapped(IVec3), self Mul Raw(i32) -> Wrapped(IVec3), + self Mul self -> Wrapped(IVec3), + self Mul Wrapped(IVec3) -> Wrapped(IVec3), self Rem Raw(i32) -> Wrapped(IVec3), - self Rem Wrapped(IVec3) -> Wrapped(IVec3), self Rem self -> Wrapped(IVec3), + self Rem Wrapped(IVec3) -> Wrapped(IVec3), ) + UnaryOps ( @@ -6655,20 +6798,20 @@ impl_script_newtype! { ) + BinOps ( - self Add Wrapped(IVec4) -> Wrapped(IVec4), self Add self -> Wrapped(IVec4), self Add Raw(i32) -> Wrapped(IVec4), + self Add Wrapped(IVec4) -> Wrapped(IVec4), self Sub self -> Wrapped(IVec4), - self Sub Wrapped(IVec4) -> Wrapped(IVec4), self Sub Raw(i32) -> Wrapped(IVec4), - self Div self -> Wrapped(IVec4), + self Sub Wrapped(IVec4) -> Wrapped(IVec4), self Div Wrapped(IVec4) -> Wrapped(IVec4), self Div Raw(i32) -> Wrapped(IVec4), + self Div self -> Wrapped(IVec4), + self Mul Raw(i32) -> Wrapped(IVec4), self Mul self -> Wrapped(IVec4), self Mul Wrapped(IVec4) -> Wrapped(IVec4), - self Mul Raw(i32) -> Wrapped(IVec4), - self Rem Raw(i32) -> Wrapped(IVec4), self Rem Wrapped(IVec4) -> Wrapped(IVec4), + self Rem Raw(i32) -> Wrapped(IVec4), self Rem self -> Wrapped(IVec4), ) + UnaryOps @@ -6802,21 +6945,21 @@ impl_script_newtype! { ) + BinOps ( - self Add Raw(u32) -> Wrapped(UVec2), self Add Wrapped(UVec2) -> Wrapped(UVec2), self Add self -> Wrapped(UVec2), + self Add Raw(u32) -> Wrapped(UVec2), + self Sub Raw(u32) -> Wrapped(UVec2), self Sub self -> Wrapped(UVec2), self Sub Wrapped(UVec2) -> Wrapped(UVec2), - self Sub Raw(u32) -> Wrapped(UVec2), self Div self -> Wrapped(UVec2), - self Div Raw(u32) -> Wrapped(UVec2), self Div Wrapped(UVec2) -> Wrapped(UVec2), + self Div Raw(u32) -> Wrapped(UVec2), self Mul Wrapped(UVec2) -> Wrapped(UVec2), - self Mul Raw(u32) -> Wrapped(UVec2), self Mul self -> Wrapped(UVec2), + self Mul Raw(u32) -> Wrapped(UVec2), + self Rem Wrapped(UVec2) -> Wrapped(UVec2), self Rem self -> Wrapped(UVec2), self Rem Raw(u32) -> Wrapped(UVec2), - self Rem Wrapped(UVec2) -> Wrapped(UVec2), ) + UnaryOps ( @@ -6960,18 +7103,18 @@ impl_script_newtype! { ) + BinOps ( - self Add Wrapped(UVec3) -> Wrapped(UVec3), - self Add Raw(u32) -> Wrapped(UVec3), self Add self -> Wrapped(UVec3), + self Add Raw(u32) -> Wrapped(UVec3), + self Add Wrapped(UVec3) -> Wrapped(UVec3), self Sub Wrapped(UVec3) -> Wrapped(UVec3), self Sub Raw(u32) -> Wrapped(UVec3), self Sub self -> Wrapped(UVec3), - self Div self -> Wrapped(UVec3), self Div Raw(u32) -> Wrapped(UVec3), self Div Wrapped(UVec3) -> Wrapped(UVec3), - self Mul Wrapped(UVec3) -> Wrapped(UVec3), + self Div self -> Wrapped(UVec3), self Mul Raw(u32) -> Wrapped(UVec3), self Mul self -> Wrapped(UVec3), + self Mul Wrapped(UVec3) -> Wrapped(UVec3), self Rem Raw(u32) -> Wrapped(UVec3), self Rem self -> Wrapped(UVec3), self Rem Wrapped(UVec3) -> Wrapped(UVec3), @@ -7111,20 +7254,20 @@ impl_script_newtype! { + BinOps ( self Add self -> Wrapped(UVec4), - self Add Wrapped(UVec4) -> Wrapped(UVec4), self Add Raw(u32) -> Wrapped(UVec4), + self Add Wrapped(UVec4) -> Wrapped(UVec4), self Sub self -> Wrapped(UVec4), self Sub Wrapped(UVec4) -> Wrapped(UVec4), self Sub Raw(u32) -> Wrapped(UVec4), self Div self -> Wrapped(UVec4), - self Div Raw(u32) -> Wrapped(UVec4), self Div Wrapped(UVec4) -> Wrapped(UVec4), - self Mul Wrapped(UVec4) -> Wrapped(UVec4), + self Div Raw(u32) -> Wrapped(UVec4), self Mul self -> Wrapped(UVec4), self Mul Raw(u32) -> Wrapped(UVec4), + self Mul Wrapped(UVec4) -> Wrapped(UVec4), + self Rem Wrapped(UVec4) -> Wrapped(UVec4), self Rem self -> Wrapped(UVec4), self Rem Raw(u32) -> Wrapped(UVec4), - self Rem Wrapped(UVec4) -> Wrapped(UVec4), ) + UnaryOps ( @@ -7339,12 +7482,12 @@ impl_script_newtype! { ( self Add self -> Wrapped(Mat3), self Sub self -> Wrapped(Mat3), + self Mul self -> Wrapped(Mat3), self Mul Wrapped(Mat3) -> Wrapped(Mat3), + self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), self Mul Wrapped(Affine2) -> Wrapped(Mat3), self Mul Raw(f32) -> Wrapped(Mat3), - self Mul self -> Wrapped(Mat3), self Mul Wrapped(Vec3) -> Wrapped(Vec3), - self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), ) + UnaryOps ( @@ -7368,7 +7511,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) } } }) @@ -7481,9 +7624,9 @@ impl_script_newtype! { ( self Add self -> Wrapped(Mat2), self Sub self -> Wrapped(Mat2), - self Mul Wrapped(Vec2) -> Wrapped(Vec2), - self Mul Wrapped(Mat2) -> Wrapped(Mat2), self Mul Raw(f32) -> Wrapped(Mat2), + self Mul Wrapped(Mat2) -> Wrapped(Mat2), + self Mul Wrapped(Vec2) -> Wrapped(Vec2), self Mul self -> Wrapped(Mat2), ) + UnaryOps @@ -7508,7 +7651,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat2".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat2".into()}) } } }) @@ -7723,8 +7866,8 @@ impl_script_newtype! { self Add self -> Wrapped(Mat3A), self Sub self -> Wrapped(Mat3A), self Mul Wrapped(Mat3A) -> Wrapped(Mat3A), - self Mul Wrapped(Affine2) -> Wrapped(Mat3A), self Mul Wrapped(Vec3) -> Wrapped(Vec3), + self Mul Wrapped(Affine2) -> Wrapped(Mat3A), self Mul Raw(f32) -> Wrapped(Mat3A), self Mul self -> Wrapped(Mat3A), self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), @@ -7751,7 +7894,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3A".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3A".into()}) } } }) @@ -8110,9 +8253,9 @@ impl_script_newtype! { self Sub self -> Wrapped(Mat4), self Mul self -> Wrapped(Mat4), self Mul Raw(f32) -> Wrapped(Mat4), + self Mul Wrapped(Vec4) -> Wrapped(Vec4), self Mul Wrapped(Mat4) -> Wrapped(Mat4), self Mul Wrapped(Affine3A) -> Wrapped(Mat4), - self Mul Wrapped(Vec4) -> Wrapped(Vec4), ) + UnaryOps ( @@ -8136,7 +8279,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat4".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat4".into()}) } } }) @@ -8244,10 +8387,10 @@ impl_script_newtype! { ( self Add self -> Wrapped(DMat2), self Sub self -> Wrapped(DMat2), - self Mul Raw(f64) -> Wrapped(DMat2), - self Mul Wrapped(DVec2) -> Wrapped(DVec2), self Mul self -> Wrapped(DMat2), + self Mul Wrapped(DVec2) -> Wrapped(DVec2), self Mul Wrapped(DMat2) -> Wrapped(DMat2), + self Mul Raw(f64) -> Wrapped(DMat2), ) + UnaryOps ( @@ -8271,7 +8414,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat2".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"DMat2".into()}) } } }) @@ -8482,11 +8625,11 @@ impl_script_newtype! { ( self Add self -> Wrapped(DMat3), self Sub self -> Wrapped(DMat3), - self Mul self -> Wrapped(DMat3), - self Mul Wrapped(DVec3) -> Wrapped(DVec3), - self Mul Wrapped(DMat3) -> Wrapped(DMat3), self Mul Raw(f64) -> Wrapped(DMat3), self Mul Wrapped(DAffine2) -> Wrapped(DMat3), + self Mul Wrapped(DMat3) -> Wrapped(DMat3), + self Mul self -> Wrapped(DMat3), + self Mul Wrapped(DVec3) -> Wrapped(DVec3), ) + UnaryOps ( @@ -8510,7 +8653,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat3".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"DMat3".into()}) } } }) @@ -8850,11 +8993,11 @@ impl_script_newtype! { ( self Add self -> Wrapped(DMat4), self Sub self -> Wrapped(DMat4), - self Mul Wrapped(DAffine3) -> Wrapped(DMat4), + self Mul Wrapped(DVec4) -> Wrapped(DVec4), self Mul Raw(f64) -> Wrapped(DMat4), self Mul self -> Wrapped(DMat4), + self Mul Wrapped(DAffine3) -> Wrapped(DMat4), self Mul Wrapped(DMat4) -> Wrapped(DMat4), - self Mul Wrapped(DVec4) -> Wrapped(DVec4), ) + UnaryOps ( @@ -8878,7 +9021,7 @@ impl_script_newtype! { .unwrap() .col_mut(idx)) } else { - Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat4".into()}) + Err(ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"DMat4".into()}) } } }) @@ -8980,9 +9123,9 @@ impl_script_newtype! { ) + BinOps ( - self Mul Wrapped(Mat3A) -> Wrapped(Mat3A), self Mul Wrapped(Mat3) -> Wrapped(Mat3), self Mul Wrapped(Affine2) -> Wrapped(Affine2), + self Mul Wrapped(Mat3A) -> Wrapped(Mat3A), ) + UnaryOps ( @@ -9137,8 +9280,8 @@ impl_script_newtype! { ) + BinOps ( - self Mul Wrapped(Mat4) -> Wrapped(Mat4), self Mul Wrapped(Affine3A) -> Wrapped(Affine3A), + self Mul Wrapped(Mat4) -> Wrapped(Mat4), ) + UnaryOps ( @@ -9381,8 +9524,8 @@ impl_script_newtype! { ) + BinOps ( - self Mul Wrapped(DMat4) -> Wrapped(DMat4), self Mul Wrapped(DAffine3) -> Wrapped(DAffine3), + self Mul Wrapped(DMat4) -> Wrapped(DMat4), ) + UnaryOps ( @@ -9646,10 +9789,10 @@ impl_script_newtype! { self Add self -> Wrapped(Quat), self Sub self -> Wrapped(Quat), self Div Raw(f32) -> Wrapped(Quat), + self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), + self Mul Raw(f32) -> Wrapped(Quat), self Mul Wrapped(Vec3) -> Wrapped(Vec3), self Mul self -> Wrapped(Quat), - self Mul Raw(f32) -> Wrapped(Quat), - self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), ) + UnaryOps ( @@ -9909,8 +10052,8 @@ impl_script_newtype! { self Sub self -> Wrapped(DQuat), self Div Raw(f64) -> Wrapped(DQuat), self Mul Raw(f64) -> Wrapped(DQuat), - self Mul self -> Wrapped(DQuat), self Mul Wrapped(DVec3) -> Wrapped(DVec3), + self Mul self -> Wrapped(DQuat), ) + UnaryOps ( @@ -10175,6 +10318,24 @@ impl_script_newtype! { ///``` inset(&self:Raw(f32)) -> self, + ///Build a new rectangle from this one with its coordinates expressed + ///relative to `other` in a normalized ([0..1] x [0..1]) coordinate system. + /// + ///# Examples + /// + ///```rust + ///# use bevy_math::{Rect, Vec2}; + ///let r = Rect::new(2., 3., 4., 6.); + ///let s = Rect::new(0., 0., 10., 10.); + ///let n = r.normalize(s); + /// + ///assert_eq!(n.min.x, 0.2); + ///assert_eq!(n.min.y, 0.3); + ///assert_eq!(n.max.x, 0.4); + ///assert_eq!(n.max.y, 0.6); + ///``` + normalize(&self:self) -> self, + ) + Fields ( @@ -10264,10 +10425,6 @@ impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for BevyAPIGlobals { "CameraRenderGraph", bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, )?; - instances.add_instance( - "HandleId", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; instances.add_instance( "Vec2", bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, @@ -10496,7 +10653,8 @@ impl APIProvider for LuaBevyAPIProvider { .process_type::>() .process_type::() .process_type::() - .process_type::() + .process_type::() + .process_type::() .process_type::() .process_type::() .process_type::() @@ -10515,11 +10673,7 @@ impl APIProvider for LuaBevyAPIProvider { .process_type::() .process_type::() .process_type::>() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::>() + .process_type::() .process_type::() .process_type::>() .process_type::() @@ -10683,7 +10837,8 @@ impl APIProvider for LuaBevyAPIProvider { app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); @@ -10698,10 +10853,7 @@ impl APIProvider for LuaBevyAPIProvider { app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); app.register_foreign_lua_type::(); diff --git a/bevy_script_api/src/lua/bevy/mod.rs b/bevy_script_api/src/lua/bevy/mod.rs index d9fc339a..1914a87b 100644 --- a/bevy_script_api/src/lua/bevy/mod.rs +++ b/bevy_script_api/src/lua/bevy/mod.rs @@ -92,8 +92,8 @@ impl TealData for LuaWorld { let registry = registry.read(); Ok(registry - .get_with_short_name(&type_name) - .or_else(|| registry.get_with_name(&type_name)) + .get_with_short_type_path(&type_name) + .or_else(|| registry.get_with_type_path(&type_name)) .map(|registration| LuaTypeRegistration::new(Arc::new(registration.clone())))) }); diff --git a/bevy_script_api/src/lua/mod.rs b/bevy_script_api/src/lua/mod.rs index 5114e93c..ab091e5c 100644 --- a/bevy_script_api/src/lua/mod.rs +++ b/bevy_script_api/src/lua/mod.rs @@ -119,7 +119,7 @@ impl ApplyLua for ScriptRef { Err(mlua::Error::RuntimeError(self.get(|s| format!("Attempted to assign `{}` = {v:?}. Did you forget to call `app.register_foreign_lua_type::<{}>`?", self.path, - s.type_name() + s.get_represented_type_info().unwrap().type_path() ))?) ) } diff --git a/bevy_script_api/src/lua/std.rs b/bevy_script_api/src/lua/std.rs index 9d6dbd76..5dbf239f 100644 --- a/bevy_script_api/src/lua/std.rs +++ b/bevy_script_api/src/lua/std.rs @@ -108,7 +108,7 @@ impl FromLuaProxy<' get: |ref_| { ref_.downcast_ref::>() .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.type_name().to_owned().into(), + from: ref_.get_represented_type_info().unwrap().type_path().into(), to: stringify!(Option).into(), })? .as_ref() @@ -122,7 +122,7 @@ impl FromLuaProxy<' get_mut: |ref_| { ref_.downcast_mut::>() // TODO: there is some weird borrow checker fuckery going on here - // i tried having from: ref_.type_name().to_owned().into() instead of "Reflect" + // i tried having from: ref_.get_represented_type_info().unwrap().type_path().into() instead of "Reflect" // and lying this out in an if let expression, but nothing will satisfy the borrow checker here, so leaving this for now .ok_or_else(|| ReflectionError::CannotDowncast { from: "Reflect".into(), @@ -171,7 +171,7 @@ impl FromLuaProxy<' get: |ref_| { ref_.downcast_ref::>() .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.type_name().to_owned().into(), + from: ref_.get_represented_type_info().unwrap().type_path().into(), to: stringify!(Option).into(), })? .as_ref() @@ -195,7 +195,7 @@ impl FromLuaProxy<' }) } else { Err(ReflectionError::CannotDowncast { - from: ref_.type_name().to_owned().into(), + from: ref_.get_represented_type_info().unwrap().type_path().into(), to: stringify!(Option).into(), }) } diff --git a/bevy_script_api/src/rhai/mod.rs b/bevy_script_api/src/rhai/mod.rs index b5391e34..5b937239 100644 --- a/bevy_script_api/src/rhai/mod.rs +++ b/bevy_script_api/src/rhai/mod.rs @@ -142,9 +142,9 @@ impl ApplyRhai for ScriptRef { } Err(Box::new(EvalAltResult::ErrorRuntime(self.get(|s| - format!("Attempted to assign `{}` = {value:?}. Did you forget to call `app.register_foreign_lua_type::<{}>`?", + format!("Attempted to assign `{}` = {value:?}. Did you forget to call `app.register_foreign_rhai_type::<{}>`?", self.path, - s.type_name() + s.get_represented_type_info().unwrap().type_path() ))?.into(),Position::NONE) )) } diff --git a/bevy_script_api/src/rhai/std.rs b/bevy_script_api/src/rhai/std.rs index eb5a6309..c2986b55 100644 --- a/bevy_script_api/src/rhai/std.rs +++ b/bevy_script_api/src/rhai/std.rs @@ -123,7 +123,7 @@ impl>() .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.type_name().to_owned().into(), + from: ref_.get_represented_type_info().unwrap().type_path().into(), to: stringify!(Option).into(), })? .as_ref() @@ -137,7 +137,7 @@ impl>() // TODO: there is some weird borrow checker fuckery going on here - // i tried having from: ref_.type_name().to_owned().into() instead of "Reflect" + // i tried having from: ref_.get_represented_type_info().unwrap().type_path().into() instead of "Reflect" // and lying this out in an if let expression, but nothing will satisfy the borrow checker here, so leaving this for now .ok_or_else(|| ReflectionError::CannotDowncast { from: "Reflect".into(), @@ -184,7 +184,7 @@ impl>() .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.type_name().to_owned().into(), + from: ref_.get_represented_type_info().unwrap().type_path().into(), to: stringify!(Option).into(), })? .as_ref() @@ -208,7 +208,7 @@ impl).into(), }) } diff --git a/bevy_script_api/src/script_ref.rs b/bevy_script_api/src/script_ref.rs index 5bd0a48a..416dcf9b 100644 --- a/bevy_script_api/src/script_ref.rs +++ b/bevy_script_api/src/script_ref.rs @@ -93,7 +93,7 @@ impl ScriptRef { panic!( "Expected `{}` found `{}`", ::std::any::type_name::(), - reflect.type_name() + reflect.get_represented_type_info().unwrap().type_path() ) })) }) diff --git a/examples/lua/complex_game_loop.rs b/examples/lua/complex_game_loop.rs index 08e47d45..55efa657 100644 --- a/examples/lua/complex_game_loop.rs +++ b/examples/lua/complex_game_loop.rs @@ -79,7 +79,7 @@ fn print_frame_count(frame: Res) { fn load_our_script(server: Res, mut commands: Commands) { let path = "scripts/complex_game_loop.lua"; - let handle = server.load::(path); + let handle = server.load::(path); commands.spawn(()).insert(ScriptCollection:: { scripts: vec![Script::::new(path.to_string(), handle)], @@ -96,7 +96,7 @@ enum ComplexGameLoopSet { } fn main() -> std::io::Result<()> { - const TIMESTEP_2_PER_SECOND: f32 = 30.0 / 60.0; + const TIMESTEP_2_PER_SECOND: f64 = 30.0 / 60.0; let mut app = App::new(); @@ -106,18 +106,18 @@ fn main() -> std::io::Result<()> { // we run the post-update scripts after post-update // pretty straightforward, note we use FixedUpdate for physics, which means it runs less often than Update app.add_plugins(DefaultPlugins) - .insert_resource(FixedTime::new_from_secs(TIMESTEP_2_PER_SECOND)) + .insert_resource(Time::::from_seconds(TIMESTEP_2_PER_SECOND)) .add_plugins(ScriptingPlugin) .add_systems(Startup, load_our_script) - .configure_set( + .configure_sets( FixedUpdate, ComplexGameLoopSet::PrePhysicsScripts.before(ComplexGameLoopSet::Physics), ) - .configure_set( + .configure_sets( FixedUpdate, ComplexGameLoopSet::PostPhysicsScripts.after(ComplexGameLoopSet::Physics), ) - .configure_set( + .configure_sets( PostUpdate, ComplexGameLoopSet::EndFrame.after(ComplexGameLoopSet::PostUpdateScripts), ); diff --git a/examples/lua/console_integration.rs b/examples/lua/console_integration.rs index 248ae85a..ee6daeb6 100644 --- a/examples/lua/console_integration.rs +++ b/examples/lua/console_integration.rs @@ -1,9 +1,9 @@ -use bevy::{asset::ChangeWatcher, ecs::event::Events, prelude::*}; +use bevy::{ecs::event::Events, prelude::*}; use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; use bevy_mod_scripting::prelude::*; use clap::Parser; -use std::{sync::Mutex, time::Duration}; +use std::sync::Mutex; #[derive(Default)] pub struct LuaAPIProvider; @@ -69,7 +69,7 @@ pub fn forward_script_err_to_console( mut r: EventReader, mut w: EventWriter, ) { - for e in r.iter() { + for e in r.read() { w.send(PrintConsoleLine { line: format!("ERROR:{}", e.error).into(), }); @@ -97,7 +97,7 @@ pub fn run_script_cmd( mut existing_scripts: Query<&mut ScriptCollection>, ) { if let Some(Ok(RunScriptCmd { path, entity })) = log.take() { - let handle = server.load::(&format!("scripts/{}", &path)); + let handle = server.load::(&format!("scripts/{}", &path)); match entity { Some(e) => { @@ -158,23 +158,20 @@ pub struct DeleteScriptCmd { fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .add_plugins(ScriptingPlugin) - .add_plugins(ConsolePlugin) - // register bevy_console commands - .add_console_command::(run_script_cmd) - .add_console_command::(delete_script_cmd) - // choose and register the script hosts you want to use - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)) - .add_api_provider::>(Box::new(LuaBevyAPIProvider)) - .add_script_handler::, 0, 0>(PostUpdate) - // add your systems - .add_systems(Update, trigger_on_update_lua) - .add_systems(Update, forward_script_err_to_console); + app.add_plugins(DefaultPlugins) + .add_plugins(ScriptingPlugin) + .add_plugins(ConsolePlugin) + // register bevy_console commands + .add_console_command::(run_script_cmd) + .add_console_command::(delete_script_cmd) + // choose and register the script hosts you want to use + .add_script_host::>(PostUpdate) + .add_api_provider::>(Box::new(LuaAPIProvider)) + .add_api_provider::>(Box::new(LuaBevyAPIProvider)) + .add_script_handler::, 0, 0>(PostUpdate) + // add your systems + .add_systems(Update, trigger_on_update_lua) + .add_systems(Update, forward_script_err_to_console); info!("press '~' to open the console. Type in `run_script \"console_integration.lua\"` to run example script!"); app.run(); diff --git a/examples/lua/coroutines.rs b/examples/lua/coroutines.rs index 1d286c5b..2285984a 100644 --- a/examples/lua/coroutines.rs +++ b/examples/lua/coroutines.rs @@ -1,6 +1,4 @@ -use std::time::Duration; - -use bevy::{asset::ChangeWatcher, prelude::*}; +use bevy::prelude::*; use bevy_mod_scripting::prelude::*; /// fire on_update @@ -16,7 +14,7 @@ fn do_update(mut w: PriorityEventWriter>) { fn load_our_scripts(server: Res, mut commands: Commands) { let path = "scripts/coroutines.lua"; - let handle = server.load::(path); + let handle = server.load::(path); let script = Script::::new(path.to_string(), handle); commands.spawn(()).insert(ScriptCollection:: { @@ -27,18 +25,15 @@ fn load_our_scripts(server: Res, mut commands: Commands) { fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .add_plugins(ScriptingPlugin) - .add_systems(Startup, load_our_scripts) - // randomly fire events for either all scripts, - // the script with id 0 - // or the script with id 1 - .add_systems(Update, do_update) - .add_script_handler::, 0, 0>(PostUpdate) - .add_script_host::>(PostUpdate); + app.add_plugins(DefaultPlugins) + .add_plugins(ScriptingPlugin) + .add_systems(Startup, load_our_scripts) + // randomly fire events for either all scripts, + // the script with id 0 + // or the script with id 1 + .add_systems(Update, do_update) + .add_script_handler::, 0, 0>(PostUpdate) + .add_script_host::>(PostUpdate); app.run(); Ok(()) diff --git a/examples/lua/documentation_gen.rs b/examples/lua/documentation_gen.rs index 84e9021d..1ed6546c 100644 --- a/examples/lua/documentation_gen.rs +++ b/examples/lua/documentation_gen.rs @@ -1,11 +1,11 @@ -use bevy::{asset::ChangeWatcher, prelude::*}; +use bevy::prelude::*; use bevy_mod_scripting::{ api::{impl_tealr_type, lua::bevy::LuaBevyAPIProvider}, prelude::*, }; -use std::{sync::Mutex, time::Duration}; +use std::sync::Mutex; #[derive(Clone)] pub struct MyLuaArg; @@ -95,22 +95,19 @@ impl APIProvider for LuaAPIProvider { fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .add_plugins(ScriptingPlugin) - // add the providers and script host - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)) - .add_api_provider::>(Box::new(LuaBevyAPIProvider)) - // this needs to be placed after any `add_api_provider` and `add_script_host` calls - // it will generate `doc` and `types` folders under `assets/scripts` containing the documentation and teal declaration files - // respectively. See example asset folder to see how they look like. The `teal_file.tl` script in example assets shows the usage of one of those - // declaration files, use the teal vscode extension to explore the type hints! - // Note: This is a noop in optimized builds unless the `doc_always` feature is enabled! - .update_documentation::>() - .add_script_handler::, 0, 0>(PostUpdate); + app.add_plugins(DefaultPlugins) + .add_plugins(ScriptingPlugin) + // add the providers and script host + .add_script_host::>(PostUpdate) + .add_api_provider::>(Box::new(LuaAPIProvider)) + .add_api_provider::>(Box::new(LuaBevyAPIProvider)) + // this needs to be placed after any `add_api_provider` and `add_script_host` calls + // it will generate `doc` and `types` folders under `assets/scripts` containing the documentation and teal declaration files + // respectively. See example asset folder to see how they look like. The `teal_file.tl` script in example assets shows the usage of one of those + // declaration files, use the teal vscode extension to explore the type hints! + // Note: This is a noop in optimized builds unless the `doc_always` feature is enabled! + .update_documentation::>() + .add_script_handler::, 0, 0>(PostUpdate); // app.run(); no need, documentation gets generated before the app even starts diff --git a/examples/lua/event_recipients.rs b/examples/lua/event_recipients.rs index 07cac41c..3a8a75e1 100644 --- a/examples/lua/event_recipients.rs +++ b/examples/lua/event_recipients.rs @@ -1,10 +1,8 @@ -use bevy::asset::ChangeWatcher; use bevy::prelude::*; use bevy_mod_scripting::prelude::*; use rand::prelude::SliceRandom; use std::sync::atomic::Ordering::Relaxed; use std::sync::{atomic::AtomicU32, Mutex}; -use std::time::Duration; #[derive(Clone)] pub struct MyLuaArg(usize); @@ -107,7 +105,7 @@ fn load_our_scripts(server: Res, mut commands: Commands) { // spawn two identical scripts // id's will be 0 and 1 let path = "scripts/event_recipients.lua"; - let handle = server.load::(path); + let handle = server.load::(path); let scripts = (0..2) .map(|_| Script::::new(path.to_string(), handle.clone())) .collect(); @@ -120,19 +118,16 @@ fn load_our_scripts(server: Res, mut commands: Commands) { fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .add_plugins(ScriptingPlugin) - .add_systems(Startup, load_our_scripts) - // randomly fire events for either all scripts, - // the script with id 0 - // or the script with id 1 - .add_systems(Update, do_update) - .add_script_handler::, 0, 0>(PostUpdate) - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)); + app.add_plugins(DefaultPlugins) + .add_plugins(ScriptingPlugin) + .add_systems(Startup, load_our_scripts) + // randomly fire events for either all scripts, + // the script with id 0 + // or the script with id 1 + .add_systems(Update, do_update) + .add_script_handler::, 0, 0>(PostUpdate) + .add_script_host::>(PostUpdate) + .add_api_provider::>(Box::new(LuaAPIProvider)); app.run(); Ok(()) diff --git a/examples/lua/game_of_life.rs b/examples/lua/game_of_life.rs index 5bee2236..93822065 100644 --- a/examples/lua/game_of_life.rs +++ b/examples/lua/game_of_life.rs @@ -1,7 +1,6 @@ -use std::{borrow::Cow, sync::Mutex, time::Duration}; +use std::{borrow::Cow, sync::Mutex}; use bevy::{ - asset::ChangeWatcher, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, reflect::Reflect, @@ -100,7 +99,7 @@ pub fn setup( TextureFormat::R8Unorm, ); - image.sampler_descriptor = ImageSampler::nearest(); + image.sampler = ImageSampler::nearest(); // in release builds we want to fetch ".lua" files over ".tl" files let script_path = bevy_mod_scripting_lua::lua_path!("game_of_life"); @@ -141,7 +140,7 @@ pub fn sync_window_size( primary_windows: Query<(&Window, With)>, ) { if let Some(e) = resize_event - .iter() + .read() .filter(|e| primary_windows.get(e.window).is_ok()) .last() { @@ -216,25 +215,22 @@ const UPDATE_FREQUENCY: f32 = 1.0 / 20.0; fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .insert_resource(FixedTime::new_from_secs(UPDATE_FREQUENCY)) - .add_plugins(LogDiagnosticsPlugin::default()) - .add_plugins(FrameTimeDiagnosticsPlugin) - .add_plugins(ScriptingPlugin) - .init_resource::() - .add_systems(Startup, setup) - .add_systems(Startup, send_init) - .add_systems(Update, sync_window_size) - .add_systems(FixedUpdate, update_rendered_state.after(sync_window_size)) - .add_systems(FixedUpdate, send_on_update.after(update_rendered_state)) - .add_systems(FixedUpdate, script_event_handler::, 0, 1>) - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaBevyAPIProvider)) - .add_api_provider::>(Box::new(LifeAPI)) - .update_documentation::>(); + app.add_plugins(DefaultPlugins) + .insert_resource(Time::::from_seconds(UPDATE_FREQUENCY.into())) + .add_plugins(LogDiagnosticsPlugin::default()) + .add_plugins(FrameTimeDiagnosticsPlugin) + .add_plugins(ScriptingPlugin) + .init_resource::() + .add_systems(Startup, setup) + .add_systems(Startup, send_init) + .add_systems(Update, sync_window_size) + .add_systems(FixedUpdate, update_rendered_state.after(sync_window_size)) + .add_systems(FixedUpdate, send_on_update.after(update_rendered_state)) + .add_systems(FixedUpdate, script_event_handler::, 0, 1>) + .add_script_host::>(PostUpdate) + .add_api_provider::>(Box::new(LuaBevyAPIProvider)) + .add_api_provider::>(Box::new(LifeAPI)) + .update_documentation::>(); app.run(); diff --git a/examples/rhai/console_integration.rs b/examples/rhai/console_integration.rs index de657844..fdb13fda 100644 --- a/examples/rhai/console_integration.rs +++ b/examples/rhai/console_integration.rs @@ -1,6 +1,4 @@ -use std::time::Duration; - -use bevy::{asset::ChangeWatcher, ecs::event::Events, prelude::*}; +use bevy::{ecs::event::Events, prelude::*}; use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; use bevy_mod_scripting::prelude::*; use bevy_script_api::common::bevy::ScriptWorld; @@ -63,7 +61,7 @@ pub fn forward_script_err_to_console( mut r: EventReader, mut w: EventWriter, ) { - for e in r.iter() { + for e in r.read() { w.send(PrintConsoleLine { line: format!("ERROR:{}", e.error).into(), }); @@ -91,7 +89,7 @@ pub fn run_script_cmd( mut existing_scripts: Query<&mut ScriptCollection>, ) { if let Some(Ok(RunScriptCmd { path, entity })) = log.take() { - let handle = server.load::(&format!("scripts/{}", &path)); + let handle = server.load::(&format!("scripts/{}", &path)); match entity { Some(e) => { @@ -153,23 +151,20 @@ pub struct DeleteScriptCmd { fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .add_plugins(ScriptingPlugin) - .add_plugins(ConsolePlugin) - // register bevy_console commands - .add_console_command::(run_script_cmd) - .add_console_command::(delete_script_cmd) - // choose and register the script hosts you want to use - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(RhaiAPI)) - .add_api_provider::>(Box::new(RhaiBevyAPIProvider)) - .add_script_handler::, 0, 0>(PostUpdate) - // add your systems - .add_systems(Update, trigger_on_update_rhai) - .add_systems(Update, forward_script_err_to_console); + app.add_plugins(DefaultPlugins) + .add_plugins(ScriptingPlugin) + .add_plugins(ConsolePlugin) + // register bevy_console commands + .add_console_command::(run_script_cmd) + .add_console_command::(delete_script_cmd) + // choose and register the script hosts you want to use + .add_script_host::>(PostUpdate) + .add_api_provider::>(Box::new(RhaiAPI)) + .add_api_provider::>(Box::new(RhaiBevyAPIProvider)) + .add_script_handler::, 0, 0>(PostUpdate) + // add your systems + .add_systems(Update, trigger_on_update_rhai) + .add_systems(Update, forward_script_err_to_console); info!("press '~' to open the console. Type in `run_script \"console_integration.rhai\"` to run example script!"); diff --git a/examples/rhai/game_of_life.rs b/examples/rhai/game_of_life.rs index 4f995f0b..d7e34583 100644 --- a/examples/rhai/game_of_life.rs +++ b/examples/rhai/game_of_life.rs @@ -1,7 +1,4 @@ -use std::time::Duration; - use bevy::{ - asset::ChangeWatcher, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, reflect::Reflect, @@ -88,7 +85,7 @@ pub fn setup( TextureFormat::R8Unorm, ); - image.sampler_descriptor = ImageSampler::nearest(); + image.sampler = ImageSampler::nearest(); let script_path = "scripts/game_of_life.rhai"; @@ -128,7 +125,7 @@ pub fn sync_window_size( primary_windows: Query<(&Window, With)>, ) { if let Some(e) = resize_event - .iter() + .read() .filter(|e| primary_windows.get(e.window).is_ok()) .last() { @@ -198,32 +195,29 @@ pub fn send_init(mut events: PriorityEventWriter>) { } /// how often to step the simulation -const UPDATE_FREQUENCY: f32 = 1.0 / 30.0; +const UPDATE_FREQUENCY: f64 = 1.0 / 30.0; fn main() -> std::io::Result<()> { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(0)), - ..Default::default() - })) - .insert_resource(FixedTime::new_from_secs(UPDATE_FREQUENCY)) - .add_plugins(LogDiagnosticsPlugin::default()) - .add_plugins(FrameTimeDiagnosticsPlugin) - .add_plugins(ScriptingPlugin) - .init_resource::() - .add_systems(Startup, setup) - .add_systems(Startup, send_init) - .add_systems(Update, sync_window_size) - .add_systems(FixedUpdate, (update_rendered_state, send_on_update).chain()) - .add_systems( - FixedUpdate, - script_event_handler::, 0, 1>, - ) - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(RhaiBevyAPIProvider)) - .add_api_provider::>(Box::new(LifeAPI)) - .update_documentation::>(); + app.add_plugins(DefaultPlugins) + .insert_resource(Time::::from_seconds(UPDATE_FREQUENCY)) + .add_plugins(LogDiagnosticsPlugin::default()) + .add_plugins(FrameTimeDiagnosticsPlugin) + .add_plugins(ScriptingPlugin) + .init_resource::() + .add_systems(Startup, setup) + .add_systems(Startup, send_init) + .add_systems(Update, sync_window_size) + .add_systems(FixedUpdate, (update_rendered_state, send_on_update).chain()) + .add_systems( + FixedUpdate, + script_event_handler::, 0, 1>, + ) + .add_script_host::>(PostUpdate) + .add_api_provider::>(Box::new(RhaiBevyAPIProvider)) + .add_api_provider::>(Box::new(LifeAPI)) + .update_documentation::>(); app.run(); diff --git a/examples/rhai/multiple_events_rhai.rs b/examples/rhai/multiple_events_rhai.rs index 6ecf7c55..7d455ac2 100644 --- a/examples/rhai/multiple_events_rhai.rs +++ b/examples/rhai/multiple_events_rhai.rs @@ -128,7 +128,7 @@ fn call_init( mut commands: Commands, ) { // Call init on all entities that have a script that was just loaded, and remove the Marker component, so that Update can be called - 'outer: for loaded_script in loaded_scripts.iter() { + 'outer: for loaded_script in loaded_scripts.read() { for (entity, name, scripts) in entity_query.iter() { if let Some(scripts) = scripts { if scripts.scripts.iter().any(|s| s.id() == loaded_script.sid) { diff --git a/languages/bevy_mod_scripting_lua/Cargo.toml b/languages/bevy_mod_scripting_lua/Cargo.toml index d247b38a..4185c9f5 100644 --- a/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/languages/bevy_mod_scripting_lua/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_lua" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -43,13 +43,13 @@ name = "bevy_mod_scripting_lua" path = "src/lib.rs" [dependencies] -bevy = { version = "0.11", default-features = false } -bevy_mod_scripting_core = { path = "../../bevy_mod_scripting_core", version = "0.3.0" } +bevy = { version = "0.12", default-features = false } +bevy_mod_scripting_core = { path = "../../bevy_mod_scripting_core", version = "0.4.0" } tealr = { version = "0.9", features = [ "mlua_vendored", "mlua_send", "mlua_macros", ] } -parking_lot = "0.12.1" #Git pin required for v0.9.0-alpha4 dependancy, without it 0.9.1 is pulled +parking_lot = "0.12.1" serde_json = "1.0.81" -serde = { version = "1", features = ["derive"] } +anyhow = "1.0.75" \ No newline at end of file diff --git a/languages/bevy_mod_scripting_lua/src/assets.rs b/languages/bevy_mod_scripting_lua/src/assets.rs index 5ebfadb5..8c94f4e5 100644 --- a/languages/bevy_mod_scripting_lua/src/assets.rs +++ b/languages/bevy_mod_scripting_lua/src/assets.rs @@ -1,21 +1,21 @@ use bevy::{ - asset::{AssetLoader, Error, LoadedAsset}, - reflect::{TypePath, TypeUuid}, + asset::{io::Reader, Asset, AssetLoader, AsyncReadExt}, + reflect::TypePath, + utils::BoxedFuture, }; use bevy_mod_scripting_core::asset::CodeAsset; -use std::sync::Arc; +use anyhow::Error; -#[derive(Debug, TypeUuid, TypePath)] -#[uuid = "39cadc56-aa9c-4543-8640-a018b74b5052"] +#[derive(Asset, TypePath, Debug)] /// A lua code file in bytes pub struct LuaFile { - pub bytes: Arc<[u8]>, + pub bytes: Vec, } impl CodeAsset for LuaFile { fn bytes(&self) -> &[u8] { - &self.bytes + self.bytes.as_slice() } } @@ -23,111 +23,126 @@ impl CodeAsset for LuaFile { /// Asset loader for lua scripts pub struct LuaLoader; -impl AssetLoader for LuaLoader { - fn load<'a>( - &'a self, - bytes: &'a [u8], - load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::asset::BoxedFuture<'a, Result<(), Error>> { - match load_context.path().extension().map(|s| s.to_str().unwrap()) { - #[cfg(all(feature = "teal", debug_assertions))] - Some("tl") => { - use bevy::asset::FileAssetIo; - use std::fs; - use std::path::PathBuf; - use std::process::Command; - - let scripts_dir = &FileAssetIo::get_base_path().join("assets").join("scripts"); - - let temp_file_path = &std::env::temp_dir().join("bevy_mod_scripting.temp.lua"); - - // optionally put the output in the /build folder - let build_dir_path: Option = - if load_context.path().starts_with("scripts/build/") { - Some( - load_context - .path() - .strip_prefix("scripts/") - .unwrap() - .to_owned(), - ) - } else if load_context.path().starts_with("scripts/") { - Some( - PathBuf::from("build/") - .join(load_context.path().strip_prefix("scripts/").unwrap()), - ) - } else { - None - }; - - let full_path = &FileAssetIo::get_base_path() - .join("assets") - .join(load_context.path()); - - if let Ok(e) = Command::new("tl") - .args(["check", full_path.to_str().unwrap()]) - .current_dir(scripts_dir) - .status() - { - if !e.success() { - return Box::pin(async move { - Err(Error::msg(format!( - "Teal file `{}` has errors", - load_context.path().to_str().unwrap() - ))) - }); - } +fn old_lua_load<'a>( + bytes: &'a [u8], + load_context: &'a mut bevy::asset::LoadContext, +) -> BoxedFuture<'a, Result, Error>> { + match load_context.path().extension().map(|s| s.to_str().unwrap()) { + #[cfg(all(feature = "teal", debug_assertions))] + Some("tl") => { + use bevy::asset::io::file::FileAssetReader; + use std::fs; + use std::path::PathBuf; + use std::process::Command; + + let scripts_dir = &FileAssetReader::get_base_path() + .join("assets") + .join("scripts"); + + let temp_file_path = &std::env::temp_dir().join("bevy_mod_scripting.temp.lua"); + bevy::prelude::info!("tl file path {}", scripts_dir.to_str().unwrap()); + // optionally put the output in the /build folder + let build_dir_path: Option = + if load_context.path().starts_with("scripts/build/") { + Some( + load_context + .path() + .strip_prefix("scripts/") + .unwrap() + .to_owned(), + ) + } else if load_context.path().starts_with("scripts/") { + Some( + PathBuf::from("build/") + .join(load_context.path().strip_prefix("scripts/").unwrap()), + ) } else { - fs::remove_file(temp_file_path) - .expect("Something went wrong running `tl check`"); - panic!("Something went wrong running `tl check`"); + None + }; + + let full_path = &FileAssetReader::get_base_path() + .join("assets") + .join(load_context.path()); + bevy::log::info!( + "tl check {} : {}", + full_path.to_str().unwrap(), + scripts_dir.to_str().unwrap() + ); + if let Ok(e) = Command::new("tl") + .args(["check", full_path.to_str().unwrap()]) + .current_dir(scripts_dir) + .status() + { + if !e.success() { + return Box::pin(async move { + Err(Error::msg(format!( + "Teal file `{}` has errors", + load_context.path().to_str().unwrap() + ))) + }); } + } else { + fs::remove_file(temp_file_path).expect("Something went wrong running `tl check`"); + panic!("Something went wrong running `tl check`"); + } - if let Ok(e) = Command::new("tl") - .args([ - "gen", - full_path.to_str().unwrap(), - "-o", - temp_file_path.to_str().unwrap(), - ]) - .current_dir(scripts_dir) - .status() - { - if !e.success() { - return Box::pin(async move { - Err(Error::msg(format!( - "Teal file `{}` could not be compiled!", - load_context.path().to_str().unwrap() - ))) - }); - } - } else { - fs::remove_file(temp_file_path).expect("Something went wrong running `tl gen`"); - panic!("Something went wrong running `tl gen`") + if let Ok(e) = Command::new("tl") + .args([ + "gen", + full_path.to_str().unwrap(), + "-o", + temp_file_path.to_str().unwrap(), + ]) + .current_dir(scripts_dir) + .status() + { + if !e.success() { + return Box::pin(async move { + Err(Error::msg(format!( + "Teal file `{}` could not be compiled!", + load_context.path().to_str().unwrap() + ))) + }); } + } else { + fs::remove_file(temp_file_path).expect("Something went wrong running `tl gen`"); + panic!("Something went wrong running `tl gen`") + } - if let Some(mut build_dir_path) = build_dir_path { - build_dir_path = scripts_dir.join(build_dir_path); - let _ = fs::create_dir_all(build_dir_path.parent().unwrap()); - let _ = fs::copy(temp_file_path, build_dir_path.with_extension("lua")); - } + if let Some(mut build_dir_path) = build_dir_path { + build_dir_path = scripts_dir.join(build_dir_path); + let _ = fs::create_dir_all(build_dir_path.parent().unwrap()); + let _ = fs::copy(temp_file_path, build_dir_path.with_extension("lua")); + } - let lua_code = - fs::read_to_string(temp_file_path).expect("Could not find output lua file"); - fs::remove_file(temp_file_path).unwrap(); + let lua_code = + fs::read_to_string(temp_file_path).expect("Could not find output lua file"); + fs::remove_file(temp_file_path).unwrap(); - load_context.set_default_asset(LoadedAsset::new(LuaFile { - bytes: lua_code.as_bytes().into(), - })); - } - _ => { - load_context.set_default_asset(LoadedAsset::new(LuaFile { - bytes: bytes.into(), - })); - } + Box::pin(async move { Ok(lua_code.as_bytes().into()) }) } - Box::pin(async move { Ok(()) }) + _ => Box::pin(async move { Ok(bytes.into()) }), + } +} +impl AssetLoader for LuaLoader { + type Asset = LuaFile; + type Settings = (); + type Error = Error; + + fn load<'a>( + &'a self, + reader: &'a mut Reader, //bytes: &'a [u8], + _settings: &'a (), + load_context: &'a mut bevy::asset::LoadContext, + ) -> bevy::asset::BoxedFuture<'a, Result> { + bevy::prelude::info!("lua loader invoked: {:#}", load_context.asset_path()); + Box::pin(async move { + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let bytes = old_lua_load(bytes.as_slice(), load_context).await?; + Ok(LuaFile { bytes }) //}) + }) } #[cfg(feature = "teal")] diff --git a/languages/bevy_mod_scripting_lua/src/docs.rs b/languages/bevy_mod_scripting_lua/src/docs.rs index 807ae1a9..bc0249e7 100644 --- a/languages/bevy_mod_scripting_lua/src/docs.rs +++ b/languages/bevy_mod_scripting_lua/src/docs.rs @@ -5,10 +5,10 @@ use std::{ process::Command, }; -use bevy::asset::FileAssetIo; -use tealr::{TypeGenerator, TypeWalker}; - +//use bevy::asset::FileAssetIo; +use bevy::asset::io::file::FileAssetReader; use bevy_mod_scripting_core::prelude::*; +use tealr::{TypeGenerator, TypeWalker}; pub type TypeWalkerBuilder = fn(TypeWalker) -> TypeWalker; @@ -75,7 +75,9 @@ impl DocFragment for LuaDocFragment { } fn gen_docs(self) -> Result<(), ScriptError> { - let script_asset_path = &FileAssetIo::get_base_path().join("assets").join("scripts"); + let script_asset_path = &FileAssetReader::get_base_path() + .join("assets") + .join("scripts"); let script_doc_dir = &env::var("SCRIPT_DOC_DIR") .map(|v| v.into()) diff --git a/languages/bevy_mod_scripting_lua/src/lib.rs b/languages/bevy_mod_scripting_lua/src/lib.rs index 8af061d5..1521e09b 100644 --- a/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/languages/bevy_mod_scripting_lua/src/lib.rs @@ -80,7 +80,7 @@ impl ScriptHost for LuaScriptHost { fn register_with_app_in_set(app: &mut App, schedule: impl ScheduleLabel, set: impl SystemSet) { app.add_priority_event::() - .add_asset::() + .init_asset::() .init_asset_loader::() .init_resource::>() .init_resource::>() diff --git a/languages/bevy_mod_scripting_lua_derive/Cargo.toml b/languages/bevy_mod_scripting_lua_derive/Cargo.toml index fbb15c9e..1de91998 100644 --- a/languages/bevy_mod_scripting_lua_derive/Cargo.toml +++ b/languages/bevy_mod_scripting_lua_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_lua_derive" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -23,7 +23,7 @@ path="src/lib.rs" proc-macro=true [dependencies] -bevy_mod_scripting_common = {path = "../../bevy_mod_scripting_common", version = "0.3.0" } +bevy_mod_scripting_common = {path = "../../bevy_mod_scripting_common", version = "0.4.0" } paste = "1.0.7" syn = {version="1.0.57",features=["full","fold","extra-traits"]} quote = "1.0.8" diff --git a/languages/bevy_mod_scripting_rhai/Cargo.toml b/languages/bevy_mod_scripting_rhai/Cargo.toml index b5e41ea1..501c0241 100644 --- a/languages/bevy_mod_scripting_rhai/Cargo.toml +++ b/languages/bevy_mod_scripting_rhai/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_rhai" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -13,15 +13,16 @@ readme = "readme.md" [package.metadata.release] pre-release-replacements = [ - {file="Cargo.toml", search='^version\s*=\s*.*$', replace="version = \"{{version}}\"", exactly=1}, - {file="Cargo.toml", search='^(?Pbevy_mod_scripting_core\s*=.*)version\s*=\s*".*"(?P.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1}, + { file = "Cargo.toml", search = '^version\s*=\s*.*$', replace = "version = \"{{version}}\"", exactly = 1 }, + { file = "Cargo.toml", search = '^(?Pbevy_mod_scripting_core\s*=.*)version\s*=\s*".*"(?P.*)$', replace = "${h}version = \"{{version}}\"${t}", exactly = 1 }, ] [lib] -name="bevy_mod_scripting_rhai" -path="src/lib.rs" +name = "bevy_mod_scripting_rhai" +path = "src/lib.rs" [dependencies] -bevy= { version = "0.11", default-features = false} +bevy = { version = "0.12", default-features = false } rhai = { version = "1.16", features = ["sync"] } -bevy_mod_scripting_core = {path="../../bevy_mod_scripting_core", version = "0.3.0" } +bevy_mod_scripting_core = { path = "../../bevy_mod_scripting_core", version = "0.4.0" } +anyhow = "1.0.75" diff --git a/languages/bevy_mod_scripting_rhai/src/assets.rs b/languages/bevy_mod_scripting_rhai/src/assets.rs index 6d803b49..4470cf59 100644 --- a/languages/bevy_mod_scripting_rhai/src/assets.rs +++ b/languages/bevy_mod_scripting_rhai/src/assets.rs @@ -1,21 +1,19 @@ use bevy::{ - asset::Error, - asset::{AssetLoader, LoadedAsset}, - reflect::{TypePath, TypeUuid}, + asset::{io::Reader, Asset, AssetLoader, AsyncReadExt, LoadContext}, + reflect::TypePath, }; + use bevy_mod_scripting_core::prelude::*; -use std::sync::Arc; -#[derive(Debug, TypeUuid, TypePath)] -#[uuid = "e4f7d00d-5acd-45fb-a29c-5a44c5447f5c"] +#[derive(Asset, Debug, TypePath)] /// A rhai code file in bytes pub struct RhaiFile { - pub bytes: Arc<[u8]>, + pub bytes: Vec, } impl CodeAsset for RhaiFile { fn bytes(&self) -> &[u8] { - &self.bytes + self.bytes.as_slice() } } @@ -24,15 +22,20 @@ impl CodeAsset for RhaiFile { pub struct RhaiLoader; impl AssetLoader for RhaiLoader { + type Asset = RhaiFile; + type Settings = (); + type Error = anyhow::Error; fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::asset::BoxedFuture<'a, Result<(), Error>> { - load_context.set_default_asset(LoadedAsset::new(RhaiFile { - bytes: bytes.into(), - })); - Box::pin(async move { Ok(()) }) + reader: &'a mut Reader, + _: &'a Self::Settings, + _: &'a mut LoadContext, + ) -> bevy::asset::BoxedFuture<'a, Result> { + Box::pin(async move { + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + Ok(RhaiFile { bytes }) + }) } fn extensions(&self) -> &[&str] { diff --git a/languages/bevy_mod_scripting_rhai/src/lib.rs b/languages/bevy_mod_scripting_rhai/src/lib.rs index 4b8751e2..cbb0eb16 100644 --- a/languages/bevy_mod_scripting_rhai/src/lib.rs +++ b/languages/bevy_mod_scripting_rhai/src/lib.rs @@ -75,7 +75,7 @@ impl ScriptHost for RhaiScriptHost< set: impl SystemSet, ) { app.add_priority_event::() - .add_asset::() + .init_asset::() .init_asset_loader::() .init_resource::>() .init_resource::>() diff --git a/languages/bevy_mod_scripting_rhai_derive/Cargo.toml b/languages/bevy_mod_scripting_rhai_derive/Cargo.toml index fc27f633..5c01699b 100644 --- a/languages/bevy_mod_scripting_rhai_derive/Cargo.toml +++ b/languages/bevy_mod_scripting_rhai_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_rhai_derive" -version = "0.3.0" +version = "0.4.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT" @@ -23,7 +23,7 @@ path="src/lib.rs" proc-macro=true [dependencies] -bevy_mod_scripting_common = {path = "../../bevy_mod_scripting_common", version = "0.3.0" } +bevy_mod_scripting_common = {path = "../../bevy_mod_scripting_common", version = "0.4.0" } paste = "1.0.7" syn = {version="1.0.57",features=["full","fold","extra-traits"]} quote = "1.0.8" diff --git a/languages/bevy_mod_scripting_rune/Cargo.toml b/languages/bevy_mod_scripting_rune/Cargo.toml index da3effb2..8a087989 100644 --- a/languages/bevy_mod_scripting_rune/Cargo.toml +++ b/languages/bevy_mod_scripting_rune/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_scripting_rune" -version = "0.3.0" +version = "0.4.0" edition = "2021" license = "MIT" description = "Necessary functionality for Rune support with bevy_mod_scripting" @@ -21,7 +21,8 @@ name = "bevy_mod_scripting_rune" path = "src/lib.rs" [dependencies] -bevy_mod_scripting_core = { path = "../../bevy_mod_scripting_core", version = "0.3.0" } -bevy = "0.11" +bevy_mod_scripting_core = { path = "../../bevy_mod_scripting_core", version = "0.4.0" } +bevy = "0.12.1" rune = "0.13.1" rune-modules = "0.13.1" +anyhow = "1.0.75" diff --git a/languages/bevy_mod_scripting_rune/src/assests.rs b/languages/bevy_mod_scripting_rune/src/assests.rs deleted file mode 100644 index 27ad9651..00000000 --- a/languages/bevy_mod_scripting_rune/src/assests.rs +++ /dev/null @@ -1,44 +0,0 @@ -use bevy::{ - asset::{AssetLoader, LoadedAsset}, - reflect::{TypePath, TypeUuid}, -}; -use bevy_mod_scripting_core::prelude::*; -use std::sync::Arc; - -#[derive(Debug, TypeUuid, TypePath)] -#[uuid = "e4f7d00d-5acd-45fb-a29c-6472718771fc"] -/// A loaded rune file in bytes. -pub struct RuneFile { - /// File content in bytes. - pub bytes: Arc<[u8]>, -} - -impl CodeAsset for RuneFile { - fn bytes(&self) -> &[u8] { - &self.bytes - } -} - -#[derive(Default)] -/// Enables loading Rune scripts from `.rune` and `.rn` files. -pub struct RuneLoader; - -impl AssetLoader for RuneLoader { - fn load<'a>( - &'a self, - bytes: &'a [u8], - load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::utils::BoxedFuture<'a, Result<(), bevy::asset::Error>> { - Box::pin(async move { - load_context.set_default_asset(LoadedAsset::new(RuneFile { - bytes: bytes.into(), - })); - - Ok(()) - }) - } - - fn extensions(&self) -> &[&str] { - &["rune", "rn"] - } -} diff --git a/languages/bevy_mod_scripting_rune/src/assets.rs b/languages/bevy_mod_scripting_rune/src/assets.rs new file mode 100644 index 00000000..23be9f0f --- /dev/null +++ b/languages/bevy_mod_scripting_rune/src/assets.rs @@ -0,0 +1,46 @@ +use anyhow::Error; +use bevy::{ + asset::{io::Reader, Asset, AssetLoader, AsyncReadExt}, + reflect::TypePath, +}; +use bevy_mod_scripting_core::prelude::*; + +#[derive(Asset, TypePath, Debug)] +/// A loaded rune file in bytes. +pub struct RuneFile { + /// File content in bytes. + pub bytes: Vec, +} + +impl CodeAsset for RuneFile { + fn bytes(&self) -> &[u8] { + self.bytes.as_slice() + } +} + +#[derive(Default)] +/// Enables loading Rune scripts from `.rune` and `.rn` files. +pub struct RuneLoader; + +impl AssetLoader for RuneLoader { + type Asset = RuneFile; + type Settings = (); + type Error = Error; + + fn load<'a>( + &'a self, + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut bevy::asset::LoadContext, + ) -> bevy::utils::BoxedFuture<'a, Result> { + Box::pin(async move { + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + Ok(RuneFile { bytes }) + }) + } + + fn extensions(&self) -> &[&str] { + &["rune", "rn"] + } +} diff --git a/languages/bevy_mod_scripting_rune/src/lib.rs b/languages/bevy_mod_scripting_rune/src/lib.rs index 5683bde5..4c7dc065 100644 --- a/languages/bevy_mod_scripting_rune/src/lib.rs +++ b/languages/bevy_mod_scripting_rune/src/lib.rs @@ -12,12 +12,12 @@ use rune::{ Context, Diagnostics, Source, Sources, Unit, Vm, }; -mod assests; +mod assets; mod docs; pub mod prelude { pub use crate::{ - assests::{RuneFile, RuneLoader}, + assets::{RuneFile, RuneLoader}, docs::RuneDocFragment, RuneArgs, RuneEvent, RuneScriptContext, RuneScriptHost, }; @@ -120,7 +120,7 @@ impl ScriptHost for RuneScriptHost { set: impl SystemSet, ) { app.add_priority_event::() - .add_asset::() + .init_asset::() .init_asset_loader::() .init_resource::>() .init_resource::>() diff --git a/makefile b/makefile index 3a4ccffd..64ceeebe 100644 --- a/makefile +++ b/makefile @@ -58,22 +58,22 @@ generate_api: rustfmt ./bevy_script_api/src/generated.rs make_json_files: - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_asset@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_ecs@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_pbr@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_render@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_math@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_transform@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_sprite@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_ui@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_animation@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_core@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_core_pipeline@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_gltf@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_hierarchy@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_text@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_time@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_utils@0.11.0 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy_reflect@0.11.0 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_asset@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_ecs@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_pbr@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_render@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_math@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_transform@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_sprite@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_ui@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_animation@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_core@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_core_pipeline@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_gltf@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_hierarchy@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_text@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_time@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_utils@0.12.1 -- -Zunstable-options --output-format json && \ + rustup run nightly-2023-07-16 cargo rustdoc -p bevy_reflect@0.12.1 -- -Zunstable-options --output-format json && \ rustup run nightly-2023-07-16 cargo rustdoc -p glam@0.24.1 -- -Zunstable-options --output-format json && \ - rustup run nightly-2023-07-16 cargo rustdoc -p bevy@0.11.0 -- -Zunstable-options --output-format json + rustup run nightly-2023-07-16 cargo rustdoc -p bevy@0.12.1 -- -Zunstable-options --output-format json