summaryrefslogtreecommitdiff
path: root/engine-ecs/src/component.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src/component.rs')
-rw-r--r--engine-ecs/src/component.rs36
1 files changed, 28 insertions, 8 deletions
diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs
index 9220ffb..847ecbd 100644
--- a/engine-ecs/src/component.rs
+++ b/engine-ecs/src/component.rs
@@ -294,6 +294,7 @@ pub struct Parts
{
pub id: Uid,
pub name: &'static str,
+ pub is_sole: bool,
pub type_reflection: Option<&'static TypeReflection>,
pub data: Box<dyn Any>,
pub pair_relation_metadata: Option<PairMemberMetadata>,
@@ -302,6 +303,18 @@ pub struct Parts
impl Parts
{
+ pub fn from_component_info(component_info: &Info, id: Uid, data: Box<dyn Any>)
+ -> Self
+ {
+ assert_eq!((*data).type_id(), component_info.ty_id);
+
+ Self::builder()
+ .type_reflection(component_info.type_reflection)
+ .name(component_info.name)
+ .is_sole(component_info.is_sole)
+ .build_with_any_data(id, data)
+ }
+
#[must_use]
pub fn builder() -> PartsBuilder
{
@@ -313,6 +326,7 @@ impl Parts
pub struct PartsBuilder
{
name: &'static str,
+ is_sole: bool,
type_reflection: Option<&'static TypeReflection>,
pair_relation_metadata: Option<PairMemberMetadata>,
pair_target_metadata: Option<PairMemberMetadata>,
@@ -328,6 +342,13 @@ impl PartsBuilder
}
#[must_use]
+ pub fn is_sole(mut self, is_sole: bool) -> Self
+ {
+ self.is_sole = is_sole;
+ self
+ }
+
+ #[must_use]
pub fn type_reflection(
mut self,
type_reflection: Option<&'static TypeReflection>,
@@ -338,20 +359,15 @@ impl PartsBuilder
}
#[must_use]
- pub fn pair_relation_metadata(
- mut self,
- metadata: Option<PairMemberMetadata>,
- ) -> Self
+ pub fn pair_relation_metadata(mut self, metadata: Option<PairMemberMetadata>)
+ -> Self
{
self.pair_relation_metadata = metadata;
self
}
#[must_use]
- pub fn pair_target_metadata(
- mut self,
- metadata: Option<PairMemberMetadata>,
- ) -> Self
+ pub fn pair_target_metadata(mut self, metadata: Option<PairMemberMetadata>) -> Self
{
self.pair_target_metadata = metadata;
self
@@ -363,6 +379,7 @@ impl PartsBuilder
Parts {
id,
name: self.name,
+ is_sole: self.is_sole,
type_reflection: self.type_reflection,
data: Box::new(data),
pair_relation_metadata: self.pair_relation_metadata,
@@ -376,6 +393,7 @@ impl PartsBuilder
Parts {
id,
name: self.name,
+ is_sole: self.is_sole,
type_reflection: self.type_reflection,
data,
pair_relation_metadata: self.pair_relation_metadata,
@@ -390,6 +408,7 @@ impl Default for PartsBuilder
{
Self {
name: "(unspecified)",
+ is_sole: false,
type_reflection: None,
pair_relation_metadata: None,
pair_target_metadata: None,
@@ -404,4 +423,5 @@ pub struct Info
pub type_reflection: Option<&'static TypeReflection>,
pub ty_id: TypeId,
pub name: &'static str,
+ pub is_sole: bool,
}