Skip to content

Commit

Permalink
Rename ReflectEventComponent into ReflectedValue in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Sep 6, 2023
1 parent ebbc0fc commit 1af4ddd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
10 changes: 5 additions & 5 deletions tests/client_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_replicon::prelude::*;

use common::{DummyEvent, ReflectEvent, ReflectEventDeserializer, ReflectEventSerializer};

use crate::common::ReflectEventComponent;
use crate::common::ReflectedValue;

#[test]
fn without_server_plugin() {
Expand Down Expand Up @@ -92,7 +92,7 @@ fn sending_receiving_reflect() {
let mut client_app = App::new();
for app in [&mut server_app, &mut client_app] {
app.add_plugins((MinimalPlugins, ReplicationPlugins))
.register_type::<ReflectEventComponent>()
.register_type::<ReflectedValue>()
.add_client_reflect_event::<ReflectEvent, ReflectEventSerializer, ReflectEventDeserializer>(
SendPolicy::Ordered,
);
Expand All @@ -105,7 +105,7 @@ fn sending_receiving_reflect() {
.resource_mut::<Events<ReflectEvent>>()
.send(ReflectEvent {
entity: Entity::PLACEHOLDER,
component: ReflectEventComponent.clone_value(),
reflect: ReflectedValue.clone_value(),
});

client_app.update();
Expand All @@ -123,7 +123,7 @@ fn mapping_and_sending_receiving_reflect() {
let mut client_app = App::new();
for app in [&mut server_app, &mut client_app] {
app.add_plugins((MinimalPlugins, ReplicationPlugins))
.register_type::<ReflectEventComponent>()
.register_type::<ReflectedValue>()
.add_mapped_client_reflect_event::<ReflectEvent, ReflectEventSerializer, ReflectEventDeserializer>(SendPolicy::Ordered);
}

Expand All @@ -141,7 +141,7 @@ fn mapping_and_sending_receiving_reflect() {
.resource_mut::<Events<ReflectEvent>>()
.send(ReflectEvent {
entity: client_entity,
component: ReflectEventComponent.clone_value(),
reflect: ReflectedValue.clone_value(),
});

client_app.update();
Expand Down
20 changes: 9 additions & 11 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ fn create_client(
(client, transport)
}

#[derive(Reflect, Debug)]
pub(super) struct ReflectEventComponent;

#[derive(Debug, Deserialize, Event, Serialize)]
pub(super) struct DummyEvent(pub(super) Entity);

Expand All @@ -141,10 +138,13 @@ impl MapEventEntities for DummyEvent {
}
}

#[derive(Reflect, Debug)]
pub(super) struct ReflectedValue;

#[derive(Debug, Event)]
pub(super) struct ReflectEvent {
pub(super) entity: Entity,
pub(super) component: Box<dyn Reflect>,
pub(super) reflect: Box<dyn Reflect>,
}

impl MapEventEntities for ReflectEvent {
Expand All @@ -158,7 +158,7 @@ impl MapEventEntities for ReflectEvent {
#[strum(serialize_all = "snake_case")]
enum ReflectEventField {
Entity,
Component,
Reflect,
}

pub(super) struct ReflectEventSerializer<'a> {
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Serialize for ReflectEventSerializer<'_> {
state.serialize_field(ReflectEventField::Entity.into(), &self.event.entity)?;
state.serialize_field(
ReflectEventField::Entity.into(),
&ReflectSerializer::new(&*self.event.component, self.registry),
&ReflectSerializer::new(&*self.event.reflect, self.registry),
)?;
state.end()
}
Expand Down Expand Up @@ -227,11 +227,9 @@ impl<'de> Visitor<'de> for ReflectEventDeserializer<'_> {
let entity = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(ReflectEventField::Entity as usize, &self))?;
let component = seq
let reflect = seq
.next_element_seed(UntypedReflectDeserializer::new(self.registry))?
.ok_or_else(|| {
de::Error::invalid_length(ReflectEventField::Component as usize, &self)
})?;
Ok(ReflectEvent { entity, component })
.ok_or_else(|| de::Error::invalid_length(ReflectEventField::Reflect as usize, &self))?;
Ok(ReflectEvent { entity, reflect })
}
}
10 changes: 5 additions & 5 deletions tests/server_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_replicon::prelude::*;

use common::{DummyEvent, ReflectEvent, ReflectEventDeserializer, ReflectEventSerializer};

use crate::common::ReflectEventComponent;
use crate::common::ReflectedValue;

#[test]
fn without_server_plugin() {
Expand Down Expand Up @@ -122,7 +122,7 @@ fn sending_receiving_reflect() {
MinimalPlugins,
ReplicationPlugins.set(ServerPlugin::new(TickPolicy::Manual)),
))
.register_type::<ReflectEventComponent>()
.register_type::<ReflectedValue>()
.add_server_reflect_event::<ReflectEvent, ReflectEventSerializer, ReflectEventDeserializer>(
SendPolicy::Ordered,
);
Expand All @@ -148,7 +148,7 @@ fn sending_receiving_reflect() {
mode,
event: ReflectEvent {
entity: Entity::PLACEHOLDER,
component: ReflectEventComponent.clone_value(),
reflect: ReflectedValue.clone_value(),
},
});

Expand All @@ -173,7 +173,7 @@ fn sending_receiving_and_mapping_reflect() {
MinimalPlugins,
ReplicationPlugins.set(ServerPlugin::new(TickPolicy::Manual)),
))
.register_type::<ReflectEventComponent>()
.register_type::<ReflectedValue>()
.add_mapped_server_reflect_event::<ReflectEvent, ReflectEventSerializer, ReflectEventDeserializer>(SendPolicy::Ordered);
}

Expand All @@ -193,7 +193,7 @@ fn sending_receiving_and_mapping_reflect() {
mode: SendMode::Broadcast,
event: ReflectEvent {
entity: server_entity,
component: ReflectEventComponent.clone_value(),
reflect: ReflectedValue.clone_value(),
},
});

Expand Down

0 comments on commit 1af4ddd

Please sign in to comment.