Skip to content

Commit

Permalink
Bevy 0.12 migration (#93)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
LaserWitch and makspll authored Mar 5, 2024
1 parent 46dafba commit 17cf228
Show file tree
Hide file tree
Showing 41 changed files with 906 additions and 749 deletions.
27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
46 changes: 28 additions & 18 deletions api_gen_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ type="VisibleEntities"
source="bevy_render"

[[types]]
type="ComputedVisibility"
type="InheritedVisibility"
source="bevy_render"

[[types]]
type="ViewVisibility"
source="bevy_render"

[[types]]
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down Expand Up @@ -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()})
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion bevy_api_gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_api_gen"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
5 changes: 2 additions & 3 deletions bevy_api_gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions bevy_event_priority/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_event_priority"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -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}

2 changes: 1 addition & 1 deletion bevy_mod_scripting_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_common"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
8 changes: 4 additions & 4 deletions bevy_mod_scripting_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_core"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -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"

12 changes: 7 additions & 5 deletions bevy_mod_scripting_core/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn script_remove_synchronizer<H: ScriptHost>(
mut query: RemovedComponents<ScriptCollection<H::ScriptAsset>>,
mut contexts: ResMut<ScriptContexts<H::ScriptContext>>,
) {
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
Expand All @@ -121,10 +121,10 @@ pub fn script_hot_reload_handler<H: ScriptHost>(
mut contexts: ResMut<ScriptContexts<H::ScriptContext>>,
mut event_writer: EventWriter<ScriptLoaded>,
) {
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,
};

Expand All @@ -137,7 +137,9 @@ pub fn script_hot_reload_handler<H: ScriptHost>(
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::<H::ScriptAsset>::reload_script::<H>(
&mut host,
script,
Expand Down
4 changes: 2 additions & 2 deletions bevy_mod_scripting_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_derive"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -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"
Expand Down
26 changes: 13 additions & 13 deletions bevy_script_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_script_api"
version = "0.3.0"
version = "0.4.0"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -13,26 +13,26 @@ 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='^(?P<h>bevy_mod_scripting_derive\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{file="Cargo.toml", search='^(?P<h>bevy_mod_scripting_core\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{file="Cargo.toml", search='^(?P<h>bevy_mod_scripting_lua\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{file="Cargo.toml", search='^(?P<h>bevy_mod_scripting_lua_derive\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{file="Cargo.toml", search='^(?P<h>bevy_mod_scripting_rhai\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{ file = "Cargo.toml", search='^version\s*=\s*.*$', replace="version = \"{{version}}\"", exactly=1},
{ file = "Cargo.toml", search='^(?P<h>bevy_mod_scripting_derive\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{ file = "Cargo.toml", search='^(?P<h>bevy_mod_scripting_core\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{ file = "Cargo.toml", search='^(?P<h>bevy_mod_scripting_lua\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{ file = "Cargo.toml", search='^(?P<h>bevy_mod_scripting_lua_derive\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
{ file = "Cargo.toml", search='^(?P<h>bevy_mod_scripting_rhai\s*=.*)version\s*=\s*".*"(?P<t>.*)$', replace="${h}version = \"{{version}}\"${t}", exactly=1},
]

[features]
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}
12 changes: 6 additions & 6 deletions bevy_script_api/src/common/bevy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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())))
}

Expand Down
Loading

0 comments on commit 17cf228

Please sign in to comment.