xp-command 1.2.0 → 1.3.1
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 +13 -0
- package/bin/index.js +9 -6
- package/package.json +1 -1
- package/src/api.js +15 -0
- package/src/config.js +1 -1
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,
|
|
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";
|
|
@@ -20,12 +20,15 @@ import { isAPIError, isEconnRefused } from "../src/error.js";
|
|
|
20
20
|
import history from "../src/history.js";
|
|
21
21
|
import { sleep } from "../src/sleep.js";
|
|
22
22
|
|
|
23
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
24
|
+
|
|
23
25
|
const PREFIX = "🛩 ";
|
|
24
26
|
|
|
25
27
|
program
|
|
26
|
-
.version(
|
|
27
|
-
.description(
|
|
28
|
-
.option("-p, --port <number>", "server port number")
|
|
28
|
+
.version(packageJson.version)
|
|
29
|
+
.description(`${PREFIX} ${packageJson.name}\n${packageJson.description}`)
|
|
30
|
+
.option("-p, --port <number>", "server port number")
|
|
31
|
+
.helpOption('-h, --help', 'display this help text');
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* @param {string} command
|
|
@@ -103,12 +106,12 @@ const processCommand = async (command) => {
|
|
|
103
106
|
|
|
104
107
|
if (isNaN(Number(value))) {
|
|
105
108
|
const base64 = Buffer.from(value, 'utf-8').toString('base64');
|
|
106
|
-
await
|
|
109
|
+
await setDatarefValues(c.dataref, base64);
|
|
107
110
|
} else {
|
|
108
111
|
c.transform?.forEach((t) => {
|
|
109
112
|
value = String(getTransformedValue(value, t));
|
|
110
113
|
});
|
|
111
|
-
await
|
|
114
|
+
await setDatarefValues(c.dataref, Number(value));
|
|
112
115
|
}
|
|
113
116
|
spinner.succeed(chalk.green(`${PREFIX} ${command}`));
|
|
114
117
|
hideCursor();
|
package/package.json
CHANGED
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
|
|