diff --git a/api/items.js b/api/items.js index 85750a9..7b32a18 100644 --- a/api/items.js +++ b/api/items.js @@ -225,9 +225,10 @@ function deepClone (obj) { * * @param { any } item * @param { any } type + * @param { any } values * @returns { any } The item with modified property values */ -function populateVariablesMutable (item, type) { +function populateVariablesMutable (item, type, values) { if (!item.data) { item.data = {} } @@ -239,7 +240,7 @@ function populateVariablesMutable (item, type) { const currentValue = objectPath.get(item.data, key) if (currentValue != null) { - objectPath.set(item.data, key, JSON.parse(variables.substituteInString(JSON.stringify(currentValue)))) + objectPath.set(item.data, key, JSON.parse(variables.substituteInString(JSON.stringify(currentValue), values))) } } @@ -263,7 +264,9 @@ async function playItem (id) { } const type = await types.getType(item.type) - const clone = populateVariablesMutable(deepClone(item), type) + const vars = await variables.getAllVariables() + const clone = populateVariablesMutable(deepClone(item), type, vars) + const delay = parseInt(clone?.data?.delay) if (delay && !Number.isNaN(delay)) { diff --git a/api/variables.js b/api/variables.js index ad1cd02..d4f755d 100644 --- a/api/variables.js +++ b/api/variables.js @@ -27,6 +27,15 @@ function getVariable (key) { } exports.getVariable = getVariable +/** + * Get all variables' values + * @returns { Promise. } + */ +async function getAllVariables () { + return state.get('variables') +} +exports.getAllVariables = getAllVariables + /** * Substitute variables for their * values in a string