xp-command 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -179,6 +179,19 @@ Many X-Plane datarefs are arrays (e.g., for multiple engines, generators, radios
179
179
  dataref: sim/cockpit/electrical/generator_on[1]
180
180
  ```
181
181
 
182
+ Here is an example of a custom set command which sets multiple datarefs at once (all datarefs receive the same value):
183
+
184
+ ```yaml
185
+ # toggle door and chocks
186
+ - pattern: "^d(0|1)$"
187
+ type: set
188
+ dataref:
189
+ - sim/cockpit2/switches/door_open[0]
190
+ - sim/flightmodel2/gear/is_chocked[0]
191
+ - sim/flightmodel2/gear/is_chocked[1]
192
+ - sim/flightmodel2/gear/is_chocked[2]
193
+ ```
194
+
182
195
  ## 🔄 Resetting Aircraft Profiles
183
196
 
184
197
  If you've edited an aircraft configuration and xp-command crashes or stops working, you can reset to default settings by deleting the config files.
package/bin/index.js CHANGED
@@ -12,7 +12,7 @@ import chalk from "chalk";
12
12
  import { program } from "commander";
13
13
  import ora from "ora";
14
14
 
15
- import { getDatarefValues, initAPI, setDatarefValue } from "../src/api.js";
15
+ import { getDatarefValues, initAPI, setDatarefValues } from "../src/api.js";
16
16
  import { copyToClipboard } from "../src/clipboard.js";
17
17
  import { getConfig } from "../src/config.js";
18
18
  import { clearLine, hideCursor, showCursor } from "../src/console.js";
@@ -103,12 +103,12 @@ const processCommand = async (command) => {
103
103
 
104
104
  if (isNaN(Number(value))) {
105
105
  const base64 = Buffer.from(value, 'utf-8').toString('base64');
106
- await setDatarefValue(c.dataref, base64);
106
+ await setDatarefValues(c.dataref, base64);
107
107
  } else {
108
108
  c.transform?.forEach((t) => {
109
109
  value = String(getTransformedValue(value, t));
110
110
  });
111
- await setDatarefValue(c.dataref, Number(value));
111
+ await setDatarefValues(c.dataref, Number(value));
112
112
  }
113
113
  spinner.succeed(chalk.green(`${PREFIX} ${command}`));
114
114
  hideCursor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-command",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Quick cockpit commands for X-Plane 12 - set your radios, altimeter, autopilot, and more from the terminal while flying.",
5
5
  "keywords": [
6
6
  "xplane",
package/src/api.js CHANGED
@@ -150,3 +150,18 @@ export const setDatarefValue = async (datarefNameWithOptionalIndex, value) => {
150
150
 
151
151
  return json;
152
152
  };
153
+
154
+ /**
155
+ * @param {string|Array<string>} datarefNamesWithOptionalIndex
156
+ * @param {number|string} value
157
+ * @return {Promise<number|string>}
158
+ */
159
+ export const setDatarefValues = async (datarefNamesWithOptionalIndex, value) => {
160
+ if (Array.isArray(datarefNamesWithOptionalIndex)) {
161
+ return Promise.all(datarefNamesWithOptionalIndex.map(dataref => setDatarefValue(dataref, value))).then(results => {
162
+ return results[0]
163
+ })
164
+ }
165
+
166
+ return setDatarefValue(datarefNamesWithOptionalIndex, value)
167
+ }
package/src/config.js CHANGED
@@ -20,7 +20,7 @@ const __dirname = dirname(__filename);
20
20
  * @typedef {Object} Command
21
21
  * @property {RegExp} pattern - Regular expression pattern to match commands
22
22
  * @property {'get' | 'set'} type - Operation type
23
- * @property {string} dataref - X-Plane dataref path
23
+ * @property {string|Array<string>} dataref - X-Plane dataref path(s)
24
24
  * @property {Transform[]} transform - Array of transformation operations to apply
25
25
  */
26
26