Skip to content

Commit 7292543

Browse files
committed
allow any component names
1 parent 449f3c5 commit 7292543

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

crates/bevy_mod_scripting_core/src/bindings/script_component.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ impl WorldAccessGuard<'_> {
7373
&self,
7474
component_name: String,
7575
) -> Result<ScriptComponentRegistration, InteropError> {
76-
if !component_name.starts_with("Script") {
77-
return Err(InteropError::unsupported_operation(
78-
None,
79-
None,
80-
"script registered component name must start with 'Script'",
81-
));
82-
}
8376
let component_registry = self.component_registry();
8477
let component_registry_read = component_registry.read();
8578
if component_registry_read.get(&component_name).is_some() {

crates/bevy_mod_scripting_core/src/bindings/world.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use super::{
2424
use crate::{
2525
bindings::{
2626
function::{from::FromScript, from_ref::FromScriptRef},
27-
with_access_read, with_access_write, ScriptComponent,
27+
with_access_read, with_access_write,
2828
},
2929
error::InteropError,
3030
reflection_extensions::PartialReflectExt,
@@ -978,39 +978,21 @@ impl WorldAccessGuard<'_> {
978978
pub fn get_component(
979979
&self,
980980
entity: Entity,
981-
component_id: ComponentId,
981+
component_registration: ScriptComponentRegistration,
982982
) -> Result<Option<ReflectReference>, InteropError> {
983983
let cell = self.as_unsafe_world_cell()?;
984984
let entity = cell
985985
.get_entity(entity)
986986
.ok_or_else(|| InteropError::missing_entity(entity))?;
987987

988-
let component_info = cell
989-
.components()
990-
.get_info(component_id)
991-
.ok_or_else(|| InteropError::invalid_component(component_id))?;
992-
993-
if entity.contains_id(component_id) {
994-
let type_id = component_info.type_id().or_else(|| {
995-
// check its a script component
996-
component_info
997-
.name()
998-
.starts_with("Script")
999-
.then_some(TypeId::of::<ScriptComponent>())
1000-
});
988+
if entity.contains_id(component_registration.component_id) {
1001989
Ok(Some(ReflectReference {
1002990
base: ReflectBaseType {
1003-
type_id: type_id.ok_or_else(|| {
1004-
InteropError::unsupported_operation(
1005-
None,
1006-
None,
1007-
format!(
1008-
"Component {} does not have a type id. Such components are not supported by BMS.",
1009-
component_id.display_without_world()
1010-
),
1011-
)
1012-
})?,
1013-
base_id: ReflectBase::Component(entity.id(), component_id),
991+
type_id: component_registration.type_registration().type_id(),
992+
base_id: ReflectBase::Component(
993+
entity.id(),
994+
component_registration.component_id,
995+
),
1014996
},
1015997
reflect_path: ParsedPath(vec![]),
1016998
}))

crates/bevy_mod_scripting_functions/src/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl World {
116116
) -> Result<Option<ReflectReference>, InteropError> {
117117
profiling::function_scope!("get_component");
118118
let world = ctxt.world()?;
119-
let val = world.get_component(*entity, registration.component_id())?;
119+
let val = world.get_component(*entity, registration.into_inner())?;
120120
Ok(val)
121121
}
122122

@@ -449,14 +449,14 @@ impl World {
449449
/// Registers a new component type with the world.
450450
///
451451
/// The component will behave like any other native component for all intents and purposes.
452-
/// The type that will be instantiated to back this component will be `ScriptComponent` which contains two fields:
452+
/// The type that will be instantiated to back this component will be `ScriptComponent` which contains just one field:
453453
/// - `data`
454454
///
455455
/// This field can be set to any value and modified freely.
456456
///
457457
/// Arguments:
458458
/// * `ctxt`: The function call context.
459-
/// * `name`: The name of the component type. The name MUST begin with `Script` or an error will be thrown
459+
/// * `name`: The name of the component type
460460
/// Returns:
461461
/// * `registration`: The registration of the new component type if successful.
462462
fn register_new_component(

0 commit comments

Comments
 (0)