summaryrefslogtreecommitdiff
path: root/engine-ecs/src/component.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-12-01 16:45:58 +0100
committerHampusM <hampus@hampusmat.com>2026-12-01 16:45:58 +0100
commit1d2ded384e2669d8f48a6b138b232d0eecd214d0 (patch)
tree024901d141e990dc059a8f30a89e6a9663477149 /engine-ecs/src/component.rs
parent607de6051f62652ac2799ec73ef0052436be5d62 (diff)
refactor(engine-ecs): store component::Info in component::Parts
Diffstat (limited to 'engine-ecs/src/component.rs')
-rw-r--r--engine-ecs/src/component.rs96
1 files changed, 55 insertions, 41 deletions
diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs
index a548518..3320102 100644
--- a/engine-ecs/src/component.rs
+++ b/engine-ecs/src/component.rs
@@ -263,11 +263,9 @@ pub trait IntoParts
pub struct Parts
{
pub id: Uid,
- pub name: Cow<'static, str>,
- pub type_name: &'static str,
pub is_sole: bool,
- pub type_reflection: Option<&'static TypeReflection>,
pub data: Box<dyn Any>,
+ pub component_info: Info,
pub pair_relation_metadata: Option<PairMemberMetadata>,
pub pair_target_metadata: Option<PairMemberMetadata>,
}
@@ -276,18 +274,12 @@ impl Parts
{
/// Creates components parts from the component information stored in
/// `component_info`.
- ///
- /// # Panics
- /// This function will panic if the type ID of the value in `data` does not equal
- /// to the type ID stored in `component_info`.
#[must_use]
pub fn from_component_info(component_info: &Info, id: Uid, data: Box<dyn Any>)
-> Self
{
Self::builder()
- .type_reflection(component_info.type_reflection)
- .name(component_info.name.clone())
- .type_name(component_info.type_name)
+ .component_info(component_info.clone())
.is_sole(component_info.is_sole)
.build_with_any_data(id, data)
}
@@ -310,10 +302,8 @@ impl IntoParts for Parts
#[derive(Debug)]
pub struct PartsBuilder
{
- name: Cow<'static, str>,
- type_name: &'static str,
is_sole: bool,
- type_reflection: Option<&'static TypeReflection>,
+ component_info: Info,
pair_relation_metadata: Option<PairMemberMetadata>,
pair_target_metadata: Option<PairMemberMetadata>,
}
@@ -321,16 +311,9 @@ pub struct PartsBuilder
impl PartsBuilder
{
#[must_use]
- pub fn name(mut self, name: impl Into<Cow<'static, str>>) -> Self
- {
- self.name = name.into();
- self
- }
-
- #[must_use]
- pub fn type_name(mut self, type_name: &'static str) -> Self
+ pub fn component_info(mut self, component_info: Info) -> Self
{
- self.type_name = type_name.into();
+ self.component_info = component_info;
self
}
@@ -342,16 +325,6 @@ impl PartsBuilder
}
#[must_use]
- pub fn type_reflection(
- mut self,
- type_reflection: Option<&'static TypeReflection>,
- ) -> Self
- {
- self.type_reflection = type_reflection;
- self
- }
-
- #[must_use]
pub fn pair_relation_metadata(mut self, metadata: Option<PairMemberMetadata>)
-> Self
{
@@ -371,11 +344,9 @@ impl PartsBuilder
{
Parts {
id,
- name: self.name,
- type_name: self.type_name,
is_sole: self.is_sole,
- type_reflection: self.type_reflection,
data: Box::new(data),
+ component_info: self.component_info,
pair_relation_metadata: self.pair_relation_metadata,
pair_target_metadata: self.pair_target_metadata,
}
@@ -386,11 +357,9 @@ impl PartsBuilder
{
Parts {
id,
- name: self.name,
- type_name: self.type_name,
is_sole: self.is_sole,
- type_reflection: self.type_reflection,
data,
+ component_info: self.component_info,
pair_relation_metadata: self.pair_relation_metadata,
pair_target_metadata: self.pair_target_metadata,
}
@@ -402,10 +371,8 @@ impl Default for PartsBuilder
fn default() -> Self
{
Self {
- name: "<unspecified>".into(),
- type_name: "<unspecified>",
is_sole: false,
- type_reflection: None,
+ component_info: Info::default(),
pair_relation_metadata: None,
pair_target_metadata: None,
}
@@ -422,6 +389,53 @@ pub struct Info
pub is_sole: bool,
}
+impl Default for Info
+{
+ fn default() -> Self
+ {
+ Self {
+ type_reflection: None,
+ name: "<unspecified>".into(),
+ type_name: "<unspecified>",
+ is_sole: false,
+ }
+ }
+}
+
+impl Info
+{
+ #[must_use]
+ pub fn with_name(mut self, name: impl Into<Cow<'static, str>>) -> Self
+ {
+ self.name = name.into();
+ self
+ }
+
+ #[must_use]
+ pub fn with_type_name(mut self, type_name: &'static str) -> Self
+ {
+ self.type_name = type_name.into();
+ self
+ }
+
+ #[must_use]
+ pub fn with_is_sole(mut self, is_sole: bool) -> Self
+ {
+ self.is_sole = is_sole;
+ self
+ }
+
+ #[must_use]
+ pub fn with_type_reflection(
+ mut self,
+ type_reflection: Option<&'static TypeReflection>,
+ ) -> Self
+ {
+ self.type_reflection = type_reflection;
+ self
+ }
+}
+
mod sealed
{
pub trait Sealed {}