From 2de4984e23a3d2689b421ab5fae29df4d7b0b8df Mon Sep 17 00:00:00 2001 From: James Fleming Date: Mon, 15 Aug 2022 15:17:24 -0400 Subject: [PATCH] Set ready_ attributes based on current weapon/spell selection --- The Fantasy Trip/TFT.html | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/The Fantasy Trip/TFT.html b/The Fantasy Trip/TFT.html index f93597b3e1..8f1d4198da 100644 --- a/The Fantasy Trip/TFT.html +++ b/The Fantasy Trip/TFT.html @@ -1052,6 +1052,8 @@ // select this weapon or spell, id starts with repeating_[weapon][spell] + // it will set attributes ready_name, damage, to_hit, attack, success, failure + // so macros can get at them. const selectWeaponOrSpell = function(id) { // get them all, and de check any not me... let selected = (id + "_selection-flag").toLowerCase(); @@ -1061,6 +1063,7 @@ let oldValue = values[selected]; let newValue = (oldValue == 'on' ? 0 : 'on'); let valueMap = {}; + let readyAttributes = []; // toggle this one, turn off the rest valueMap[selected] = newValue; @@ -1070,16 +1073,50 @@ let propertyName = repeatingPropertyName('weapons', weaponIds[i], 'selection-flag'); if (propertyName != selected) { valueMap[propertyName] = 0; + } else { + let id = weaponIds[i]; + readyAttributes = [repeatingPropertyName('weapons', id, 'weaponname'), + repeatingPropertyName('weapons', id, 'weapondamage'), + repeatingPropertyName('weapons', id, 'tohit'), + repeatingPropertyName('weapons', id, 'attackflavor'), + repeatingPropertyName('weapons', id, 'successflavor'), + repeatingPropertyName('weapons', id, 'failureflavor')]; } } for (var i = 0; i < spellIds.length; ++i) { let propertyName = repeatingPropertyName('spells', spellIds[i], 'selection-flag'); if (propertyName != selected) { valueMap[propertyName] = 0; + } else { + let id = spellIds[i]; + readyAttributes = [repeatingPropertyName('spells', id, 'spellname'), + repeatingPropertyName('spells', id, 'spelldamage'), + repeatingPropertyName('spells', id, 'tohit'), + repeatingPropertyName('spells', id, 'attackflavor'), + repeatingPropertyName('spells', id, 'successflavor'), + repeatingPropertyName('spells', id, 'failureflavor')]; } } } - setAttrs(valueMap, {silent: true}); + getAttrs(readyAttributes, function(readyValues) { + // convert into ready_ attributes. + for (const [key, value] of Object.entries(readyValues)) { + if (key.endsWith('name')) { + valueMap['ready_name'] = value + } else if (key.endsWith('damage')) { + valueMap['ready_damage'] = value + } else if (key.endsWith('tohit')) { + valueMap['ready_tohit'] = value + } else if (key.endsWith('attackflavor')) { + valueMap['ready_attackflavor'] = value + } else if (key.endsWith('successflavor')) { + valueMap['ready_successflavor'] = value + } else if (key.endsWith('failureflavor')) { + valueMap['ready_failureflavor'] = value + } + } + setAttrs(valueMap, {silent: true}); + }) }); }); });