From 4cc244aa5b9a71e365412b735d933cfef9b4e1d0 Mon Sep 17 00:00:00 2001 From: haunter Date: Wed, 22 Apr 2026 19:55:34 +0300 Subject: [PATCH] fix broken previoius push --- static/js/components/townViewer.js | 55 ++++++++++++++++-------------- 1 file changed, 30 insertions(+), 25 deletions(-) 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 `
-
${markers}${t.town_name}${t.has_premium ? ' ' : ''}
-
${t.sea != null ? `🌊 Θ${t.sea} · ` : ''}${t.points} pts · ${t.god || 'No god'} · ${ageMin}m ago
+
${markers}${t.town_name || 'Άγνωστη'}${t.has_premium ? ' ' : ''}
+
${t.sea != null ? `🌊 Θ${t.sea} · ` : ''}${t.points || 0} pts · ${t.god || 'No god'} · ${ageMin}m ago
-
${window.fmt(t.resources.wood)}
-
${window.fmt(t.resources.stone)}
-
${window.fmt(t.resources.iron)}
-
${window.fmt(t.resources.population)}
+
${window.fmt(res.wood || 0)}
+
${window.fmt(res.stone || 0)}
+
${window.fmt(res.iron || 0)}
+
${window.fmt(res.population || 0)}
`; }).join(''); @@ -101,9 +105,10 @@ window.renderTownDetails = function() { const t = window.getSelectedTown(); if(!t) return; - document.getElementById('td-name').textContent = t.town_name; + document.getElementById('td-name').textContent = t.town_name || 'Άγνωστη'; - const cap = t.resources.storage || 1; + const resObj = t.resources || {}; + const cap = resObj.storage || 1; const getCol = (amt) => { const pct = amt / cap; if (pct >= 0.95) return 'color: #ff4a4a;'; // Red @@ -146,14 +151,14 @@ window.renderTownDetails = function() { return base; }; - const capFmt = (t.resources.storage != null && t.resources.storage !== '') ? window.fmt(t.resources.storage) : '?'; + const capFmt = (resObj.storage != null && resObj.storage !== '') ? window.fmt(resObj.storage) : '?'; document.getElementById('td-resources').innerHTML = `
Χωρητικότητα: ${capFmt}
-
${window.RES_ICONS.wood} Ξύλο: ${resHtml(t.resources.wood, reservedWood)}
-
${window.RES_ICONS.stone} Πέτρα: ${resHtml(t.resources.stone, reservedStone)}
-
${window.RES_ICONS.iron} Ασήμι: ${resHtml(t.resources.iron, reservedIron)}
-
${window.RES_ICONS.pop} Πληθυσμός: ${t.resources.population}
+
${window.RES_ICONS.wood} Ξύλο: ${resHtml(resObj.wood || 0, reservedWood)}
+
${window.RES_ICONS.stone} Πέτρα: ${resHtml(resObj.stone || 0, reservedStone)}
+
${window.RES_ICONS.iron} Ασήμι: ${resHtml(resObj.iron || 0, reservedIron)}
+
${window.RES_ICONS.pop} Πληθυσμός: ${resObj.population || 0}
`; const godName = t.god ? t.god.charAt(0).toUpperCase() + t.god.slice(1) : 'Κανένας';