@@ -80,7 +80,7 @@ pub trait AppVisibilityExt {
8080 type ClientComponent = Self;
8181 type Scope = Entity;
8282
83- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
83+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
8484 client_component.is_some_and(|c| self == c)
8585 }
8686 }
@@ -116,7 +116,7 @@ fn update_for_new_clients<F: VisibilityFilter>(
116116 if let Ok ( mut visibility) = clients. get_mut ( insert. entity ) {
117117 let bit = registry. bit :: < F > ( ) ;
118118 for ( entity, component) in & entities {
119- let visible = component. is_visible ( None ) ;
119+ let visible = component. is_visible ( insert . entity , None ) ;
120120 debug ! (
121121 "evaluating missing `{}` for new client `{}` for entity `{entity}` to `{visible}`" ,
122122 ShortName :: of:: <F >( ) ,
@@ -136,7 +136,7 @@ fn on_insert<F: VisibilityFilter>(
136136 let bit = registry. bit :: < F > ( ) ;
137137 if let Ok ( ( client, client_component, mut visibility) ) = clients. get_mut ( insert. entity ) {
138138 for ( entity, component) in & entities {
139- let visible = component. is_visible ( client_component) ;
139+ let visible = component. is_visible ( client , client_component) ;
140140 debug ! (
141141 "evaluating inserted `{}` to client `{client}` for entity `{entity}` to `{visible}`" ,
142142 ShortName :: of:: <F >( ) ,
@@ -146,7 +146,7 @@ fn on_insert<F: VisibilityFilter>(
146146 } else {
147147 let ( entity, component) = entities. get ( insert. entity ) . unwrap ( ) ;
148148 for ( client, client_component, mut visibility) in & mut clients {
149- let visible = component. is_visible ( client_component) ;
149+ let visible = component. is_visible ( client , client_component) ;
150150 debug ! (
151151 "evaluating inserted `{}` to entity `{entity}` for client `{client}` to `{visible}`" ,
152152 ShortName :: of:: <F >( ) ,
@@ -190,7 +190,7 @@ fn on_client_remove<F: VisibilityFilter>(
190190
191191 let bit = registry. bit :: < F > ( ) ;
192192 for ( entity, component) in & entities {
193- let visible = component. is_visible ( None ) ;
193+ let visible = component. is_visible ( remove . entity , None ) ;
194194 debug ! (
195195 "evaluating removed `{}` from client `{}` for entity `{entity}` to `{visible}`" ,
196196 ShortName :: of:: <F >( ) ,
@@ -226,7 +226,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
226226 type ClientComponent = Moderator;
227227 type Scope = Entity;
228228
229- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
229+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
230230 // Only moderators can see entities with sensitive information.
231231 client_component.is_some()
232232 }
@@ -246,7 +246,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
246246 type ClientComponent = Self;
247247 type Scope = Entity;
248248
249- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
249+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
250250 // Visible only if the client also has `SpectatorOnly`.
251251 client_component.is_some()
252252 }
@@ -276,7 +276,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
276276 /// type ClientComponent = Self;
277277 /// type Scope = Entity;
278278 ///
279- /// fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
279+ /// fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
280280 /// client_component.is_some_and(|c| self == c)
281281 /// }
282282 /// }
@@ -295,7 +295,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
295295 /// type ClientComponent = Self;
296296 /// type Scope = SingleComponent<Health>;
297297 ///
298- /// fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
298+ /// fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
299299 /// client_component.is_some_and(|c| self == c)
300300 /// }
301301 /// }
@@ -317,7 +317,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
317317 /// type ClientComponent = Self;
318318 /// type Scope = (Health, Stats);
319319 ///
320- /// fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
320+ /// fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
321321 /// client_component.is_some_and(|c| self == c)
322322 /// }
323323 /// }
@@ -352,7 +352,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
352352 type ClientComponent = Self;
353353 type Scope = Entity;
354354
355- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
355+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
356356 client_component.is_some()
357357 }
358358 }
@@ -375,7 +375,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
375375 type ClientComponent = Unit;
376376 type Scope = Entity;
377377
378- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
378+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
379379 // Blind clients cannot see units.
380380 client_component.is_none()
381381 }
@@ -395,7 +395,7 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
395395 type ClientComponent = Self;
396396 type Scope = Entity;
397397
398- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
398+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
399399 // Visible if the client belongs to the same team.
400400 client_component.is_some_and(|c| self == c)
401401 }
@@ -424,13 +424,32 @@ pub trait VisibilityFilter: Component<Mutability = Immutable> {
424424 type ClientComponent = Self;
425425 type Scope = Entity;
426426
427- fn is_visible(&self, client_component: Option<&Self::ClientComponent>) -> bool {
427+ fn is_visible(&self, _client: Entity, client_component: Option<&Self::ClientComponent>) -> bool {
428428 client_component.is_some_and(|&c| self.contains(c))
429429 }
430430 }
431431 ```
432+
433+ Visible if the component references the client entity:
434+
435+ ```
436+ # use bevy::prelude::*;
437+ # use bevy_replicon::prelude::*;
438+ #[derive(Component, PartialEq)]
439+ #[component(immutable)]
440+ struct Owner(Entity);
441+
442+ impl VisibilityFilter for Owner {
443+ type ClientComponent = AuthorizedClient; // All clients authorized for replication have this component.
444+ type Scope = Entity;
445+
446+ fn is_visible(&self, client: Entity, _client_component: Option<&Self::ClientComponent>) -> bool {
447+ self.0 == client
448+ }
449+ }
450+ ```
432451 */
433- fn is_visible ( & self , client_component : Option < & Self :: ClientComponent > ) -> bool ;
452+ fn is_visible ( & self , client : Entity , client_component : Option < & Self :: ClientComponent > ) -> bool ;
434453}
435454
436455/// Associates the type with a visibility scope.
@@ -642,7 +661,11 @@ mod tests {
642661 type ClientComponent = Self ;
643662 type Scope = Entity ;
644663
645- fn is_visible ( & self , client_component : Option < & Self :: ClientComponent > ) -> bool {
664+ fn is_visible (
665+ & self ,
666+ _client : Entity ,
667+ client_component : Option < & Self :: ClientComponent > ,
668+ ) -> bool {
646669 client_component. is_some ( )
647670 }
648671 }
@@ -655,7 +678,11 @@ mod tests {
655678 type ClientComponent = ClientFilter ;
656679 type Scope = Entity ;
657680
658- fn is_visible ( & self , client_component : Option < & Self :: ClientComponent > ) -> bool {
681+ fn is_visible (
682+ & self ,
683+ _client : Entity ,
684+ client_component : Option < & Self :: ClientComponent > ,
685+ ) -> bool {
659686 client_component. is_some ( )
660687 }
661688 }
0 commit comments