-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This library is responsible for performing functionalities independent of user action.
- Loading branch information
1 parent
c962e3b
commit 83dedc3
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useControllerStore } from '@/stores/controller' | ||
import { useMainVehicleStore } from '@/stores/mainVehicle' | ||
|
||
/** | ||
* A cockpit function to be formed independent of user action | ||
*/ | ||
export enum AutomagicId { | ||
ImportJoystickFunctionsOnBoot = 'ImportJoystickFunctionsOnBoot', | ||
} | ||
export const allAutomagicIds = Object.keys(AutomagicId).filter((v) => isNaN(Number(v))) as unknown as AutomagicId[] | ||
|
||
export const availableAutomagics = [ | ||
{ | ||
id: AutomagicId.ImportJoystickFunctionsOnBoot, | ||
description: 'Import joystick function mappings from the vehicle on Cockpit boot.', | ||
function: async () => { | ||
const { globalAddress } = useMainVehicleStore() | ||
const controllerStore = useControllerStore() | ||
await controllerStore.importFunctionsMappingFromVehicle(globalAddress) | ||
}, | ||
}, | ||
] | ||
|
||
export const runAutomagics = async (selectedAutomagicsIds: AutomagicId[]): Promise<void> => { | ||
console.info(`Running the following automagics: ${selectedAutomagicsIds}.`) | ||
availableAutomagics | ||
.filter((automagic) => selectedAutomagicsIds.includes(automagic.id)) | ||
.forEach((automagic) => { | ||
try { | ||
console.info(`Running automagic '${automagic.id}'...`) | ||
automagic.function() | ||
} catch (error) { | ||
console.error(`Could not run automagic '${automagic.id}'. ${error}`) | ||
} | ||
}) | ||
} |