diff --git a/bin/web/js/layer.js b/bin/web/js/layer.js index c30fee3..fa8712e 100644 --- a/bin/web/js/layer.js +++ b/bin/web/js/layer.js @@ -100,20 +100,37 @@ const Layer = function(tp, layerID, fontsAndAxes, autoInit = true) { ); let axes = fontsAndAxes[selectedFontIndex].axes; if (axes.length > 0) { - let variationAxes = {}; + let variationAxes = {}; + let doThese = []; for (let a = 0; a < axes.length; a++) { const sanity_minMax = axes[a].minValue < axes[a].maxValue; const sanity_minDefault = axes[a].minValue <= axes[a].defaultValue; const sanity_maxDefault = axes[a].maxValue >= axes[a].defaultValue; if (sanity_minMax && sanity_minDefault && sanity_maxDefault) { variationAxes[axes[a].name] = tp.core.types.number(axes[a].defaultValue, { - range: [axes[a].minValue, axes[a].maxValue], + range: [axes[a].minValue, axes[a].maxValue], }); + if (typeof audio === 'object' && + typeof audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`] === 'object' && + typeof audio.getMapping()[this.id()][`fontVariationAxes.${axes[a].name}`] === 'object' && + tp.getPanel() !== null) { + doThese.push(() => { + audio.removeAudioOptions(this, `fontVariationAxes.${axes[a].name}`); + audio.removeAudioMapping(this, `fontVariationAxes.${axes[a].name}`); + audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].min_out = axes[a].minValue; + audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].max_out = axes[a].maxValue; + audio.addAudioMapping(this, `fontVariationAxes.${axes[a].name}`); + audio.addAudioOptions(this, `fontVariationAxes.${axes[a].name}`); + }); + } } else { console.log('js::layer::selectFont', 'this axis is insane, abort', axes[a]); } } props.fontVariationAxes = tp.core.types.compound(variationAxes); + doThese.forEach((d) => { + d(); + }); } else { delete props.fontVariationAxes; }