I'm making an ARPG where side effects are decoupled from abilities
fn ability_attack(
mut commands: Commands,
mut tilemap_query: Query<(
&TilemapSize,
&TilemapGridSize,
&TilemapType,
&mut TileStorage,
&Transform,
)>,
cursor_position: Res<CursorPosition>,
action_state_query: Query<&ActionState<Ability>>,
) {
for action_state in action_state_query.iter() {
if action_state.just_pressed(&Ability::Attack) {
for (map_size, grid_size, map_type, mut tile_storage, map_transform) in
tilemap_query.iter_mut()
{
// ...
// Once we have a world position we can transform it into a possible tile position.
if let Some(tile_pos) =
TilePos::from_world_pos(&cursor_in_map_pos, map_size, grid_size, map_type)
{
if let Some(tile_entity) = tile_storage.get(&tile_pos) {
commands
.entity(tile_entity)
.insert((EffectDamageTile { damage: 1.0, },));
}
}
}
}
}
}
This is all good, but when I apply the damage on a different system there's no way to update the tile storages by entity
fn apply_tile_damage(
mut commands: Commands,
effect_query: Query<(Entity, &EffectDamageTile)>,
mut tilemap_query: Query<&mut TileStorage>,
) {
for (entity, effect, prior_damage, noise) in &effect_query {
for mut tile_storage in &mut tilemap_query {
if let Some(tile_entity) = tile_storage.get(&effect.tile_pos) {
tile_storage.remove(entity); // <- this impl doesn't exist
}
}
commands.entity(entity).despawn();
}
}
You can only do tile_storage.remove with TilePos, which is local to each chunk 💀

