(undefined)
+
+ const robots = useMemo(() => {
+ const assemblies = [...World.SceneRenderer.sceneObjects.values()].filter(x => {
+ if (x instanceof MirabufSceneObject) {
+ return x.miraType === MiraType.ROBOT
+ }
+ return false
+ }) as MirabufSceneObject[]
+ return assemblies
+ }, [])
+
+ const drivers = useMemo(() => {
+ return selectedRobot?.mechanism
+ ? World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers
+ : undefined
+ }, [selectedRobot])
+
+ // Gets motors in preferences for ease of saving into origPrefs which can be used to revert on Cancel()
+ function saveOrigMotors(robot: MirabufSceneObject) {
+ drivers?.forEach(driver => {
+ if (driver.info && driver.info.name && !(driver instanceof WheelDriver)) {
+ const motors = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors
+ const removedMotor = motors.filter(x => {
+ if (x.name) return x.name != driver.info?.name
+ return false
+ })
+
+ if (removedMotor.length == drivers.length) {
+ removedMotor.push({
+ name: driver.info?.name ?? "",
+ maxVelocity: ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity,
+ maxForce: ((driver as SliderDriver) || (driver as HingeDriver)).maxForce,
+ })
+ PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor
+ }
+ }
+ })
+ PreferencesSystem.savePreferences()
+ setOrigPref({ ...PreferencesSystem.getRobotPreferences(robot.assemblyName) }) // clone
+ }
+
+ function Cancel() {
+ if (selectedRobot && origPref) {
+ drivers?.forEach(driver => {
+ if (driver instanceof WheelDriver) {
+ driver.maxVelocity = origPref.driveVelocity
+ driver.maxForce = origPref.driveAcceleration
+ } else {
+ if (driver.info && driver.info.name) {
+ const motor = origPref.motors.filter(x => {
+ if (x.name) return x.name == driver.info?.name
+ return false
+ })[0]
+ if (motor) {
+ // This line is a separate variable to get ES Lint and Prettier to agree on formatting the semicolon below
+ const forcePref = PreferencesSystem.getGlobalPreference("SubsystemGravity")
+ ? motor.maxForce
+ : driver instanceof SliderDriver
+ ? 500
+ : 100
+ ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity
+ ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = forcePref
+ }
+ }
+ }
+ })
+ PreferencesSystem.setRobotPreferences(selectedRobot.assemblyName, origPref)
+ }
+ PreferencesSystem.savePreferences()
+ }
+
+ return (
+ }
+ panelId={panelId}
+ openLocation={openLocation}
+ sidePadding={sidePadding}
+ onAccept={() => {
+ PreferencesSystem.savePreferences()
+ }}
+ onCancel={Cancel}
+ acceptEnabled={true}
+ >
+ {selectedRobot?.ejectorPreferences == undefined ? (
+ <>
+
+ {/** Scroll view for selecting a robot to configure */}
+
+ {robots.map(mirabufSceneObject => {
+ return (
+
+ )
+ })}
+
+ >
+ ) : (
+ <>
+ {drivers ? (
+
+ {/** Drivetrain row. Then other SliderDrivers and HingeDrivers */}
+ {
+ return selectedRobot
+ })()}
+ driver={(() => {
+ return drivers.filter(x => x instanceof WheelDriver)[0]
+ })()}
+ />
+ {drivers
+ .filter(x => x instanceof SliderDriver || x instanceof HingeDriver)
+ .map((driver: Driver, i: number) => (
+ {
+ return selectedRobot
+ })()}
+ driver={(() => {
+ return driver
+ })()}
+ />
+ ))}
+
+ ) : (
+
+ )}
+ >
+ )}
+
+ )
+}
+
+export default ConfigureSubsystemsPanel