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