@@ -135,13 +135,21 @@ impl<A: Actionlike> SummarizedActionState<A> {
135135 let mut dual_axis_state_map = HashMap :: default ( ) ;
136136 let mut triple_axis_state_map = HashMap :: default ( ) ;
137137
138- if let Some ( global_action_state) = global_action_state {
138+ println ! ( "action_state_resource check" ) ;
139+ if let Some ( global_action_state) = global_action_state
140+ && !global_action_state. disabled ( )
141+ {
142+ println ! ( "action_state_resource" ) ;
139143 let mut per_entity_button_state = HashMap :: default ( ) ;
140144 let mut per_entity_axis_state = HashMap :: default ( ) ;
141145 let mut per_entity_dual_axis_state = HashMap :: default ( ) ;
142146 let mut per_entity_triple_axis_state = HashMap :: default ( ) ;
143147
144- for ( action, action_data) in global_action_state. all_action_data ( ) {
148+ for ( action, action_data) in global_action_state
149+ . all_action_data ( )
150+ . iter ( )
151+ . filter ( |( _, action_data) | !action_data. disabled )
152+ {
145153 match & action_data. kind_data {
146154 ActionKindData :: Button ( button_data) => {
147155 per_entity_button_state
@@ -159,20 +167,26 @@ impl<A: Actionlike> SummarizedActionState<A> {
159167 }
160168 }
161169 }
162-
163170 button_state_map. insert ( Entity :: PLACEHOLDER , per_entity_button_state) ;
164171 axis_state_map. insert ( Entity :: PLACEHOLDER , per_entity_axis_state) ;
165172 dual_axis_state_map. insert ( Entity :: PLACEHOLDER , per_entity_dual_axis_state) ;
166173 triple_axis_state_map. insert ( Entity :: PLACEHOLDER , per_entity_triple_axis_state) ;
167174 }
168175
169- for ( entity, action_state) in action_state_query. iter ( ) {
176+ for ( entity, action_state) in action_state_query
177+ . iter ( )
178+ . filter ( |( _, action_state) | !action_state. disabled ( ) )
179+ {
170180 let mut per_entity_button_state = HashMap :: default ( ) ;
171181 let mut per_entity_axis_state = HashMap :: default ( ) ;
172182 let mut per_entity_dual_axis_state = HashMap :: default ( ) ;
173183 let mut per_entity_triple_axis_state = HashMap :: default ( ) ;
174184
175- for ( action, action_data) in action_state. all_action_data ( ) {
185+ for ( action, action_data) in action_state
186+ . all_action_data ( )
187+ . iter ( )
188+ . filter ( |( _, action_data) | !action_data. disabled )
189+ {
176190 match & action_data. kind_data {
177191 ActionKindData :: Button ( button_data) => {
178192 per_entity_button_state
@@ -519,4 +533,138 @@ mod tests {
519533 assert_eq ! ( action_diff_message. owner, Some ( entity) ) ;
520534 assert_eq ! ( action_diff_message. action_diffs. len( ) , 4 ) ;
521535 }
536+
537+ fn test_action_state_disabled ( ) -> ActionState < TestAction > {
538+ let mut action_state = ActionState :: default ( ) ;
539+ action_state. press ( & TestAction :: Button ) ;
540+ action_state. set_value ( & TestAction :: Axis , 0.3 ) ;
541+ action_state. set_axis_pair ( & TestAction :: DualAxis , Vec2 :: new ( 0.5 , 0.7 ) ) ;
542+ action_state. set_axis_triple ( & TestAction :: TripleAxis , Vec3 :: new ( 0.5 , 0.7 , 0.9 ) ) ;
543+ action_state. disable ( ) ;
544+ action_state
545+ }
546+
547+ fn expected_summary_when_disabled ( ) -> SummarizedActionState < TestAction > {
548+ let button_state_map = HashMap :: default ( ) ;
549+ let axis_state_map = HashMap :: default ( ) ;
550+ let dual_axis_state_map = HashMap :: default ( ) ;
551+ let triple_axis_state_map = HashMap :: default ( ) ;
552+
553+ SummarizedActionState {
554+ button_state_map,
555+ axis_state_map,
556+ dual_axis_state_map,
557+ triple_axis_state_map,
558+ }
559+ }
560+
561+ #[ test]
562+ fn summarize_filtered_from_disabled_component ( ) {
563+ let mut world = World :: new ( ) ;
564+ world. spawn ( ( test_action_state_disabled ( ) , NotSummarized ) ) ;
565+
566+ let mut system_state: SystemState < (
567+ Option < Res < ActionState < TestAction > > > ,
568+ Query < ( Entity , & ActionState < TestAction > ) , Without < NotSummarized > > ,
569+ ) > = SystemState :: new ( & mut world) ;
570+ let ( global_action_state, action_state_query) = system_state. get ( & world) ;
571+ let summarized =
572+ SummarizedActionState :: summarize_filtered ( global_action_state, action_state_query) ;
573+
574+ // Check that only the entity without NotSummarized was summarized
575+ assert_eq ! ( summarized, expected_summary_when_disabled( ) ) ;
576+ }
577+
578+ #[ test]
579+ fn summarize_filtered_from_disabled_resource ( ) {
580+ let mut world = World :: new ( ) ;
581+ world. insert_resource ( test_action_state_disabled ( ) ) ;
582+
583+ let mut system_state: SystemState < (
584+ Option < Res < ActionState < TestAction > > > ,
585+ Query < ( Entity , & ActionState < TestAction > ) , Without < NotSummarized > > ,
586+ ) > = SystemState :: new ( & mut world) ;
587+ let ( global_action_state, action_state_query) = system_state. get ( & world) ;
588+ let summarized =
589+ SummarizedActionState :: summarize_filtered ( global_action_state, action_state_query) ;
590+
591+ // Check that only the entity without NotSummarized was summarized
592+ assert_eq ! ( summarized, expected_summary_when_disabled( ) ) ;
593+ }
594+
595+ fn test_action_state_disabled_action ( ) -> ActionState < TestAction > {
596+ let mut action_state = ActionState :: default ( ) ;
597+ action_state. press ( & TestAction :: Button ) ;
598+ action_state. set_value ( & TestAction :: Axis , 0.3 ) ;
599+ action_state. set_axis_pair ( & TestAction :: DualAxis , Vec2 :: new ( 0.5 , 0.7 ) ) ;
600+ action_state. set_axis_triple ( & TestAction :: TripleAxis , Vec3 :: new ( 0.5 , 0.7 , 0.9 ) ) ;
601+ action_state. disable_action ( & TestAction :: Button ) ;
602+ action_state
603+ }
604+
605+ fn expected_summary_with_disabled_action ( entity : Entity ) -> SummarizedActionState < TestAction > {
606+ let mut button_state_map = HashMap :: default ( ) ;
607+ let mut axis_state_map = HashMap :: default ( ) ;
608+ let mut dual_axis_state_map = HashMap :: default ( ) ;
609+ let mut triple_axis_state_map = HashMap :: default ( ) ;
610+
611+ let global_button_state = HashMap :: default ( ) ;
612+ button_state_map. insert ( entity, global_button_state) ;
613+
614+ let mut global_axis_state = HashMap :: default ( ) ;
615+ global_axis_state. insert ( TestAction :: Axis , 0.3 ) ;
616+ axis_state_map. insert ( entity, global_axis_state) ;
617+
618+ let mut global_dual_axis_state = HashMap :: default ( ) ;
619+ global_dual_axis_state. insert ( TestAction :: DualAxis , Vec2 :: new ( 0.5 , 0.7 ) ) ;
620+ dual_axis_state_map. insert ( entity, global_dual_axis_state) ;
621+
622+ let mut global_triple_axis_state = HashMap :: default ( ) ;
623+ global_triple_axis_state. insert ( TestAction :: TripleAxis , Vec3 :: new ( 0.5 , 0.7 , 0.9 ) ) ;
624+ triple_axis_state_map. insert ( entity, global_triple_axis_state) ;
625+
626+ SummarizedActionState {
627+ button_state_map,
628+ axis_state_map,
629+ dual_axis_state_map,
630+ triple_axis_state_map,
631+ }
632+ }
633+
634+ #[ test]
635+ fn summarize_filtered_entites_from_component_disabled_action ( ) {
636+ let mut world = World :: new ( ) ;
637+ let entity = world. spawn ( test_action_state_disabled_action ( ) ) . id ( ) ;
638+
639+ let mut system_state: SystemState < (
640+ Option < Res < ActionState < TestAction > > > ,
641+ Query < ( Entity , & ActionState < TestAction > ) , Without < NotSummarized > > ,
642+ ) > = SystemState :: new ( & mut world) ;
643+ let ( global_action_state, action_state_query) = system_state. get ( & world) ;
644+ let summarized =
645+ SummarizedActionState :: summarize_filtered ( global_action_state, action_state_query) ;
646+
647+ // Check that only the entity without NotSummarized was summarized
648+ assert_eq ! ( summarized, expected_summary_with_disabled_action( entity) ) ;
649+ }
650+
651+ #[ test]
652+ fn summarize_filtered_entites_from_resource_disabled_action ( ) {
653+ let mut world = World :: new ( ) ;
654+ world. insert_resource ( test_action_state_disabled_action ( ) ) ;
655+
656+ let mut system_state: SystemState < (
657+ Option < Res < ActionState < TestAction > > > ,
658+ Query < ( Entity , & ActionState < TestAction > ) > ,
659+ ) > = SystemState :: new ( & mut world) ;
660+ let ( global_action_state, action_state_query) = system_state. get ( & world) ;
661+ let summarized =
662+ SummarizedActionState :: summarize_filtered ( global_action_state, action_state_query) ;
663+
664+ // Check that only the entity without NotSummarized was summarized
665+ assert_eq ! (
666+ summarized,
667+ expected_summary_with_disabled_action( Entity :: PLACEHOLDER )
668+ ) ;
669+ }
522670}
0 commit comments