diff --git a/RELEASES.md b/RELEASES.md index d69a6daf..0cf9c3cb 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -12,6 +12,10 @@ - Reflect `Component` and `Resource`, which enables accessing the data in the type registry +#### ActionDiffEvent + +- Implement `MapEntities`, which lets networking crates translate owner entity IDs between ECS worlds + ## Version 0.15.0 ### Enhancements (0.15) diff --git a/src/action_diff.rs b/src/action_diff.rs index 9e120fd6..6e2f1518 100644 --- a/src/action_diff.rs +++ b/src/action_diff.rs @@ -6,9 +6,12 @@ //! about things like keybindings or input devices. use bevy::{ - ecs::{entity::Entity, event::Event}, + ecs::{ + entity::{Entity, MapEntities}, + event::Event, + }, math::Vec2, - prelude::{EventWriter, Query, Res}, + prelude::{EntityMapper, EventWriter, Query, Res}, utils::{HashMap, HashSet}, }; use serde::{Deserialize, Serialize}; @@ -62,6 +65,16 @@ pub struct ActionDiffEvent { pub action_diffs: Vec>, } +/// Implements entity mapping for `ActionDiffEvent`. +/// +/// This allows the owner entity to be remapped when transferring event diffs +/// between different ECS worlds (e.g. client and server). +impl MapEntities for ActionDiffEvent { + fn map_entities(&mut self, entity_mapper: &mut M) { + self.owner = self.owner.map(|entity| entity_mapper.map_entity(entity)); + } +} + /// Stores the state of all actions in the current frame. /// /// Inside of the hashmap, [`Entity::PLACEHOLDER`] represents the global / resource state of the action.