Allow using JSON arrays for math commands - applies to all that receive a list. /add, /sub, /min, /max etc - Parsing is the same as the other commands where we already allow "LIST" as an argument.

2dc7b5ded1e48224447ac4cab179dc3a01a59338

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +47 -13Showing whitespace changes
public/scripts/variables.js+47 -13
@@ -679,10 +679,17 @@ function parseNumericSeries(value, scope = null) {
679679 return [value];
680680 }
681681
682- const values = Array.isArray(value) ? value : value.split(' ');
682+ /** @type {(string|number)[]} */
683- const array = values.map(i => i.trim())
683+ let values = Array.isArray(value) ? value : value.split(' ');
684+
685+ // If a JSON array was provided as the only value, convert it to an array
686+ if (values.length === 1 && typeof values[0] === 'string' && values[0].startsWith('[')) {
687+ values = convertValueType(values[0], 'array');
688+ }
689+
690+ const array = values.map(i => typeof i === 'string' ? i.trim() : i)
684691 .filter(i => i !== '')
685692 .map(i => isNaN(Number(i)) ? Number(resolveVariable(String(i), scope)) : Number(i))
686693 .filter(i => !isNaN(i));
687694
688695 return array;
@@ -1599,7 +1606,7 @@ export function registerVariableCommands() {
15991606 unnamedArgumentList: [
16001607 SlashCommandArgument.fromProps({
16011608 description: 'values to sum',
16021609 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
16031610 isRequired: true,
16041611 acceptsMultiple: true,
16051612 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1610,7 +1617,9 @@ export function registerVariableCommands() {
16101617 helpString: `
16111618 <div>
16121619 Performs an addition of the set of values and passes the result down the pipe.
1613- Can use variable names.
1620+ </div>
1621+ <div>
1622+ Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
16141623 </div>
16151624 <div>
16161625 <strong>Example:</strong>
@@ -1618,6 +1627,9 @@ export function registerVariableCommands() {
16181627 <li>
16191628 <pre><code class="language-stscript">/add 10 i 30 j</code></pre>
16201629 </li>
1630+ <li>
1631+ <pre><code class="language-stscript">/add ["count", 15, 2, "i"]</code></pre>
1632+ </li>
16211633 </ul>
16221634 </div>
16231635 `,
@@ -1629,7 +1641,7 @@ export function registerVariableCommands() {
16291641 unnamedArgumentList: [
16301642 SlashCommandArgument.fromProps({
16311643 description: 'values to multiply',
16321644 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
16331645 isRequired: true,
16341646 acceptsMultiple: true,
16351647 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1639,7 +1651,10 @@ export function registerVariableCommands() {
16391651 splitUnnamedArgument: true,
16401652 helpString: `
16411653 <div>
16421654 Performs a multiplication of the set of values and passes the result down the pipe. Can use variable names.
1655+ </div>
1656+ <div>
1657+ Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
16431658 </div>
16441659 <div>
16451660 <strong>Examples:</strong>
@@ -1647,6 +1662,9 @@ export function registerVariableCommands() {
16471662 <li>
16481663 <pre><code class="language-stscript">/mul 10 i 30 j</code></pre>
16491664 </li>
1665+ <li>
1666+ <pre><code class="language-stscript">/mul ["count", 15, 2, "i"]</code></pre>
1667+ </li>
16501668 </ul>
16511669 </div>
16521670 `,
@@ -1658,7 +1676,7 @@ export function registerVariableCommands() {
16581676 unnamedArgumentList: [
16591677 SlashCommandArgument.fromProps({
16601678 description: 'values to find the max',
16611679 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
16621680 isRequired: true,
16631681 acceptsMultiple: true,
16641682 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1668,7 +1686,10 @@ export function registerVariableCommands() {
16681686 splitUnnamedArgument: true,
16691687 helpString: `
16701688 <div>
16711689 Returns the maximum value of the set of values and passes the result down the pipe. Can use variable names.
1690+ </div>
1691+ <div>
1692+ Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
16721693 </div>
16731694 <div>
16741695 <strong>Examples:</strong>
@@ -1676,6 +1697,9 @@ export function registerVariableCommands() {
16761697 <li>
16771698 <pre><code class="language-stscript">/max 10 i 30 j</code></pre>
16781699 </li>
1700+ <li>
1701+ <pre><code class="language-stscript">/max ["count", 15, 2, "i"]</code></pre>
1702+ </li>
16791703 </ul>
16801704 </div>
16811705 `,
@@ -1687,7 +1711,7 @@ export function registerVariableCommands() {
16871711 unnamedArgumentList: [
16881712 SlashCommandArgument.fromProps({
16891713 description: 'values to find the min',
16901714 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
16911715 isRequired: true,
16921716 acceptsMultiple: true,
16931717 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1698,7 +1722,9 @@ export function registerVariableCommands() {
16981722 helpString: `
16991723 <div>
17001724 Returns the minimum value of the set of values and passes the result down the pipe.
1701- Can use variable names.
1725+ </div>
1726+ <div>
1727+ Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
17021728 </div>
17031729 <div>
17041730 <strong>Example:</strong>
@@ -1706,6 +1732,9 @@ export function registerVariableCommands() {
17061732 <li>
17071733 <pre><code class="language-stscript">/min 10 i 30 j</code></pre>
17081734 </li>
1735+ <li>
1736+ <pre><code class="language-stscript">/min ["count", 15, 2, "i"]</code></pre>
1737+ </li>
17091738 </ul>
17101739 </div>
17111740 `,
@@ -1717,7 +1746,7 @@ export function registerVariableCommands() {
17171746 unnamedArgumentList: [
17181747 SlashCommandArgument.fromProps({
17191748 description: 'values to subtract, starting form the first provided value',
17201749 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
17211750 isRequired: true,
17221751 acceptsMultiple: true,
17231752 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1728,7 +1757,9 @@ export function registerVariableCommands() {
17281757 helpString: `
17291758 <div>
17301759 Performs a subtraction of the set of values and passes the result down the pipe.
1731- Can use variable names.
1760+ </div>
1761+ <div>
1762+ Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
17321763 </div>
17331764 <div>
17341765 <strong>Example:</strong>
@@ -1736,6 +1767,9 @@ export function registerVariableCommands() {
17361767 <li>
17371768 <pre><code class="language-stscript">/sub i 5</code></pre>
17381769 </li>
1770+ <li>
1771+ <pre><code class="language-stscript">/sub ["count", 4, "i"]</code></pre>
1772+ </li>
17391773 </ul>
17401774 </div>
17411775 `,