1- /* eslint-disable @next/next/no-img-element */
21"use client"
32
3+ import React from "react" ;
44import { useRef , useState , CSSProperties } from "react" ;
55import { useRouter , ReadonlyURLSearchParams } from "next/navigation" ;
66import { XmbMenu } from "@models/menu" ;
@@ -14,6 +14,7 @@ import useQuery from "@/hooks/useQuery";
1414import build from "@services/menuBuilder" ;
1515import "./xmb.css" ;
1616import { useWindowSize } from "@uidotdev/usehooks" ;
17+ import { useGamepads } from 'awesome-react-gamepads' ;
1718
1819const config : XmbMenu = build ( ) ;
1920
@@ -63,8 +64,8 @@ export default function Menu() {
6364 function onEnter ( ) {
6465 play ( ) ;
6566
66- let selectedCategory = config . getCurrentCategory ( ) ;
67- let selectedItem = selectedCategory . getCurrentItem ( ) ;
67+ const selectedCategory = config . getCurrentCategory ( ) ;
68+ const selectedItem = selectedCategory . getCurrentItem ( ) ;
6869
6970 if ( selectedItem . modal ) {
7071 router . push ( `/?modal=${ selectedItem . modal } ` ) ;
@@ -84,29 +85,61 @@ export default function Menu() {
8485
8586 function onUp ( ) {
8687 play ( ) ;
87- let position = config . moveUp ( ) ;
88+ const position = config . moveUp ( ) ;
8889 if ( position === null ) return ;
8990 setY ( position . y ) ;
9091 }
9192
93+ function onTop ( ) {
94+ play ( ) ;
95+ const position = config . moveTop ( ) ;
96+ if ( position === null ) return ;
97+ setX ( position . x ) ;
98+ setY ( position . y ) ;
99+ }
100+
92101 function onDown ( ) {
93102 play ( ) ;
94- let position = config . moveDown ( ) ;
103+ const position = config . moveDown ( ) ;
95104 if ( position === null ) return ;
96105 setY ( position . y ) ;
97106 }
98107
108+ function onBottom ( ) {
109+ play ( ) ;
110+ const position = config . moveBottom ( ) ;
111+ if ( position === null ) return ;
112+ setX ( position . x ) ;
113+ setY ( position . y ) ;
114+ }
115+
99116 function onLeft ( ) {
100117 play ( ) ;
101- let position = config . moveLeft ( ) ;
118+ const position = config . moveLeft ( ) ;
119+ if ( position === null ) return ;
120+ setX ( position . x ) ;
121+ setY ( position . y ) ;
122+ }
123+
124+ function onFirst ( ) {
125+ play ( ) ;
126+ const position = config . moveFirst ( ) ;
102127 if ( position === null ) return ;
103128 setX ( position . x ) ;
104129 setY ( position . y ) ;
105130 }
106131
107132 function onRight ( ) {
108133 play ( ) ;
109- let position = config . moveRight ( ) ;
134+ const position = config . moveRight ( ) ;
135+ if ( position === null ) return ;
136+ setX ( position . x ) ;
137+ setY ( position . y ) ;
138+ }
139+
140+ function onLast ( ) {
141+ play ( ) ;
142+ const position = config . moveLast ( ) ;
110143 if ( position === null ) return ;
111144 setX ( position . x ) ;
112145 setY ( position . y ) ;
@@ -117,7 +150,7 @@ export default function Menu() {
117150 }
118151
119152 useQuery ( { onPathChanged : onPathChanged } ) ;
120-
153+
121154 const actions = new Map < string , KeyPressAction > ( ) ;
122155
123156 actions . set ( 'w' , { repeat : true , onKeyPress : onUp } ) ;
@@ -133,9 +166,44 @@ export default function Menu() {
133166 actions . set ( 'escape' , { repeat : false , onKeyPress : onEsc } ) ;
134167 actions . set ( 'h' , { repeat : false , onKeyPress : onHelp } ) ;
135168 actions . set ( 'f1' , { repeat : false , onKeyPress : onHelp } ) ;
169+ actions . set ( 'q' , { repeat : false , onKeyPress : onFirst } ) ;
170+ actions . set ( 'e' , { repeat : false , onKeyPress : onLast } ) ;
171+ actions . set ( 'z' , { repeat : false , onKeyPress : onTop } ) ;
172+ actions . set ( 'x' , { repeat : false , onKeyPress : onBottom } ) ;
136173
137174 useKeyboard ( { actions : actions , enabledOnModal : false } ) ;
138175
176+ useGamepads ( {
177+ onConnect : ( gamepad ) => {
178+ console . log ( `gamepad connected: ${ gamepad . id } (${ gamepad . index } )` ) ;
179+ console . log ( 'buttons:' ) ;
180+ console . log ( JSON . stringify ( gamepad . buttons , null , 2 ) ) ;
181+ } ,
182+ onDisconnect : ( gamepad ) => {
183+ console . log ( `gamepad disconnected: ${ gamepad . id } (${ gamepad . index } )` ) ;
184+ } ,
185+ onA : onEnter ,
186+ onB : onEsc ,
187+ onDPadUp : onUp ,
188+ onDPadDown : onDown ,
189+ onDPadLeft : onLeft ,
190+ onDPadRight : onRight ,
191+ onLeftStickUp : onUp ,
192+ onLeftStickDown : onDown ,
193+ onLeftStickLeft : onLeft ,
194+ onLeftStickRight : onRight ,
195+ onRightStickUp : onUp ,
196+ onRightStickDown : onDown ,
197+ onRightStickLeft : onLeft ,
198+ onRightStickRight : onRight ,
199+ onStart : onEnter ,
200+ onSelect : onHelp ,
201+ onLT : onTop ,
202+ onRT : onBottom ,
203+ onLB : onFirst ,
204+ onRB : onLast ,
205+ } ) ;
206+
139207 const wheelInput : WheelInput = {
140208 onWheelUp : onUp ,
141209 onWheelDown : onDown ,
0 commit comments