From f4016b443126202f56c97f4ecbb4ea035fd70871 Mon Sep 17 00:00:00 2001 From: haunter Date: Tue, 21 Apr 2026 23:34:59 +0300 Subject: [PATCH] add some filters v1 --- static/js/components/townViewer.js | 60 +++++++++++++++++++++++++++--- templates/dashboard.html | 19 ++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/static/js/components/townViewer.js b/static/js/components/townViewer.js index d1a73b3..607c53f 100644 --- a/static/js/components/townViewer.js +++ b/static/js/components/townViewer.js @@ -4,27 +4,75 @@ window.renderTowns = function() { const container = document.getElementById('town-list'); - if (!window.towns.length) { + if (!window.towns || !window.towns.length) { container.innerHTML = '

No towns received yet.

'; return; } + // Get active filters + const searchTerm = (document.getElementById('town-search')?.value || '').toLowerCase(); + const reqFullWh = document.getElementById('filter-full-wh')?.checked; + const reqFestival = document.getElementById('filter-festival')?.checked; + const reqPoints = document.getElementById('filter-points')?.checked; + + const filteredTowns = window.towns.filter(t => { + // 1. Search by name + if (searchTerm && !t.town_name.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; + + // 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; + + // 4. Large Points + if (reqPoints && t.points < 10000) return false; + + return true; + }); + + if (filteredTowns.length === 0) { + container.innerHTML = '

Καμία πόλη δεν ταιριάζει στα κριτήρια.

'; + return; + } + const now = Date.now(); - container.innerHTML = window.towns.map(t => { + container.innerHTML = filteredTowns.map(t => { const updatedMs = new Date(t.updated_at + 'Z').getTime(); const ageMin = Math.round((now - updatedMs) / 60000); 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; + + 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) { + markers += '🎭'; + } + + const getC = (pct) => pct >= 0.95 ? 'color:#ff4a4a;font-weight:bold;' : ''; + return `
-
${t.town_name}${t.has_premium ? ' ' : ''}
+
${markers}${t.town_name}${t.has_premium ? ' ' : ''}
${t.sea != null ? `🌊 Θ${t.sea} · ` : ''}${t.points} 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.wood)}
+
${window.fmt(t.resources.stone)}
+
${window.fmt(t.resources.iron)}
${window.fmt(t.resources.population)}
`; diff --git a/templates/dashboard.html b/templates/dashboard.html index 397c16b..6920c05 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -28,6 +28,25 @@

Towns

+ +
+ + +
+ + + + + +
+
+

Waiting for data from home PC…