Skip to content

Commit da113f9

Browse files
committed
Better Dropdown Selection
1 parent ee9e30c commit da113f9

File tree

3 files changed

+27
-86
lines changed

3 files changed

+27
-86
lines changed

fission/src/systems/MatchMode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import MatchEnd from "@/assets/sound-files/MatchEnd.wav"
77
import MatchResume from "@/assets/sound-files/MatchResume.wav"
88

99
export enum MatchModeType {
10-
SANDBOX = 0,
11-
AUTONOMOUS = 1,
12-
TELEOP = 2,
13-
ENDGAME = 3,
14-
MATCH_ENDED = 4,
10+
SANDBOX = "Sandbox",
11+
AUTONOMOUS = "Autonomous",
12+
TELEOP = "Teleop",
13+
ENDGAME = "Endgame",
14+
MATCH_ENDED = "Match Ended",
1515
}
1616

1717
// Default match mode timing values

fission/src/test/mirabuf/ProtectedZoneSceneObject.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ vi.mock("@/systems/simulation/SimulationSystem", () => ({
4747

4848
vi.mock("@/systems/MatchMode", () => ({
4949
MatchModeType: {
50-
SANDBOX: 0,
51-
AUTONOMOUS: 1,
52-
TELEOP: 2,
53-
ENDGAME: 3,
54-
MATCH_ENDED: 4,
50+
SANDBOX: "Sandbox",
51+
AUTONOMOUS: "Autonomous",
52+
TELEOP: "Teleop",
53+
ENDGAME: "Endgame",
54+
MATCH_ENDED: "Match Ended",
5555
},
5656
default: {
5757
getInstance: vi.fn(() => ({
58-
getMatchModeType: vi.fn(() => MatchModeType.TELEOP),
58+
getMatchModeType: vi.fn(() => "Teleop"),
5959
})),
6060
},
6161
}))
@@ -122,8 +122,7 @@ describe("ProtectedZoneSceneObject", () => {
122122

123123
instance["zoneCollision"](blueRobotBodyId)
124124

125-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledTimes(1)
126-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledWith(blueRobot, 5, expect.any(String))
125+
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledExactlyOnceWith(blueRobot, 5, expect.any(String))
127126
})
128127

129128
test("ZoneCollision does not penalize same alliance robot", () => {

fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ProtectedZoneConfigInterface.tsx

Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ import ProtectedZoneSceneObject, { ContactType } from "@/mirabuf/ProtectedZoneSc
2424
import Dropdown from "@/ui/components/Dropdown"
2525
import { MatchModeType } from "@/systems/MatchMode"
2626

27+
const MATCH_MODE_OPTIONS: MatchModeType[] = [
28+
MatchModeType.SANDBOX,
29+
MatchModeType.AUTONOMOUS,
30+
MatchModeType.TELEOP,
31+
MatchModeType.ENDGAME,
32+
]
33+
34+
const CONTACT_TYPE_OPTIONS = Object.values(ContactType)
35+
2736
/**
2837
* Saves ejector configuration to selected field.
2938
*
@@ -271,45 +280,11 @@ const ZoneConfigInterface: React.FC<ZoneConfigProps> = ({ selectedField, selecte
271280
{/** Determines during what game state the protected zone is active */}
272281
<Dropdown
273282
label="Active During"
274-
options={["Sandbox", "Autonomous", "Teleop", "Endgame"]}
283+
options={MATCH_MODE_OPTIONS}
275284
onSelect={(selectedOptions: string[]) => {
276-
const matchModes: MatchModeType[] = []
277-
selectedOptions.forEach(option => {
278-
switch (option) {
279-
case "Sandbox":
280-
matchModes.push(MatchModeType.SANDBOX)
281-
break
282-
case "Autonomous":
283-
matchModes.push(MatchModeType.AUTONOMOUS)
284-
break
285-
case "Teleop":
286-
matchModes.push(MatchModeType.TELEOP)
287-
break
288-
case "Endgame":
289-
matchModes.push(MatchModeType.ENDGAME)
290-
break
291-
default:
292-
break
293-
}
294-
})
295-
setActiveDuring(matchModes)
285+
setActiveDuring(selectedOptions as MatchModeType[])
296286
}}
297-
defaultValue={activeDuring
298-
.map(mode => {
299-
switch (mode) {
300-
case MatchModeType.SANDBOX:
301-
return "Sandbox"
302-
case MatchModeType.AUTONOMOUS:
303-
return "Autonomous"
304-
case MatchModeType.TELEOP:
305-
return "Teleop"
306-
case MatchModeType.ENDGAME:
307-
return "Endgame"
308-
default:
309-
return ""
310-
}
311-
})
312-
.filter(val => val !== "")}
287+
defaultValue={activeDuring}
313288
maxWidth="15rem"
314289
multiSelect={true}
315290
textAlign="left"
@@ -318,44 +293,11 @@ const ZoneConfigInterface: React.FC<ZoneConfigProps> = ({ selectedField, selecte
318293
{/** Determines what type of contact is required for the penalty to apply */}
319294
<Dropdown
320295
label="Contact Type"
321-
options={[
322-
"Robot Enters",
323-
"Collision with Both Robots Inside",
324-
"Collision with Opponent Robot Inside",
325-
"Collision with Ally Robot Inside",
326-
]}
296+
options={CONTACT_TYPE_OPTIONS}
327297
onSelect={(selectedOption: string) => {
328-
switch (selectedOption) {
329-
case "Robot Enters":
330-
setContactType(ContactType.ROBOT_ENTERS)
331-
break
332-
case "Collision with Both Robots Inside":
333-
setContactType(ContactType.BOTH_ROBOTS_INSIDE)
334-
break
335-
case "Collision with Opponent Robot Inside":
336-
setContactType(ContactType.OPPONENT_ROBOT_INSIDE)
337-
break
338-
case "Collision with Ally Robot Inside":
339-
setContactType(ContactType.ALLY_ROBOT_INSIDE)
340-
break
341-
default:
342-
break
343-
}
298+
setContactType(selectedOption as ContactType)
344299
}}
345-
defaultValue={(() => {
346-
switch (contactType) {
347-
case ContactType.ROBOT_ENTERS:
348-
return "Robot Enters"
349-
case ContactType.BOTH_ROBOTS_INSIDE:
350-
return "Collision with Both Robots Inside"
351-
case ContactType.OPPONENT_ROBOT_INSIDE:
352-
return "Collision with Opponent Robot Inside"
353-
case ContactType.ALLY_ROBOT_INSIDE:
354-
return "Collision with Ally Robot Inside"
355-
default:
356-
return "Robot Enters"
357-
}
358-
})()}
300+
defaultValue={contactType}
359301
textAlign="left"
360302
/>
361303

0 commit comments

Comments
 (0)