Skip to content

Commit 2f3148f

Browse files
committed
chore(EditInputInterface): fix react usage
1 parent cc51a88 commit 2f3148f

1 file changed

Lines changed: 87 additions & 93 deletions

File tree

fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/EditInputInterface.tsx

Lines changed: 87 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -38,98 +38,6 @@ const EditInputInterface: React.FC<EditInputProps> = ({ input, useGamepad, useTo
3838
input instanceof AxisInput ? input.joystickInverted : false
3939
)
4040

41-
/** Show the correct selection mode based on input type and how it's configured */
42-
const inputConfig = () => {
43-
if (useGamepad) {
44-
// Joystick Button
45-
if (input instanceof ButtonInput) {
46-
return (
47-
<JoystickButtonSelection
48-
input={input}
49-
selectedInput={selectedInput}
50-
setSelectedInput={setSelectedInput}
51-
/>
52-
)
53-
}
54-
55-
// Gamepad axis
56-
else if (input instanceof AxisInput) {
57-
return (
58-
<div key={input.inputName}>
59-
{input.useGamepadButtons ? (
60-
<GamepadButtonAxisSelection
61-
input={input}
62-
selectedInput={selectedInput}
63-
setSelectedInput={setSelectedInput}
64-
/>
65-
) : (
66-
// Gamepad joystick axis
67-
<JoystickAxisSelection
68-
input={input}
69-
selectedInput={selectedInput}
70-
setSelectedInput={setSelectedInput}
71-
setChosenGamepadAxis={setChosenGamepadAxis}
72-
/>
73-
)}
74-
75-
{/* // Button to switch between two buttons and a joystick axis */}
76-
<Checkbox
77-
label="Use Gamepad Buttons"
78-
checked={useGamepadButtons}
79-
onClick={checked => {
80-
input.useGamepadButtons = checked
81-
setUseGamepadButtons(checked)
82-
}}
83-
/>
84-
{/* // Button to invert the joystick axis */}
85-
<Checkbox
86-
label="Invert Joystick"
87-
checked={joystickInverted}
88-
onClick={checked => {
89-
input.joystickInverted = checked
90-
setJoystickInverted(checked)
91-
}}
92-
/>
93-
<Divider />
94-
</div>
95-
)
96-
}
97-
} else if (useTouchControls) {
98-
// here
99-
if (input instanceof AxisInput) {
100-
return (
101-
<div key={input.inputName}>
102-
<TouchControlsAxisSelection
103-
input={input}
104-
selectedInput={selectedInput}
105-
setSelectedInput={setSelectedInput}
106-
setChosenTouchControlsAxis={setChosenTouchControlsAxis}
107-
/>
108-
{/* // Button to invert the joystick axis */}
109-
<Checkbox
110-
label="Invert Joystick"
111-
checked={joystickInverted}
112-
onClick={checked => {
113-
input.joystickInverted = checked
114-
setJoystickInverted(checked)
115-
}}
116-
/>
117-
<Divider />
118-
</div>
119-
)
120-
}
121-
} else {
122-
// Keyboard button
123-
if (input instanceof ButtonInput) {
124-
return KeyboardButtonSelection({ input, setSelectedInput, selectedInput })
125-
}
126-
// Keyboard Axis
127-
else if (input instanceof AxisInput) {
128-
return KeyboardAxisSelection({ input, setSelectedInput, selectedInput })
129-
}
130-
}
131-
}
132-
13341
useEffect(() => {
13442
const checkGamepadState = () => {
13543
if (InputSystem.gamepad !== null) {
@@ -240,7 +148,93 @@ const EditInputInterface: React.FC<EditInputProps> = ({ input, useGamepad, useTo
240148
})
241149
}}
242150
>
243-
{inputConfig()}
151+
{useGamepad ? (
152+
// Joystick Button
153+
input instanceof ButtonInput ? (
154+
<JoystickButtonSelection
155+
input={input}
156+
selectedInput={selectedInput}
157+
setSelectedInput={setSelectedInput}
158+
/>
159+
) : (
160+
// Gamepad axis
161+
input instanceof AxisInput && (
162+
<div key={input.inputName}>
163+
{input.useGamepadButtons ? (
164+
<GamepadButtonAxisSelection
165+
input={input}
166+
selectedInput={selectedInput}
167+
setSelectedInput={setSelectedInput}
168+
/>
169+
) : (
170+
// Gamepad joystick axis
171+
<JoystickAxisSelection
172+
input={input}
173+
selectedInput={selectedInput}
174+
setSelectedInput={setSelectedInput}
175+
setChosenGamepadAxis={setChosenGamepadAxis}
176+
/>
177+
)}
178+
179+
{/* // Button to switch between two buttons and a joystick axis */}
180+
<Checkbox
181+
label="Use Gamepad Buttons"
182+
checked={useGamepadButtons}
183+
onClick={checked => {
184+
input.useGamepadButtons = checked
185+
setUseGamepadButtons(checked)
186+
}}
187+
/>
188+
{/* // Button to invert the joystick axis */}
189+
<Checkbox
190+
label="Invert Joystick"
191+
checked={joystickInverted}
192+
onClick={checked => {
193+
input.joystickInverted = checked
194+
setJoystickInverted(checked)
195+
}}
196+
/>
197+
<Divider />
198+
</div>
199+
)
200+
)
201+
) : useTouchControls ? (
202+
input instanceof AxisInput && (
203+
<div key={input.inputName}>
204+
<TouchControlsAxisSelection
205+
input={input}
206+
selectedInput={selectedInput}
207+
setSelectedInput={setSelectedInput}
208+
setChosenTouchControlsAxis={setChosenTouchControlsAxis}
209+
/>
210+
{/* // Button to invert the joystick axis */}
211+
<Checkbox
212+
label="Invert Joystick"
213+
checked={joystickInverted}
214+
onClick={checked => {
215+
input.joystickInverted = checked
216+
setJoystickInverted(checked)
217+
}}
218+
/>
219+
<Divider />
220+
</div>
221+
)
222+
) : input instanceof ButtonInput ? (
223+
<KeyboardButtonSelection
224+
input={input}
225+
setSelectedInput={setSelectedInput}
226+
selectedInput={selectedInput}
227+
/>
228+
) : (
229+
// Keyboard Axis
230+
input instanceof AxisInput && (
231+
<KeyboardAxisSelection
232+
input={input}
233+
setSelectedInput={setSelectedInput}
234+
selectedInput={selectedInput}
235+
/>
236+
)
237+
)}
244238
</Box>
245239
)
246240
}

0 commit comments

Comments
 (0)