Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleaning up + Fix for crash when looping through empty Vec #87

Merged
merged 27 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6424704
dwadwa
zwazel Nov 9, 2023
c73fef5
debug prints
zwazel Nov 9, 2023
06ff264
we ignore this ever happened
zwazel Nov 9, 2023
8879577
mmmmmmmmmmm
zwazel Nov 9, 2023
0c90755
does this fix the crash?
zwazel Nov 9, 2023
dd90053
that maybe fixes it
zwazel Nov 9, 2023
c19f6b1
unncessecary get_children + fixed get_parent
zwazel Nov 10, 2023
e1dcf0e
rustfmt
zwazel Nov 10, 2023
6a04b27
clippy
zwazel Nov 10, 2023
783dbf6
moved wrappers example into lua and renamed it
zwazel Nov 15, 2023
5ade1a8
WIP new example for rhai wrapper
zwazel Nov 15, 2023
eda744c
WIP implementing fix mentioned in review
zwazel Nov 15, 2023
5a56ddb
basic one shot works
zwazel Nov 15, 2023
59ac562
accessing variables work
zwazel Nov 15, 2023
c282ada
accessing variables not work
zwazel Nov 15, 2023
d4afc88
Revert "accessing variables not work"
zwazel Nov 15, 2023
478e105
empty array
zwazel Nov 15, 2023
b88e0c3
go back to <=
zwazel Nov 15, 2023
263e5f7
commented out errors, setting values seem to work
zwazel Nov 15, 2023
2c71be3
expanded multiple_events example for parent testing
zwazel Nov 15, 2023
17f0e81
returning UNIT instead of int if parent couldn't be found
zwazel Nov 15, 2023
dfa7caf
Update bevy_script_api/src/common/std.rs
zwazel Nov 17, 2023
1de2393
Update bevy_script_api/src/common/std.rs
zwazel Nov 17, 2023
bde4b3d
no longer problem at looping through empty vec
zwazel Nov 17, 2023
ec31d51
if/else to check if parent exists
zwazel Nov 18, 2023
adb1846
removed rhai wrapper example, moved normal wrapper example back and r…
zwazel Nov 18, 2023
3559bd1
rust fmt
zwazel Nov 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions bevy_mod_scripting_core/src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,25 @@ impl<T: Asset> Script<T> {
event_writer: &mut EventWriter<ScriptLoaded>,
) {
debug!("reloading script {}", script.id);
// retrieve owning entity
let entity = contexts.script_owner(script.id()).unwrap();

// remove old context
contexts.remove_context(script.id());

// insert new re-loaded context
Self::insert_new_script_context::<H>(
host,
script,
entity,
script_assets,
providers,
contexts,
event_writer,
);
// retrieve owning entity
if let Some(entity) = contexts.script_owner(script.id()) {
// remove old context
contexts.remove_context(script.id());
// insert new re-loaded context
Self::insert_new_script_context::<H>(
host,
script,
entity,
script_assets,
providers,
contexts,
event_writer,
);
} else {
// remove old context
contexts.remove_context(script.id());
}
zwazel marked this conversation as resolved.
Show resolved Hide resolved
}

/// checks if a script has loaded, and if so loads (`ScriptHost::load_script`),
Expand Down
5 changes: 3 additions & 2 deletions bevy_script_api/src/common/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ impl<T: FromReflect + TypePath> IntoIterator for ScriptVec<T> {
// TODO?: end used to be an Option, and this check moved into the next method but
// I am not sure if this will ever realistically fail, so if you do get this exception happening
// hit me with an issue
// if len > 0, subtract 1, otherwise set to 0
end: self
.len()
.map(|v| v - 1)
zwazel marked this conversation as resolved.
Show resolved Hide resolved
.expect("Could not access length when creating iterator"),
.map(|len| if len > 0 { len - 1 } else { 0 })
zwazel marked this conversation as resolved.
Show resolved Hide resolved
.expect("Failed to get length of ScriptVec"),
base: self,
}
}
Expand Down
21 changes: 9 additions & 12 deletions bevy_script_api/src/rhai/bevy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ impl CustomType for ScriptWorld {
.map(Dynamic::from)
.unwrap_or_default()
})
.with_fn("get_children", |self_: ScriptWorld, parent: Entity| {
self_
.get_children(parent)
.into_iter()
.map(Dynamic::from)
.collect::<Vec<_>>()
})
.with_fn(
"add_default_component",
|self_: ScriptWorld, entity: Entity, type_registration: ScriptTypeRegistration| {
Expand Down Expand Up @@ -138,15 +131,19 @@ impl CustomType for ScriptWorld {
})
},
)
.with_fn("get_children", |self_: &ScriptWorld, parent: Entity| {
.with_fn("get_parent", |self_: ScriptWorld, entity: Entity| {
if let Some(parent) = self_.get_parent(entity) {
zwazel marked this conversation as resolved.
Show resolved Hide resolved
Dynamic::from(parent)
} else {
Dynamic::from(-1)
}
})
.with_fn("get_children", |self_: ScriptWorld, parent: Entity| {
self_
.get_children(parent)
.into_iter()
.map(Dynamic::from)
.collect::<Vec<Dynamic>>()
})
.with_fn("get_parent", |self_: &ScriptWorld, entity: Entity| {
self_.get_parent(entity)
.collect::<Vec<_>>()
})
.with_fn(
"push_child",
Expand Down
Loading