Skip to content

Commit

Permalink
refactor: Replace ActionDefinitions with Record.
Browse files Browse the repository at this point in the history
  • Loading branch information
jswalden committed Nov 29, 2024
1 parent a1cecaa commit 755a5c6
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 37 deletions.
9 changes: 0 additions & 9 deletions src/actions/actionid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { CompanionActionDefinition } from '@companion-module/base'
import type { CustomCommandActionId } from './custom-command.js'
import type { ExposureActionId } from './exposure.js'
import type { FocusActionId } from './focus.js'
Expand All @@ -9,14 +8,6 @@ import type { PresetActionId } from './presets.js'
import type { WhiteBalanceActionId } from './white-balance.js'
import type { ZoomActionId } from './zoom.js'

/**
* The type of action definitions for all actions within the specified action
* set.
*/
export type ActionDefinitions<ActionSet extends string> = {
[actionId in ActionSet]: CompanionActionDefinition
}

export type PtzOpticsActionId =
| CustomCommandActionId
| ExposureActionId
Expand Down
5 changes: 3 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ActionDefinitions, PtzOpticsActionId } from './actionid.js'
import type { CompanionActionDefinition } from '@companion-module/base'
import type { PtzOpticsActionId } from './actionid.js'
import { customCommandActions } from './custom-command.js'
import { exposureActions } from './exposure.js'
import { focusActions } from './focus.js'
Expand All @@ -10,7 +11,7 @@ import { presetActions } from './presets.js'
import { whiteBalanceActions } from './white-balance.js'
import { zoomActions } from './zoom.js'

