Skip to content

Commit

Permalink
Merge pull request #36 from phillipivan/main
Browse files Browse the repository at this point in the history
Add action recorder support
  • Loading branch information
phillipivan authored Sep 20, 2024
2 parents b041c8a + 68408cf commit fc0ccda
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generic-emberplus",
"version": "2.3.3",
"version": "2.4.0",
"main": "dist/index.js",
"scripts": {
"prepare": "husky",
Expand Down
39 changes: 38 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type EmberPlusConfig, GetConfigFields } from './config'
import { GetPresetsList } from './presets'
import { FeedbackId, GetFeedbacksList } from './feedback'
import { EmberPlusState } from './state'
import { EmberClient } from 'emberplus-connection' // note - emberplus-conn is in parent repo, not sure if it needs to be defined as dependency
import { EmberClient, Model as EmberModel } from 'emberplus-connection' // note - emberplus-conn is in parent repo, not sure if it needs to be defined as dependency
import { ElementType } from 'emberplus-connection/dist/model'
import type { TreeElement, EmberElement } from 'emberplus-connection/dist/model'
import { GetVariablesList } from './variables'
Expand All @@ -22,6 +22,7 @@ class EmberPlusInstance extends InstanceBase<EmberPlusConfig> {
private state!: EmberPlusState
private emberQueue!: PQueue
private reconnectTimer!: ReturnType<typeof setTimeout> | undefined
private isRecordingActions!: boolean

// Override base types to make types stricter
public checkFeedbacks(...feedbackTypes: string[]): void {
Expand Down Expand Up @@ -196,13 +197,49 @@ class EmberPlusInstance extends InstanceBase<EmberPlusConfig> {
})
}
}
// Track whether actions are being recorded
public handleStartStopRecordActions(isRecording: boolean) {
this.isRecordingActions = isRecording
}
private async handleChangedValue(path: string, node: TreeElement<EmberElement>) {
if (node.contents.type == ElementType.Parameter) {
this.log('debug', 'Got parameter value for ' + path + ': ' + (node.contents.value?.toString() ?? ''))
this.state.parameters.set(path, node.contents.value?.toString() ?? '')
this.checkFeedbacks(FeedbackId.Parameter, FeedbackId.String)

this.setVariableValues(Object.fromEntries(this.state.parameters.entries()))
if (this.isRecordingActions) {
let actionType: string
let actionValue: any
if (node.contents.parameterType === EmberModel.ParameterType.Integer) {
actionType = 'setValueInt'
actionValue = Number(node.contents.value)
if (isNaN(actionValue)) return
} else if (node.contents.parameterType === EmberModel.ParameterType.Boolean) {
actionType = 'setValueBoolean'
actionValue = !!node.contents.value
} else if (node.contents.parameterType === EmberModel.ParameterType.Enum) {
actionType = 'setValueEnum'
actionValue = Number(node.contents.value)
if (isNaN(actionValue)) return
} else if (node.contents.parameterType === EmberModel.ParameterType.Real) {
actionType = 'setValueReal'
actionValue = Number(node.contents.value)
if (isNaN(actionValue)) return
} else if (node.contents.parameterType === EmberModel.ParameterType.String) {
actionType = 'setValueString'
actionValue = node.contents.value?.toString()
} else {
return
}
this.recordAction(
{
actionId: actionType,
options: { path: path, value: actionValue },
},
`${path}`,
)
}
}
}
}
Expand Down

0 comments on commit fc0ccda

Please sign in to comment.