Skip to content

Commit 3f0b3c2

Browse files
committed
wii: fix input
1 parent 886e845 commit 3f0b3c2

File tree

2 files changed

+156
-3
lines changed

2 files changed

+156
-3
lines changed

src/input/joystick_input.cpp

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ input::JoystickInput& input::JoystickInput::operator=(JoystickInput&& input) noe
5959
return std::make_unique<_3DSJoystickInput_Type1>(joystick, instance_id, name);
6060
}
6161

62-
#elif defined(__WII_)
62+
#elif defined(__WII__)
6363
if (guid == WiiJoystickInput_Type1::guid) {
6464
return std::make_unique<WiiJoystickInput_Type1>(joystick, instance_id, name);
6565
}
@@ -660,6 +660,157 @@ input::_3DSJoystickInput_Type1::default_settings_raw() const {
660660
return settings;
661661
}
662662

663+
#elif defined(__WII__)
664+
665+
input::WiiJoystickInput_Type1::WiiJoystickInput_Type1(
666+
SDL_Joystick* joystick,
667+
SDL_JoystickID instance_id,
668+
const std::string& name
669+
)
670+
: ConsoleJoystickInput{
671+
joystick,
672+
instance_id,
673+
name,
674+
//NOTE: this are not all, but atm only those, who can be checked with a SDL_JOYBUTTONDOWN event
675+
{
676+
{ "LEFT", JOYCON_LEFT },
677+
{ "RIGHT", JOYCON_RIGHT },
678+
{ "DOWN", JOYCON_DOWN },
679+
{ "UP", JOYCON_UP },
680+
{ "PLUS", JOYCON_PLUS },
681+
{ "MINUS", JOYCON_MINUS },
682+
{ "1", JOYCON_1 },
683+
{ "2", JOYCON_2 },
684+
{ "A", JOYCON_A },
685+
{ "B", JOYCON_B },
686+
{ "NUNCHUCK_C", NUNCHUK_C },
687+
{ "NUNCHUCK_Z", NUNCHUK_Z },
688+
{ "HOME", JOYCON_HOME },
689+
}
690+
} { }
691+
692+
693+
[[nodiscard]] helper::optional<input::NavigationEvent> input::WiiJoystickInput_Type1::get_navigation_event(
694+
const SDL_Event& event
695+
) const {
696+
if (event.type == SDL_JOYBUTTONDOWN) {
697+
698+
if (event.jbutton.which != instance_id()) {
699+
return helper::nullopt;
700+
}
701+
702+
switch (event.jbutton.button) {
703+
case JOYCON_A:
704+
return NavigationEvent::OK;
705+
case JOYCON_DOWN:
706+
return NavigationEvent::DOWN;
707+
case JOYCON_UP:
708+
return NavigationEvent::UP;
709+
case JOYCON_LEFT:
710+
return NavigationEvent::LEFT;
711+
case JOYCON_RIGHT:
712+
return NavigationEvent::RIGHT;
713+
case JOYCON_B:
714+
return NavigationEvent::BACK;
715+
default:
716+
return helper::nullopt;
717+
718+
//note, that NavigationEvent::TAB is not supported
719+
}
720+
}
721+
722+
return handle_axis_navigation_event(event);
723+
}
724+
725+
[[nodiscard]] std::string input::WiiJoystickInput_Type1::describe_navigation_event(NavigationEvent event) const {
726+
switch (event) {
727+
case NavigationEvent::OK:
728+
return "A";
729+
case NavigationEvent::BACK:
730+
return "B";
731+
case NavigationEvent::DOWN:
732+
return "Down";
733+
case NavigationEvent::UP:
734+
return "Up";
735+
case NavigationEvent::LEFT:
736+
return "Left";
737+
case NavigationEvent::RIGHT:
738+
return "Right";
739+
case NavigationEvent::TAB:
740+
throw std::runtime_error("Tab is not supported");
741+
default:
742+
utils::unreachable();
743+
}
744+
}
745+
746+
747+
[[nodiscard]] std::string input::WiiJoystickInput_Type1::key_to_string(console::SettingsType key) const {
748+
switch (key) {
749+
case JOYCON_LEFT:
750+
return "LEFT";
751+
case JOYCON_RIGHT:
752+
return "RIGHT";
753+
case JOYCON_DOWN:
754+
return "DOWN";
755+
case JOYCON_UP:
756+
return "UP";
757+
case JOYCON_PLUS:
758+
return "PLUS";
759+
case JOYCON_MINUS:
760+
return "MINUS";
761+
case JOYCON_1:
762+
return "1";
763+
case JOYCON_2:
764+
return "2";
765+
case JOYCON_A:
766+
return "A";
767+
case JOYCON_B:
768+
return "B";
769+
case NUNCHUK_C:
770+
return "NUNCHUCK_C";
771+
case NUNCHUK_Z:
772+
return "NUNCHUCK_Z";
773+
case JOYCON_HOME:
774+
return "HOME";
775+
776+
default:
777+
utils::unreachable();
778+
}
779+
}
780+
781+
[[nodiscard]] input::JoystickSettings input::WiiJoystickInput_Type1::to_normal_settings(
782+
const AbstractJoystickSettings<input::console::SettingsType>& settings
783+
) const {
784+
785+
JoystickSettings result{};
786+
787+
#define X_LIST_MACRO(x) SETTINGS_TO_STRING(settings, result, key_to_string, x);
788+
789+
X_LIST_OF_SETTINGS_KEYS
790+
791+
#undef X_LIST_MACRO
792+
793+
return result;
794+
}
795+
[[nodiscard]] input::AbstractJoystickSettings<input::console::SettingsType>
796+
input::WiiJoystickInput_Type1::default_settings_raw() const {
797+
const AbstractJoystickSettings<console::SettingsType> settings = //
798+
{
799+
.identification = JoystickIdentification{ .guid = WiiJoystickInput_Type1::guid, .name = "TODO" },
800+
.rotate_left = JOYCON_1,
801+
.rotate_right = JOYCON_2,
802+
.move_left = JOYCON_LEFT,
803+
.move_right = JOYCON_RIGHT,
804+
.move_down = JOYCON_DOWN,
805+
.drop = JOYCON_A,
806+
.hold = JOYCON_B,
807+
.pause = JOYCON_MINUS,
808+
.open_settings = JOYCON_PLUS
809+
};
810+
811+
return settings;
812+
}
813+
663814

664815
#endif
665816
#endif

tools/dependencies/meson.build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
only_allow_native_libs = false
22

33
if meson.is_cross_build()
4-
if host_machine.system() == 'switch' or host_machine.system() == '3ds'
4+
if host_machine.system() == 'switch' or host_machine.system() == '3ds' or host_machine.system() == 'wii'
55
# we do not link to code that was compiled with gcc 10.1 / gcc 7.1, the code we link with is all compiled with gcc 13.2
66
core_lib += {
77
'compile_args': [core_lib.get('compile_args'), '-Wno-psabi'],
@@ -32,7 +32,9 @@ fmt_use_header_only = false
3232
if (
3333
meson.is_cross_build()
3434
and (host_machine.system() == 'switch'
35-
or host_machine.system() == '3ds')
35+
or host_machine.system() == '3ds'
36+
or host_machine.system() == 'wii'
37+
)
3638
)
3739
fmt_use_header_only = true
3840
endif

0 commit comments

Comments
 (0)