export function getActions(instance: PtzOpticsInstance): ActionDefinitions<PtzOpticsActionId> {
export function getActions(instance: PtzOpticsInstance): Record<PtzOpticsActionId, CompanionActionDefinition> {
return {
...customCommandActions(instance),
...exposureActions(instance),
Expand Down
6 changes: 4 additions & 2 deletions src/actions/custom-command.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type {
CompanionActionContext,
CompanionActionDefinition,
CompanionActionInfo,
CompanionInputFieldTextInput,
CompanionOptionValues,
} from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { PtzOpticsInstance } from '../instance.js'
import { type CommandParams, type PartialCommandParams, UserDefinedCommand } from '../visca/command.js'

Expand Down Expand Up @@ -196,7 +196,9 @@ export async function computeCustomCommandAndOptions(
return { command, options: commandOpts }
}

export function customCommandActions(instance: PtzOpticsInstance): ActionDefinitions<CustomCommandActionId> {
export function customCommandActions(
instance: PtzOpticsInstance,
): Record<CustomCommandActionId, CompanionActionDefinition> {
const PARAMETER_LIST_REGEX = '/^(?:[0-9]+(?:, ?[0-9]+)*(?:; ?[0-9]+(?:, ?[0-9]+)*)*|)$/'

return {
Expand Down
5 changes: 2 additions & 3 deletions src/actions/exposure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import { ExposureMode, IrisDown, IrisSet, IrisUp, ShutterDown, ShutterSet, ShutterUp } from '../camera/commands.js'
import { ExposureModeInquiry } from '../camera/inquiries.js'
import { ExposureModeOption, IrisSetOption, ShutterSetOption } from '../camera/options.js'
Expand All @@ -15,7 +14,7 @@ export enum ExposureActionId {
SetShutter = 'shutS',
}

export function exposureActions(instance: PtzOpticsInstance): ActionDefinitions<ExposureActionId> {
export function exposureActions(instance: PtzOpticsInstance): Record<ExposureActionId, CompanionActionDefinition> {
return {
[ExposureActionId.SelectExposureMode]: {
name: 'Exposure Mode',
Expand Down
5 changes: 2 additions & 3 deletions src/actions/focus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import {
FocusFarStandard,
FocusLock,
Expand All @@ -21,7 +20,7 @@ export enum FocusActionId {
UnlockFocus = 'focusU',
}

export function focusActions(instance: PtzOpticsInstance): ActionDefinitions<FocusActionId> {
export function focusActions(instance: PtzOpticsInstance): Record<FocusActionId, CompanionActionDefinition> {
return {
[FocusActionId.SelectFocusMode]: {
name: 'Focus Mode',
Expand Down
7 changes: 4 additions & 3 deletions src/actions/miscellaneous.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import { AutoTracking, CameraPower } from '../camera/commands.js'
import { AutoTrackingOption, CameraPowerOption } from '../camera/options.js'
import type { PtzOpticsInstance } from '../instance.js'
Expand All @@ -9,7 +8,9 @@ export enum MiscellaneousActionId {
CameraPowerState = 'power',
}

export function miscellaneousActions(instance: PtzOpticsInstance): ActionDefinitions<MiscellaneousActionId> {
export function miscellaneousActions(
instance: PtzOpticsInstance,
): Record<MiscellaneousActionId, CompanionActionDefinition> {
return {
[MiscellaneousActionId.CameraPowerState]: {
name: 'Power Camera',
Expand Down
5 changes: 2 additions & 3 deletions src/actions/osd.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import {
OnScreenDisplayBack,
OnScreenDisplayClose,
Expand All @@ -18,7 +17,7 @@ export enum OSDActionId {
OSDBack = 'onScreenDisplayBack',
}

export function osdActions(instance: PtzOpticsInstance): ActionDefinitions<OSDActionId> {
export function osdActions(instance: PtzOpticsInstance): Record<OSDActionId, CompanionActionDefinition> {
return {
[OSDActionId.OSD]: {
name: 'OSD Open/Close',
Expand Down
5 changes: 2 additions & 3 deletions src/actions/pan-tilt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import { PanTiltAction, PanTiltDirection, PanTiltHome, sendPanTiltCommand } from '../camera/commands.js'
import { PanTiltSetSpeedOption } from '../camera/options.js'
import type { PtzOpticsInstance } from '../instance.js'
Expand All @@ -20,7 +19,7 @@ export enum PanTiltActionId {
PanTiltSpeedDown = 'ptSpeedD',
}

export function panTiltActions(instance: PtzOpticsInstance): ActionDefinitions<PanTiltActionId> {
export function panTiltActions(instance: PtzOpticsInstance): Record<PanTiltActionId, CompanionActionDefinition> {
function createPanTiltCallback(direction: readonly [number, number]) {
return async (_event: CompanionActionEvent) => {
const { panSpeed, tiltSpeed } = instance.panTiltSpeed()
Expand Down
10 changes: 7 additions & 3 deletions src/actions/presets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { CompanionActionContext, CompanionActionEvent, CompanionOptionValues } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type {
CompanionActionContext,
CompanionActionDefinition,
CompanionActionEvent,
CompanionOptionValues,
} from '@companion-module/base'
import { PresetDriveSpeed, PresetRecall, PresetSave } from '../camera/commands.js'
import {
isValidPreset,
Expand Down Expand Up @@ -45,7 +49,7 @@ export async function parsePresetVariableOption(
}
}

export function presetActions(instance: PtzOpticsInstance): ActionDefinitions<PresetActionId> {
export function presetActions(instance: PtzOpticsInstance): Record<PresetActionId, CompanionActionDefinition> {
return {
[PresetActionId.SetPreset]: {
name: 'Save Preset',
Expand Down
7 changes: 4 additions & 3 deletions src/actions/white-balance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import { AutoWhiteBalanceSensitivity, WhiteBalance, WhiteBalanceOnePushTrigger } from '../camera/commands.js'
import { AutoWhiteBalanceSensitivityOption, WhiteBalanceOption } from '../camera/options.js'
import type { PtzOpticsInstance } from '../instance.js'
Expand All @@ -10,7 +9,9 @@ export enum WhiteBalanceActionId {
SelectAutoWhiteBalanceSensitivity = 'awbS',
}

export function whiteBalanceActions(instance: PtzOpticsInstance): ActionDefinitions<WhiteBalanceActionId> {
export function whiteBalanceActions(
instance: PtzOpticsInstance,
): Record<WhiteBalanceActionId, CompanionActionDefinition> {
return {
[WhiteBalanceActionId.SelectWhiteBalance]: {
name: 'White balance',
Expand Down
5 changes: 2 additions & 3 deletions src/actions/zoom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CompanionActionEvent } from '@companion-module/base'
import type { ActionDefinitions } from './actionid.js'
import type { CompanionActionDefinition, CompanionActionEvent } from '@companion-module/base'
import { ZoomIn, ZoomOut, ZoomStop } from '../camera/commands.js'
import type { PtzOpticsInstance } from '../instance.js'

Expand All @@ -9,7 +8,7 @@ export enum ZoomActionId {
StopZoom = 'zoomS',
}

export function zoomActions(instance: PtzOpticsInstance): ActionDefinitions<ZoomActionId> {
export function zoomActions(instance: PtzOpticsInstance): Record<ZoomActionId, CompanionActionDefinition> {
return {
[ZoomActionId.StartZoomIn]: {
name: 'Zoom In',
Expand Down

0 comments on commit 755a5c6

Please sign in to comment.