diff --git a/static/js/components/townViewer.js b/static/js/components/townViewer.js index 480fff3..8a9b6b1 100644 --- a/static/js/components/townViewer.js +++ b/static/js/components/townViewer.js @@ -17,22 +17,25 @@ window.renderTowns = function() { const filteredTowns = window.towns.filter(t => { // 1. Search by name - if (searchTerm && !t.town_name.toLowerCase().includes(searchTerm)) return false; + const tName = t.town_name || ''; + if (searchTerm && !tName.toLowerCase().includes(searchTerm)) return false; - const cap = t.resources.storage || 1; - const wPct = t.resources.wood / cap; - const sPct = t.resources.stone / cap; - const iPct = t.resources.iron / cap; + const res = t.resources || {}; + const cap = res.storage || 1; + const wPct = (res.wood || 0) / cap; + const sPct = (res.stone || 0) / cap; + const iPct = (res.iron || 0) / cap; // 2. Full WH (>95%) if (reqFullWh && Math.max(wPct, sPct, iPct) < 0.95) return false; // 3. Festival (Wood>15k, Stone>18k, Iron>15k) // City Festival exact costs = 15000, 18000, 15000 - if (reqFestival && (t.resources.wood < 15000 || t.resources.stone < 18000 || t.resources.iron < 15000)) return false; + if (reqFestival && ((res.wood || 0) < 15000 || (res.stone || 0) < 18000 || (res.iron || 0) < 15000)) return false; // 4. Large Points - if (reqPoints && t.points < 10000) return false; + const pts = typeof t.points === 'number' ? t.points : parseInt(t.points) || 0; + if (reqPoints && pts < 10000) return false; return true; }); @@ -49,16 +52,17 @@ window.renderTowns = function() { const stale = ageMin > 3; const selected = t.town_id === window.selectedTownId ? 'selected' : ''; - const cap = t.resources.storage || 1; - const wPct = t.resources.wood / cap; - const sPct = t.resources.stone / cap; - const iPct = t.resources.iron / cap; + const res = t.resources || {}; + const cap = res.storage || 1; + const wPct = (res.wood || 0) / cap; + const sPct = (res.stone || 0) / cap; + const iPct = (res.iron || 0) / cap; let markers = ''; if (wPct >= 0.95 || sPct >= 0.95 || iPct >= 0.95) { markers += '⚠️'; } - if (t.resources.wood >= 15000 && t.resources.stone >= 18000 && t.resources.iron >= 15000) { + if ((res.wood || 0) >= 15000 && (res.stone || 0) >= 18000 && (res.iron || 0) >= 15000) { markers += '🎭'; } @@ -67,13 +71,13 @@ window.renderTowns = function() { return `