-
Notifications
You must be signed in to change notification settings - Fork 15
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
Refactor optional model properties #263
base: main
Are you sure you want to change the base?
Changes from 25 commits
4f8f1ba
2923bf6
5b35ec3
f65bbda
e33e360
4de0f3a
b3111a2
a312a10
e332401
88d0ed1
19a8274
3274b60
edd54cc
dcdf8b3
3fae5da
a8ff8d7
c69b6ce
6c09af4
98f3dba
5652be2
538ebd8
7985a80
d93a4db
a173474
bc769fa
3b1e85b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,17 +33,19 @@ pub fn update_model_instance_visual_cues( | |
&mut Selected, | ||
&mut Hovered, | ||
&mut Affiliation<Entity>, | ||
Option<Ref<Tasks<Entity>>>, | ||
Option<Ref<Tasks>>, | ||
), | ||
(With<ModelMarker>, Without<Group>), | ||
>, | ||
mut locations: Query<(&mut Selected, &mut Hovered), (With<LocationTags>, Without<ModelMarker>)>, | ||
mut removed_components: RemovedComponents<Tasks<Entity>>, | ||
mut locations: Query< | ||
(&NameInSite, &mut Selected, &mut Hovered), | ||
(With<LocationTags>, Without<ModelMarker>), | ||
>, | ||
mut removed_components: RemovedComponents<Tasks>, | ||
) { | ||
for (instance_entity, mut instance_selected, mut instance_hovered, affiliation, tasks) in | ||
&mut model_instances | ||
{ | ||
let mut is_description_selected = false; | ||
if let Some(description_entity) = affiliation.0 { | ||
if let Ok((_, description_selected, description_hovered)) = | ||
model_descriptions.get(description_entity) | ||
|
@@ -52,7 +54,6 @@ pub fn update_model_instance_visual_cues( | |
instance_selected | ||
.support_selected | ||
.insert(description_entity); | ||
is_description_selected = true; | ||
} else { | ||
instance_selected | ||
.support_selected | ||
|
@@ -72,34 +73,18 @@ pub fn update_model_instance_visual_cues( | |
if let Some(tasks) = tasks { | ||
// When tasks for an instance have changed, reset all locations from supporting this instance | ||
if tasks.is_changed() { | ||
for (mut location_selected, mut location_hovered) in locations.iter_mut() { | ||
for (_, mut location_selected, mut location_hovered) in locations.iter_mut() { | ||
location_selected.support_selected.remove(&instance_entity); | ||
location_hovered.support_hovering.remove(&instance_entity); | ||
} | ||
} | ||
|
||
if let Some(task_location) = tasks.0.first().and_then(|t| t.location()) { | ||
if let Ok((mut location_selected, mut location_hovered)) = | ||
locations.get_mut(task_location.0) | ||
{ | ||
if instance_selected.cue() && !is_description_selected { | ||
location_selected.support_selected.insert(instance_entity); | ||
} else { | ||
location_selected.support_selected.remove(&instance_entity); | ||
} | ||
if instance_hovered.cue() { | ||
location_hovered.support_hovering.insert(instance_entity); | ||
} else { | ||
location_hovered.support_hovering.remove(&instance_entity); | ||
} | ||
} | ||
} | ||
// TODO(@xiyuoh) support task-based visual cues | ||
} | ||
} | ||
|
||
// When instances are removed, prevent any location from supporting them | ||
for removed in removed_components.read() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed any longer either. |
||
for (mut location_selected, mut location_hovered) in locations.iter_mut() { | ||
for (_, mut location_selected, mut location_hovered) in locations.iter_mut() { | ||
location_selected.support_selected.remove(&removed); | ||
location_hovered.support_hovering.remove(&removed); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,18 +348,21 @@ fn generate_site_entities( | |
model_description_dependents.insert(model_description_entity, HashSet::new()); | ||
model_description_to_source | ||
.insert(model_description_entity, model_description.source.0.clone()); | ||
// Insert optional model properties | ||
for optional_property in &model_description.optional_properties.0 { | ||
match optional_property { | ||
OptionalModelProperty::DifferentialDrive(diff_drive) => commands | ||
.entity(model_description_entity) | ||
.insert(ModelProperty(diff_drive.clone())), | ||
OptionalModelProperty::MobileRobotMarker(robot_marker) => commands | ||
.entity(model_description_entity) | ||
.insert(ModelProperty(robot_marker.clone())), | ||
_ => continue, | ||
}; | ||
} | ||
} | ||
|
||
for (robot_id, robot_data) in &site_data.robots { | ||
// Robot IDs are pointing to model description entities | ||
if let Some(model_description_entity) = id_to_entity | ||
.get(robot_id) | ||
.filter(|e| model_description_to_source.contains_key(*e)) | ||
{ | ||
commands | ||
.entity(*model_description_entity) | ||
.insert(ModelProperty(robot_data.clone())); | ||
} else { | ||
// TODO(@xiyuoh) consider creating an entity if not found | ||
error!("Robot is pointing to a non-existent model description!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's include the |
||
}; | ||
} | ||
|
||
for (model_instance_id, parented_model_instance) in &site_data.model_instances { | ||
|
@@ -396,15 +399,8 @@ fn generate_site_entities( | |
model_instance.name.0, | ||
); | ||
} | ||
|
||
// Insert optional model properties | ||
for optional_property in &model_instance.optional_properties.0 { | ||
match optional_property { | ||
OptionalModelProperty::Tasks(tasks) => { | ||
commands.entity(model_instance_entity).insert(tasks.clone()) | ||
} | ||
_ => continue, | ||
}; | ||
if let Some(tasks) = site_data.tasks.get(model_instance_id) { | ||
commands.entity(model_instance_entity).insert(tasks.clone()); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this isn't hurting anything, but I don't believe any of this block is needed any longer.