@@ -45,7 +45,7 @@ input::JoystickInput& input::JoystickInput::operator=(JoystickInput&& input) noe
4545 return std::make_unique<_3DSJoystickInput_Type1>(joystick, instance_id, name);
4646 }
4747
48- #elif defined(__WII_ )
48+ #elif defined(__WII__ )
4949 if (guid == WiiJoystickInput_Type1::guid) {
5050 return std::make_unique<WiiJoystickInput_Type1>(joystick, instance_id, name);
5151 }
@@ -565,6 +565,157 @@ input::_3DSJoystickInput_Type1::default_settings_raw() const {
565565 return settings;
566566}
567567
568+ #elif defined(__WII__)
569+
570+ input::WiiJoystickInput_Type1::WiiJoystickInput_Type1 (
571+ SDL_Joystick* joystick,
572+ SDL_JoystickID instance_id,
573+ const std::string& name
574+ )
575+ : ConsoleJoystickInput{
576+ joystick,
577+ instance_id,
578+ name,
579+ // NOTE: this are not all, but atm only those, who can be checked with a SDL_JOYBUTTONDOWN event
580+ {
581+ { " LEFT" , JOYCON_LEFT },
582+ { " RIGHT" , JOYCON_RIGHT },
583+ { " DOWN" , JOYCON_DOWN },
584+ { " UP" , JOYCON_UP },
585+ { " PLUS" , JOYCON_PLUS },
586+ { " MINUS" , JOYCON_MINUS },
587+ { " 1" , JOYCON_1 },
588+ { " 2" , JOYCON_2 },
589+ { " A" , JOYCON_A },
590+ { " B" , JOYCON_B },
591+ { " NUNCHUCK_C" , NUNCHUK_C },
592+ { " NUNCHUCK_Z" , NUNCHUK_Z },
593+ { " HOME" , JOYCON_HOME },
594+ }
595+ } { }
596+
597+
598+ [[nodiscard]] helper::optional<input::NavigationEvent> input::WiiJoystickInput_Type1::get_navigation_event (
599+ const SDL_Event& event
600+ ) const {
601+ if (event.type == SDL_JOYBUTTONDOWN) {
602+
603+ if (event.jbutton .which != instance_id ()) {
604+ return helper::nullopt ;
605+ }
606+
607+ switch (event.jbutton .button ) {
608+ case JOYCON_A:
609+ return NavigationEvent::OK;
610+ case JOYCON_DOWN:
611+ return NavigationEvent::DOWN;
612+ case JOYCON_UP:
613+ return NavigationEvent::UP;
614+ case JOYCON_LEFT:
615+ return NavigationEvent::LEFT;
616+ case JOYCON_RIGHT:
617+ return NavigationEvent::RIGHT;
618+ case JOYCON_B:
619+ return NavigationEvent::BACK;
620+ default :
621+ return helper::nullopt ;
622+
623+ // note, that NavigationEvent::TAB is not supported
624+ }
625+ }
626+
627+ return handle_axis_navigation_event (event);
628+ }
629+
630+ [[nodiscard]] std::string input::WiiJoystickInput_Type1::describe_navigation_event (NavigationEvent event) const {
631+ switch (event) {
632+ case NavigationEvent::OK:
633+ return " A" ;
634+ case NavigationEvent::BACK:
635+ return " B" ;
636+ case NavigationEvent::DOWN:
637+ return " Down" ;
638+ case NavigationEvent::UP:
639+ return " Up" ;
640+ case NavigationEvent::LEFT:
641+ return " Left" ;
642+ case NavigationEvent::RIGHT:
643+ return " Right" ;
644+ case NavigationEvent::TAB:
645+ throw std::runtime_error (" Tab is not supported" );
646+ default :
647+ utils::unreachable ();
648+ }
649+ }
650+
651+
652+ [[nodiscard]] std::string input::WiiJoystickInput_Type1::key_to_string (console::SettingsType key) const {
653+ switch (key) {
654+ case JOYCON_LEFT:
655+ return " LEFT" ;
656+ case JOYCON_RIGHT:
657+ return " RIGHT" ;
658+ case JOYCON_DOWN:
659+ return " DOWN" ;
660+ case JOYCON_UP:
661+ return " UP" ;
662+ case JOYCON_PLUS:
663+ return " PLUS" ;
664+ case JOYCON_MINUS:
665+ return " MINUS" ;
666+ case JOYCON_1:
667+ return " 1" ;
668+ case JOYCON_2:
669+ return " 2" ;
670+ case JOYCON_A:
671+ return " A" ;
672+ case JOYCON_B:
673+ return " B" ;
674+ case NUNCHUK_C:
675+ return " NUNCHUCK_C" ;
676+ case NUNCHUK_Z:
677+ return " NUNCHUCK_Z" ;
678+ case JOYCON_HOME:
679+ return " HOME" ;
680+
681+ default :
682+ utils::unreachable ();
683+ }
684+ }
685+
686+ [[nodiscard]] input::JoystickSettings input::WiiJoystickInput_Type1::to_normal_settings (
687+ const AbstractJoystickSettings<input::console::SettingsType>& settings
688+ ) const {
689+
690+ JoystickSettings result{};
691+
692+ #define X_LIST_MACRO (x ) SETTINGS_TO_STRING(settings, result, key_to_string, x);
693+
694+ X_LIST_OF_SETTINGS_KEYS
695+
696+ #undef X_LIST_MACRO
697+
698+ return result;
699+ }
700+ [[nodiscard]] input::AbstractJoystickSettings<input::console::SettingsType>
701+ input::WiiJoystickInput_Type1::default_settings_raw () const {
702+ const AbstractJoystickSettings<console::SettingsType> settings = //
703+ {
704+ .identification = JoystickIdentification{ .guid = WiiJoystickInput_Type1::guid, .name = " TODO" },
705+ .rotate_left = JOYCON_1,
706+ .rotate_right = JOYCON_2,
707+ .move_left = JOYCON_LEFT,
708+ .move_right = JOYCON_RIGHT,
709+ .move_down = JOYCON_DOWN,
710+ .drop = JOYCON_A,
711+ .hold = JOYCON_B,
712+ .pause = JOYCON_MINUS,
713+ .open_settings = JOYCON_PLUS
714+ };
715+
716+ return settings;
717+ }
718+
568719
569720#endif
570721#endif
0 commit comments