diff --git a/static/js/components/commandForm.js b/static/js/components/commandForm.js index efbbc62..c3957ea 100644 --- a/static/js/components/commandForm.js +++ b/static/js/components/commandForm.js @@ -376,6 +376,9 @@ window.openUnitModal = function() { let costStr = ''; let clickable = false; + let maxBuild = 0; + let currentCount = town.units ? (town.units[key] || 0) : 0; + const requiredGod = window.UNIT_GODS ? window.UNIT_GODS[key] : null; const isWrongGod = requiredGod && town.god !== requiredGod; const isNoGod = key === 'godsent' && !town.god; @@ -396,6 +399,19 @@ window.openUnitModal = function() { const i = window.fmt(data.iron || 0); const pop = data.pop || 0; + // Calculate max buildable + if (!isLocked) { + const tRes = town.resources || {}; + const mWood = data.wood ? Math.floor((tRes.wood || 0) / data.wood) : Infinity; + const mStone = data.stone ? Math.floor((tRes.stone || 0) / data.stone) : Infinity; + const mIron = data.iron ? Math.floor((tRes.iron || 0) / data.iron) : Infinity; + const mPop = data.pop ? Math.floor((tRes.population || 0) / data.pop) : Infinity; + const mFavor = data.favor ? Math.floor((tRes.favor || 0) / data.favor) : Infinity; + + maxBuild = Math.min(mWood, mStone, mIron, mPop, mFavor); + if (maxBuild === Infinity) maxBuild = 0; + } + let t = data.build_time || 0; let tStr = `${t}s`; if (t > 60) { @@ -410,7 +426,7 @@ window.openUnitModal = function() { if (isLocked) { statusClass = 'locked'; statusLabel = '🔒 Κλειδωμένο'; cardClass = 'bld-locked'; - } else if (data.enough_resources === false) { + } else if (maxBuild <= 0) { statusClass = 'no-resources'; statusLabel = '❌ Λείπουν Πόροι'; } else { statusClass = 'can-build'; statusLabel = '✅ Διαθέσιμο'; @@ -423,11 +439,13 @@ window.openUnitModal = function() { const onclick = clickable ? `onclick="window.selectUnit('${key}', '${nameGr}')"` : ''; - catHtml += `
- ${icon} - ${nameGr} - ${statusLabel} - ${costStr} + catHtml += `
+ ${icon} +
${currentCount}
+
+${maxBuild}
+ ${nameGr} + ${statusLabel} + ${costStr}
`; }