Skip to content

Commit

Permalink
WIP, correct api gen, TODO: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Jul 17, 2023
1 parent 0405296 commit 0af6d4f
Show file tree
Hide file tree
Showing 21 changed files with 759 additions and 465 deletions.
4 changes: 0 additions & 4 deletions api_gen_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ source="bevy_ui"
type="CalculatedClip"
source="bevy_ui"

[[types]]
type="CalculatedSize"
source="bevy_ui"

[[types]]
type="Node"
source="bevy_ui"
Expand Down
2 changes: 1 addition & 1 deletion bevy_api_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ path = "src/main.rs"


[dependencies]
rustdoc-types = "0.19.0"
rustdoc-types = "0.22.0"
clap = { version = "3.2.6", features = ["derive"] }
serde_json = "1.0.81"
toml = "0.5.9"
Expand Down
5 changes: 3 additions & 2 deletions bevy_mod_scripting_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ pub trait AddScriptHostHandler {
///
/// Note: this is identical to adding the script_event_handler system manually, so if you require setting schedules etc, you should use that directly.
/// ```rust,ignore
/// self.add_system(
/// script_event_handler::<T, MAX, MIN>.in_set(set).in_schedule(MySchedule::SomeSchedule)
/// self.add_systems(
/// MySchedule,
/// script_event_handler::<T, MAX, MIN>.in_set(set)
/// );
/// ```
/// Think of handler system sets as a way to run certain types of events at specific points in your engine.
Expand Down
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 @@ -8,8 +8,9 @@ use crate::ScriptRef;
use bevy::{
ecs::system::Command,
prelude::{
AppTypeRegistry, BuildWorldChildren, Children, DespawnChildrenRecursive, DespawnRecursive,
Entity, Parent, ReflectComponent, ReflectDefault, ReflectResource,
despawn_with_children_recursive, AppTypeRegistry, BuildWorldChildren, Children,
DespawnChildrenRecursive, DespawnRecursive, Entity, Parent, ReflectComponent,
ReflectDefault, ReflectResource,
},
reflect::{
DynamicArray, DynamicEnum, DynamicList, DynamicMap, DynamicStruct, DynamicTuple,
Expand Down Expand Up @@ -141,12 +142,12 @@ impl ScriptWorld {

pub fn despawn_children_recursive(&self, entity: Entity) {
let mut w = self.write();
DespawnChildrenRecursive { entity }.write(&mut w);
DespawnChildrenRecursive { entity }.apply(&mut w);
}

pub fn despawn_recursive(&self, entity: Entity) {
let mut w = self.write();
DespawnRecursive { entity }.write(&mut w);
DespawnRecursive { entity }.apply(&mut w);
}

pub fn get_type_by_name(&self, type_name: &str) -> Option<ScriptTypeRegistration> {
Expand Down Expand Up @@ -183,8 +184,7 @@ impl ScriptWorld {
bevy::reflect::TypeInfo::List(_) => component_data.insert(&mut w.entity_mut(entity), &DynamicList::default()),
bevy::reflect::TypeInfo::Array(_) => component_data.insert(&mut w.entity_mut(entity), &DynamicArray::new(Box::new([]))),
bevy::reflect::TypeInfo::Map(_) => component_data.insert(&mut w.entity_mut(entity), &DynamicMap::default()),
bevy::reflect::TypeInfo::Value(_) |
bevy::reflect::TypeInfo::Dynamic(_) => component_data.insert(&mut w.entity_mut(entity),
bevy::reflect::TypeInfo::Value(_) => component_data.insert(&mut w.entity_mut(entity),
comp_type.data::<ReflectDefault>().ok_or_else(||
ScriptError::Other(format!("Component {} is a value or dynamic type with no `ReflectDefault` type_data, cannot instantiate sensible value",comp_type.short_name())))?
.default()
Expand Down
8 changes: 4 additions & 4 deletions bevy_script_api/src/common/std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::marker::PhantomData;

use bevy::reflect::FromReflect;
use bevy::reflect::{FromReflect, TypePath};

use crate::{error::ReflectionError, ScriptRef, ValueIndex};

Expand All @@ -26,7 +26,7 @@ impl<T> std::fmt::Debug for ScriptVec<T> {
}
}

impl<T: std::fmt::Display + FromReflect> std::fmt::Display for ScriptVec<T> {
impl<T: std::fmt::Display + FromReflect + TypePath> std::fmt::Display for ScriptVec<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = self
.ref_
Expand All @@ -39,7 +39,7 @@ impl<T: std::fmt::Display + FromReflect> std::fmt::Display for ScriptVec<T> {
}
}

impl<T: FromReflect> ScriptVec<T> {
impl<T: FromReflect + TypePath> ScriptVec<T> {
pub fn new_ref(ref_: ScriptRef) -> Self {
Self {
ref_,
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<T: FromReflect> Iterator for ScriptVecIterator<T> {
}
}

impl<T: FromReflect> IntoIterator for ScriptVec<T> {
impl<T: FromReflect + TypePath> IntoIterator for ScriptVec<T> {
type Item = ScriptRef;

type IntoIter = ScriptVecIterator<T>;
Expand Down
Loading

0 comments on commit 0af6d4f

Please sign in to comment.