Skip to content

Commit

Permalink
joystick: Remove options to import/export mappings from/to vehicle
Browse files Browse the repository at this point in the history
This is now done automatically by the settings syncer.
  • Loading branch information
rafaellehmkuhl committed Apr 30, 2024
1 parent 2c7f1cb commit 9d76664
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 71 deletions.
33 changes: 0 additions & 33 deletions src/stores/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { type JoystickEvent, EventType, joystickManager, JoystickModel } from '@
import { allAvailableAxes, allAvailableButtons } from '@/libs/joystick/protocols'
import { modifierKeyActions, otherAvailableActions } from '@/libs/joystick/protocols/other'
import {
type GamepadToCockpitStdMapping,
type JoystickProtocolActionsMapping,
type JoystickState,
type ProtocolAction,
Expand Down Expand Up @@ -266,36 +265,6 @@ export const useControllerStore = defineStore('controller', () => {
reader.readAsText(e.target.files[0])
}

const exportJoysticksMappingsToVehicle = async (
vehicleAddress: string,
joystickMappings: { [key in JoystickModel]: GamepadToCockpitStdMapping }
): Promise<void> => {
await setKeyDataOnCockpitVehicleStorage(vehicleAddress, cockpitStdMappingsKey, joystickMappings)
Swal.fire({ icon: 'success', text: 'Joystick mapping exported to vehicle.', timer: 3000 })
}

const importJoysticksMappingsFromVehicle = async (vehicleAddress: string): Promise<void> => {
const newMapping = await getKeyDataFromCockpitVehicleStorage(vehicleAddress, cockpitStdMappingsKey)
if (!newMapping) {
Swal.fire({ icon: 'error', text: 'No joystick mappings to import from vehicle.', timer: 3000 })
return
}
try {
Object.values(newMapping).forEach((mapping) => {
if (!mapping['name'] || !mapping['axes'] || !mapping['buttons']) {
throw Error('Invalid joystick mapping inside vehicle.')
}
})
} catch (error) {
Swal.fire({ icon: 'error', text: `Could not import joystick mapping from vehicle. ${error}`, timer: 3000 })
return
}

// @ts-ignore: We check for the necessary fields in the if before
cockpitStdMappings.value = newMapping
Swal.fire({ icon: 'success', text: 'Joystick mapping imported from vehicle.', timer: 3000 })
}

const exportFunctionsMapping = (protocolActionsMapping: JoystickProtocolActionsMapping): void => {
const blob = new Blob([JSON.stringify(protocolActionsMapping)], { type: 'text/plain;charset=utf-8' })
saveAs(blob, `cockpit-std-profile-joystick-${protocolActionsMapping.name}.json`)
Expand Down Expand Up @@ -379,8 +348,6 @@ export const useControllerStore = defineStore('controller', () => {
loadProtocolMapping,
exportJoystickMapping,
importJoystickMapping,
exportJoysticksMappingsToVehicle,
importJoysticksMappingsFromVehicle,
exportFunctionsMapping,
importFunctionsMapping,
exportFunctionsMappingToVehicle,
Expand Down
38 changes: 0 additions & 38 deletions src/views/ConfigurationJoystickView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,6 @@
/>
Import from computer
</label>
<button
class="p-2 m-1 font-medium border rounded-md text-uppercase"
@click="
controllerStore.exportJoysticksMappingsToVehicle(globalAddress, controllerStore.cockpitStdMappings)
"
>
Export to vehicle
</button>
<button
class="p-2 m-1 font-medium border rounded-md text-uppercase"
@click="controllerStore.importJoysticksMappingsFromVehicle(globalAddress)"
>
Import from vehicle
</button>
</div>
</div>
<div class="flex flex-col items-center max-w-[30%] mb-4">
Expand All @@ -179,20 +165,6 @@
/>
Import from computer
</label>
<button
class="p-2 m-1 font-medium border rounded-md text-uppercase"
@click="
controllerStore.exportFunctionsMappingToVehicle(globalAddress, controllerStore.protocolMappings)
"
>
Export to vehicle
</button>
<button
class="p-2 m-1 font-medium border rounded-md text-uppercase"
@click="importFunctionsMappingFromVehicle"
>
Import from vehicle
</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -338,7 +310,6 @@

<script setup lang="ts">
import semver from 'semver'
import Swal from 'sweetalert2'
import { type Ref, computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import Button from '@/components/Button.vue'
Expand Down Expand Up @@ -435,15 +406,6 @@ const setCurrentInputs = (joystick: Joystick, inputs: JoystickInput[]): void =>
inputClickedDialog.value = true
}
const importFunctionsMappingFromVehicle = async (): Promise<void> => {
try {
await controllerStore.importFunctionsMappingFromVehicle(globalAddress)
Swal.fire({ icon: 'success', text: 'Joystick functions mappings imported from the vehicle.' })
} catch (error) {
Swal.fire({ icon: 'error', text: `${error}` })
}
}
/**
* Remaps the input of a given joystick. The function waits for a button press on the joystick and then
* updates the mapping to associate the joystick input with the pressed button. If no button is pressed
Expand Down

0 comments on commit 9d76664

Please sign in to comment.