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 -13Ignore whitespace
public/scripts/variables.js+47 -13
@@ -679,10 +679,17 @@ function parseNumericSeries(value, scope = null) {
679 return [value];679 return [value];
680 }680 }
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)
684 .filter(i => i !== '')691 .filter(i => i !== '')
685 .map(i => isNaN(Number(i)) ? Number(resolveVariable(i, scope)) : Number(i))692 .map(i => isNaN(Number(i)) ? Number(resolveVariable(String(i), scope)) : Number(i))
686 .filter(i => !isNaN(i));693 .filter(i => !isNaN(i));
687694
688 return array;695 return array;
@@ -1599,7 +1606,7 @@ export function registerVariableCommands() {
1599 unnamedArgumentList: [1606 unnamedArgumentList: [
1600 SlashCommandArgument.fromProps({1607 SlashCommandArgument.fromProps({
1601 description: 'values to sum',1608 description: 'values to sum',
1602 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME],1609 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
1603 isRequired: true,1610 isRequired: true,
1604 acceptsMultiple: true,1611 acceptsMultiple: true,
1605 enumProvider: commonEnumProviders.numbersAndVariables,1612 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1610,7 +1617,9 @@ export function registerVariableCommands() {
1610 helpString: `1617 helpString: `
1611 <div>1618 <div>
1612 Performs an addition of the set of values and passes the result down the pipe.1619 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).
1614 </div>1623 </div>
1615 <div>1624 <div>
1616 <strong>Example:</strong>1625 <strong>Example:</strong>
@@ -1618,6 +1627,9 @@ export function registerVariableCommands() {
1618 <li>1627 <li>
1619 <pre><code class="language-stscript">/add 10 i 30 j</code></pre>1628 <pre><code class="language-stscript">/add 10 i 30 j</code></pre>
1620 </li>1629 </li>
1630 <li>
1631 <pre><code class="language-stscript">/add ["count", 15, 2, "i"]</code></pre>
1632 </li>
1621 </ul>1633 </ul>
1622 </div>1634 </div>
1623 `,1635 `,
@@ -1629,7 +1641,7 @@ export function registerVariableCommands() {
1629 unnamedArgumentList: [1641 unnamedArgumentList: [
1630 SlashCommandArgument.fromProps({1642 SlashCommandArgument.fromProps({
1631 description: 'values to multiply',1643 description: 'values to multiply',
1632 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME],1644 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
1633 isRequired: true,1645 isRequired: true,
1634 acceptsMultiple: true,1646 acceptsMultiple: true,
1635 enumProvider: commonEnumProviders.numbersAndVariables,1647 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1639,7 +1651,10 @@ export function registerVariableCommands() {
1639 splitUnnamedArgument: true,1651 splitUnnamedArgument: true,
1640 helpString: `1652 helpString: `
1641 <div>1653 <div>
1642 Performs a multiplication of the set of values and passes the result down the pipe. Can use variable names.1654 Performs a multiplication of the set of values and passes the result down the pipe.
1655 </div>
1656 <div>
1657 Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
1643 </div>1658 </div>
1644 <div>1659 <div>
1645 <strong>Examples:</strong>1660 <strong>Examples:</strong>
@@ -1647,6 +1662,9 @@ export function registerVariableCommands() {
1647 <li>1662 <li>
1648 <pre><code class="language-stscript">/mul 10 i 30 j</code></pre>1663 <pre><code class="language-stscript">/mul 10 i 30 j</code></pre>
1649 </li>1664 </li>
1665 <li>
1666 <pre><code class="language-stscript">/mul ["count", 15, 2, "i"]</code></pre>
1667 </li>
1650 </ul>1668 </ul>
1651 </div>1669 </div>
1652 `,1670 `,
@@ -1658,7 +1676,7 @@ export function registerVariableCommands() {
1658 unnamedArgumentList: [1676 unnamedArgumentList: [
1659 SlashCommandArgument.fromProps({1677 SlashCommandArgument.fromProps({
1660 description: 'values to find the max',1678 description: 'values to find the max',
1661 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME],1679 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
1662 isRequired: true,1680 isRequired: true,
1663 acceptsMultiple: true,1681 acceptsMultiple: true,
1664 enumProvider: commonEnumProviders.numbersAndVariables,1682 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1668,7 +1686,10 @@ export function registerVariableCommands() {
1668 splitUnnamedArgument: true,1686 splitUnnamedArgument: true,
1669 helpString: `1687 helpString: `
1670 <div>1688 <div>
1671 Returns the maximum value of the set of values and passes the result down the pipe. Can use variable names.1689 Returns the maximum value of the set of values and passes the result down the pipe.
1690 </div>
1691 <div>
1692 Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
1672 </div>1693 </div>
1673 <div>1694 <div>
1674 <strong>Examples:</strong>1695 <strong>Examples:</strong>
@@ -1676,6 +1697,9 @@ export function registerVariableCommands() {
1676 <li>1697 <li>
1677 <pre><code class="language-stscript">/max 10 i 30 j</code></pre>1698 <pre><code class="language-stscript">/max 10 i 30 j</code></pre>
1678 </li>1699 </li>
1700 <li>
1701 <pre><code class="language-stscript">/max ["count", 15, 2, "i"]</code></pre>
1702 </li>
1679 </ul>1703 </ul>
1680 </div>1704 </div>
1681 `,1705 `,
@@ -1687,7 +1711,7 @@ export function registerVariableCommands() {
1687 unnamedArgumentList: [1711 unnamedArgumentList: [
1688 SlashCommandArgument.fromProps({1712 SlashCommandArgument.fromProps({
1689 description: 'values to find the min',1713 description: 'values to find the min',
1690 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME],1714 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
1691 isRequired: true,1715 isRequired: true,
1692 acceptsMultiple: true,1716 acceptsMultiple: true,
1693 enumProvider: commonEnumProviders.numbersAndVariables,1717 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1698,7 +1722,9 @@ export function registerVariableCommands() {
1698 helpString: `1722 helpString: `
1699 <div>1723 <div>
1700 Returns the minimum value of the set of values and passes the result down the pipe.1724 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).
1702 </div>1728 </div>
1703 <div>1729 <div>
1704 <strong>Example:</strong>1730 <strong>Example:</strong>
@@ -1706,6 +1732,9 @@ export function registerVariableCommands() {
1706 <li>1732 <li>
1707 <pre><code class="language-stscript">/min 10 i 30 j</code></pre>1733 <pre><code class="language-stscript">/min 10 i 30 j</code></pre>
1708 </li>1734 </li>
1735 <li>
1736 <pre><code class="language-stscript">/min ["count", 15, 2, "i"]</code></pre>
1737 </li>
1709 </ul>1738 </ul>
1710 </div>1739 </div>
1711 `,1740 `,
@@ -1717,7 +1746,7 @@ export function registerVariableCommands() {
1717 unnamedArgumentList: [1746 unnamedArgumentList: [
1718 SlashCommandArgument.fromProps({1747 SlashCommandArgument.fromProps({
1719 description: 'values to subtract, starting form the first provided value',1748 description: 'values to subtract, starting form the first provided value',
1720 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME],1749 typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST],
1721 isRequired: true,1750 isRequired: true,
1722 acceptsMultiple: true,1751 acceptsMultiple: true,
1723 enumProvider: commonEnumProviders.numbersAndVariables,1752 enumProvider: commonEnumProviders.numbersAndVariables,
@@ -1728,7 +1757,9 @@ export function registerVariableCommands() {
1728 helpString: `1757 helpString: `
1729 <div>1758 <div>
1730 Performs a subtraction of the set of values and passes the result down the pipe.1759 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).
1732 </div>1763 </div>
1733 <div>1764 <div>
1734 <strong>Example:</strong>1765 <strong>Example:</strong>
@@ -1736,6 +1767,9 @@ export function registerVariableCommands() {
1736 <li>1767 <li>
1737 <pre><code class="language-stscript">/sub i 5</code></pre>1768 <pre><code class="language-stscript">/sub i 5</code></pre>
1738 </li>1769 </li>
1770 <li>
1771 <pre><code class="language-stscript">/sub ["count", 4, "i"]</code></pre>
1772 </li>
1739 </ul>1773 </ul>
1740 </div>1774 </div>
1741 `,1775 `,