diff --git a/iframe.html b/iframe.html index 81fa320..bd2d3e1 100644 --- a/iframe.html +++ b/iframe.html @@ -1948,13 +1948,19 @@ return; } - // Check if this is the only unlocked source (will be forced to fixed percentage) + // Check if this source has no flexibility (either only unlocked or no percentage available) const otherUnlockedSources = this.foodSources.filter((fs, index) => fs.id !== id && !fs.isLocked ); - if (otherUnlockedSources.length === 0) { - // This is the only unlocked source - don't update display, just call adjustPercentages + // Calculate available percentage for this source + const lockedSources = this.foodSources.filter(fs => fs.id !== id && fs.isLocked); + const totalLockedPercentage = lockedSources.reduce((sum, fs) => sum + fs.percentage, 0); + const otherUnlockedPercentage = otherUnlockedSources.reduce((sum, fs) => sum + fs.percentage, 0); + const availablePercentage = 100 - totalLockedPercentage - otherUnlockedPercentage; + + if (otherUnlockedSources.length === 0 || availablePercentage <= 0) { + // This source has no flexibility - don't update display, just call adjustPercentages // which will force it to the correct value and update display properly this.adjustPercentages(id, parseInt(percentageSlider.value)); return;