use super::*;
pub fn sync_tool_stages(
service: Res<ToolServiceRes>,
entered: Query<(Entity, &StageJustEntered)>,
mut commands: Commands,
) {
crate::tick_scope::clear();
for (entity, stage) in entered.iter() {
crate::tick_scope::enter(entity);
service.0.sync_stage(entity, stage.index, &stage.name);
commands.entity(entity).remove::<StageJustEntered>();
}
}
pub fn refresh_advertised_tools(
service: Res<ToolServiceRes>,
mut agents: Query<
(
Entity,
&StageCursor,
&mut StageInference,
&mut StageInferences,
),
With<ToolsNeedRefresh>,
>,
mut commands: Commands,
) {
crate::tick_scope::clear();
for (entity, cursor, mut si, mut sis) in agents.iter_mut() {
crate::tick_scope::enter(entity);
if let Some(tools) = service.0.refresh_tools(entity, cursor.index) {
si.tools = tools.clone();
if let Some(slot) = sis.0.get_mut(cursor.index) {
slot.tools = tools;
}
}
commands.entity(entity).remove::<ToolsNeedRefresh>();
}
}
pub fn poll_dynamic_tool_refresh(
service: Res<ToolServiceRes>,
agents: Query<Entity, With<DynamicTools>>,
mut commands: Commands,
) {
crate::tick_scope::clear();
for entity in agents.iter() {
crate::tick_scope::enter(entity);
if service.0.wants_refresh(entity) {
commands.entity(entity).insert(ToolsNeedRefresh);
}
}
}