@@ -114,7 +114,7 @@ static PyObject* set_gc_buttons(PyObject* module, PyObject* args)
114114 Py_RETURN_NONE;
115115}
116116
117- static PyObject* get_wii_buttons (PyObject* module , PyObject* args)
117+ static PyObject* get_wiimote_buttons (PyObject* module , PyObject* args)
118118{
119119 const auto controller_id_opt = Py::ParseTuple<int >(args);
120120 if (!controller_id_opt.has_value ())
@@ -139,7 +139,7 @@ static PyObject* get_wii_buttons(PyObject* module, PyObject* args)
139139 );
140140}
141141
142- static PyObject* set_wii_buttons (PyObject* module , PyObject* args)
142+ static PyObject* set_wiimote_buttons (PyObject* module , PyObject* args)
143143{
144144 int controller_id;
145145 PyObject* dict;
@@ -179,7 +179,7 @@ static PyObject* set_wii_buttons(PyObject* module, PyObject* args)
179179 Py_RETURN_NONE;
180180}
181181
182- static PyObject* get_wii_pointer (PyObject* module , PyObject* args)
182+ static PyObject* get_wiimote_pointer (PyObject* module , PyObject* args)
183183{
184184 const auto controller_id_opt = Py::ParseTuple<int >(args);
185185 if (!controller_id_opt.has_value ())
@@ -190,7 +190,7 @@ static PyObject* get_wii_pointer(PyObject* module, PyObject* args)
190190 state->wii_manip ->Get (controller_id, API::InputKey::WII_IR_Y));
191191}
192192
193- static PyObject* set_wii_pointer (PyObject* module , PyObject* args)
193+ static PyObject* set_wiimote_pointer (PyObject* module , PyObject* args)
194194{
195195 int controller_id;
196196 float x, y;
@@ -202,7 +202,7 @@ static PyObject* set_wii_pointer(PyObject* module, PyObject* args)
202202 Py_RETURN_NONE;
203203}
204204
205- static PyObject* get_wii_acceleration (PyObject* module , PyObject* args)
205+ static PyObject* get_wiimote_acceleration (PyObject* module , PyObject* args)
206206{
207207 const auto controller_id_opt = Py::ParseTuple<int >(args);
208208 if (!controller_id_opt.has_value ())
@@ -214,7 +214,7 @@ static PyObject* get_wii_acceleration(PyObject* module, PyObject* args)
214214 state->wii_manip ->Get (controller_id, API::InputKey::WII_ACCELERATION_Z));
215215}
216216
217- static PyObject* set_wii_acceleration (PyObject* module , PyObject* args)
217+ static PyObject* set_wiimote_acceleration (PyObject* module , PyObject* args)
218218{
219219 int controller_id;
220220 float x, y, z;
@@ -227,7 +227,7 @@ static PyObject* set_wii_acceleration(PyObject* module, PyObject* args)
227227 Py_RETURN_NONE;
228228}
229229
230- static PyObject* get_wii_angular_velocity (PyObject* module , PyObject* args)
230+ static PyObject* get_wiimote_angular_velocity (PyObject* module , PyObject* args)
231231{
232232 const auto controller_id_opt = Py::ParseTuple<int >(args);
233233 if (!controller_id_opt.has_value ())
@@ -240,7 +240,7 @@ static PyObject* get_wii_angular_velocity(PyObject* module, PyObject* args)
240240 state->wii_manip ->Get (controller_id, API::InputKey::WII_ANGULAR_VELOCITY_Z));
241241}
242242
243- static PyObject* set_wii_angular_velocity (PyObject* module , PyObject* args)
243+ static PyObject* set_wiimote_angular_velocity (PyObject* module , PyObject* args)
244244{
245245 int controller_id;
246246 float x, y, z;
@@ -532,6 +532,121 @@ static PyObject* set_gba_buttons(PyObject* module, PyObject* args)
532532
533533static void setup_controller_module (PyObject* module , ControllerModuleState* state)
534534{
535+ static const char pycode[] = R"(
536+ # The typed dicts are also defined here make them available at runtime.
537+ # They are copied from controller.pyi and should stay in sync with that file.
538+ from typing import TypedDict
539+
540+
541+ class GCInputs(TypedDict, total=False):
542+ """
543+ Dictionary describing the state of a GameCube controller.
544+ Boolean keys (buttons): True means pressed, False means released.
545+ Float keys for triggers: 0 means fully released, 1 means fully pressed.
546+ Float keys for sticks: 0 means neutral, ranges from -1 to 1.
547+ """
548+ A: bool
549+ B: bool
550+ X: bool
551+ Y: bool
552+ Z: bool
553+ Start: bool
554+ Up: bool
555+ Down: bool
556+ Left: bool
557+ Right: bool
558+ L: bool
559+ R: bool
560+ StickX: float
561+ StickY: float
562+ CStickX: float
563+ CStickY: float
564+ TriggerLeft: float
565+ TriggerRight: float
566+
567+
568+ class WiimoteInputs(TypedDict, total=False):
569+ """
570+ Dictionary describing the state of a Wii Remote controller.
571+ Boolean keys (buttons): True means pressed, False means released.
572+ """
573+ A: bool
574+ B: bool
575+ One: bool
576+ Two: bool
577+ Plus: bool
578+ Minus: bool
579+ Home: bool
580+ Up: bool
581+ Down: bool
582+ Left: bool
583+ Right: bool
584+
585+
586+ class WiiClassicInputs(TypedDict, total=False):
587+ """
588+ Dictionary describing the state of a Wii Classic controller.
589+ Boolean keys: True means pressed, False means released.
590+ Float keys for triggers: 0 means fully released, 1 means fully pressed.
591+ Float keys for sticks: 0 means neutral, ranges from -1 to 1.
592+ """
593+ A: bool
594+ B: bool
595+ X: bool
596+ Y: bool
597+ ZL: bool
598+ ZR: bool
599+ Plus: bool
600+ Minus: bool
601+ Home: bool
602+ Up: bool
603+ Down: bool
604+ Left: bool
605+ Right: bool
606+ L: bool
607+ R: bool
608+ TriggerLeft: float
609+ TriggerRight: float
610+ LeftStickX: float
611+ LeftStickY: float
612+ RightStickX: float
613+ RightStickY: float
614+
615+
616+ class WiiNunchukInputs(TypedDict, total=False):
617+ """
618+ Dictionary describing the state of a Wii Nunchuk controller.
619+ Boolean keys (buttons): True means pressed, False means released.
620+ Float keys for sticks: 0 means neutral, ranges from -1 to 1.
621+ """
622+ C: bool
623+ Z: bool
624+ StickX: float
625+ StickY: float
626+
627+
628+ class GBAInputs(TypedDict, total=False):
629+ """
630+ Dictionary describing the state of a GameBoy Advance controller.
631+ Boolean keys (buttons): True means pressed, False means released.
632+ """
633+ A: bool
634+ B: bool
635+ L: bool
636+ R: bool
637+ Start: bool
638+ Select: bool
639+ Up: bool
640+ Down: bool
641+ Left: bool
642+ Right: bool
643+
644+ )" ;
645+ Py::Object result = Py::LoadPyCodeIntoModule (module , pycode);
646+ if (result.IsNull ())
647+ {
648+ ERROR_LOG_FMT (SCRIPTING, " Failed to load embedded python code into controller module" );
649+ }
535650 state->gc_manip = PyScriptingBackend::GetCurrent ()->GetGCManip ();
536651 state->wii_manip = PyScriptingBackend::GetCurrent ()->GetWiiManip ();
537652 state->wii_classic_manip = PyScriptingBackend::GetCurrent ()->GetWiiClassicManip ();
@@ -551,14 +666,14 @@ PyMODINIT_FUNC PyInit_controller()
551666 static PyMethodDef method_defs[] = {
552667 {" get_gc_buttons" , get_gc_buttons, METH_VARARGS, " " },
553668 {" set_gc_buttons" , set_gc_buttons, METH_VARARGS, " " },
554- {" get_wii_buttons " , get_wii_buttons , METH_VARARGS, " " },
555- {" set_wii_buttons " , set_wii_buttons , METH_VARARGS, " " },
556- {" get_wii_pointer " , get_wii_pointer , METH_VARARGS, " " },
557- {" set_wii_pointer " , set_wii_pointer , METH_VARARGS, " " },
558- {" get_wii_acceleration " , get_wii_acceleration , METH_VARARGS, " " },
559- {" set_wii_acceleration " , set_wii_acceleration , METH_VARARGS, " " },
560- {" get_wii_angular_velocity " , get_wii_angular_velocity , METH_VARARGS, " " },
561- {" set_wii_angular_velocity " , set_wii_angular_velocity , METH_VARARGS, " " },
669+ {" get_wiimote_buttons " , get_wiimote_buttons , METH_VARARGS, " " },
670+ {" set_wiimote_buttons " , set_wiimote_buttons , METH_VARARGS, " " },
671+ {" get_wiimote_pointer " , get_wiimote_pointer , METH_VARARGS, " " },
672+ {" set_wiimote_pointer " , set_wiimote_pointer , METH_VARARGS, " " },
673+ {" get_wiimote_acceleration " , get_wiimote_acceleration , METH_VARARGS, " " },
674+ {" set_wiimote_acceleration " , set_wiimote_acceleration , METH_VARARGS, " " },
675+ {" get_wiimote_angular_velocity " , get_wiimote_angular_velocity , METH_VARARGS, " " },
676+ {" set_wiimote_angular_velocity " , set_wiimote_angular_velocity , METH_VARARGS, " " },
562677 {" get_wii_classic_buttons" , get_wii_classic_buttons, METH_VARARGS, " " },
563678 {" set_wii_classic_buttons" , set_wii_classic_buttons, METH_VARARGS, " " },
564679 {" get_wii_nunchuk_buttons" , get_wii_nunchuk_buttons, METH_VARARGS, " " },
0 commit comments