From c1cc8ceb7a60fdd3bfbf5915575dc7059ebf2500 Mon Sep 17 00:00:00 2001 From: haunter Date: Wed, 22 Apr 2026 20:48:34 +0300 Subject: [PATCH] greekbuilding names ,live synch button ,market capacity --- GrepolisRemoteControl.user.js | 21 +++++++++++++++++++ routes/api.py | 31 ++++++++++++++++++++++++++++- routes/dashboard.py | 1 + static/js/api.js | 25 +++++++++++++++++++++++ static/js/components/commandForm.js | 8 +++++--- static/js/components/townViewer.js | 5 +++++ templates/dashboard.html | 6 +++++- 7 files changed, 92 insertions(+), 5 deletions(-) diff --git a/GrepolisRemoteControl.user.js b/GrepolisRemoteControl.user.js index 401c3a6..8f8a847 100644 --- a/GrepolisRemoteControl.user.js +++ b/GrepolisRemoteControl.user.js @@ -157,6 +157,21 @@ log(`storage capacity lookup failed: ${e}`); } + // ---- Market / Trade capacity ----------------------------------------- + let marketCapacity = 0; + try { + const marketLevel = buildings.market ?? 0; + const gd = uw.GameData?.buildingData?.market; + marketCapacity = gd?.capacity_per_level?.[marketLevel] || 0; + + // Add Trade Office bonus if present + if (buildings.trade_office && buildings.trade_office > 0) { + marketCapacity += (uw.GameData?.buildingData?.trade_office?.capacity_extra_per_level || 500) * marketLevel; + } + } catch (e) { + log(`market capacity lookup failed: ${e}`); + } + // ---- Coordinates & sea zone ----------------------------------------- let x = null, y = null, sea = null; try { @@ -234,6 +249,7 @@ stone: res.stone, iron: res.iron, storage: storageCapacity, + market_capacity: marketCapacity, population: res.population, points: town.getPoints?.() ?? 0, god: town.god?.() ?? null, @@ -466,6 +482,11 @@ const recruitCmd = cmdData.recruit; const marketCmd = cmdData.market; + if (cmdData.sync_requested) { + log('Sync requested by server — pushing state immediately'); + pushState(); + } + const execute = async (cmd) => { if (!cmd) return; log(`Executing command #${cmd.id} — type:${cmd.type} town:${cmd.town_id}`); diff --git a/routes/api.py b/routes/api.py index a0df951..bdc67c5 100644 --- a/routes/api.py +++ b/routes/api.py @@ -105,9 +105,38 @@ def get_pending_command(): return jsonify({ 'build': build_cmd, 'recruit': recruit_cmd, - 'market': market_cmd + 'market': market_cmd, + 'sync_requested': _check_and_reset_sync(c, player_id) }) +def _check_and_reset_sync(c, player_id): + key = f'sync_request_{player_id}' + row = c.execute("SELECT value FROM kv_store WHERE key = ?", (key,)).fetchone() + if row and row['value'] == '1': + c.execute("UPDATE kv_store SET value = '0', updated_at = ? WHERE key = ?", (datetime.utcnow().isoformat(), key)) + return True + return False + +# ------------------------------------------------------------------ +# POST /api/sync-request +# Dashboard requests an immediate state update from the client. +# ------------------------------------------------------------------ +@api.route('/api/sync-request', methods=['POST']) +def sync_request(): + player_id = request.args.get('player_id') + if not player_id: + return jsonify({'error': 'no player_id provided'}), 400 + + conn = get_db() + conn.execute(''' + INSERT INTO kv_store (key, value, updated_at) + VALUES (?, '1', ?) + ON CONFLICT(key) DO UPDATE SET value = '1', updated_at = excluded.updated_at + ''', (f'sync_request_{player_id}', datetime.utcnow().isoformat())) + conn.commit() + conn.close() + return jsonify({'ok': True}) + # ------------------------------------------------------------------ # POST /api/commands//result diff --git a/routes/dashboard.py b/routes/dashboard.py index 1a73f02..2c1f7cd 100644 --- a/routes/dashboard.py +++ b/routes/dashboard.py @@ -89,6 +89,7 @@ def get_towns(): 'stone': d.get('stone', 0), 'iron': d.get('iron', 0), 'storage': d.get('storage', 0), + 'market_capacity': d.get('market_capacity', 0), 'population': d.get('population', 0), }, 'buildings': d.get('buildings', {}), diff --git a/static/js/api.js b/static/js/api.js index 74749d5..ee24f3d 100644 --- a/static/js/api.js +++ b/static/js/api.js @@ -223,3 +223,28 @@ window.dismissCaptchaBanner = function() { banner.dataset.dismissed = '1'; } }; + +window.requestLiveSync = async function() { + const btn = document.getElementById('live-btn'); + const originalText = btn.textContent; + btn.textContent = '⏳ Requesting...'; + btn.disabled = true; + + try { + const res = await fetch('/api/sync-request?player_id=' + window.PLAYER_ID, { method: 'POST' }); + const data = await res.json(); + if (data.ok) { + btn.textContent = '✅ Requested!'; + setTimeout(() => { + btn.textContent = originalText; + btn.disabled = false; + }, 5000); + } + } catch (e) { + btn.textContent = '❌ Failed'; + setTimeout(() => { + btn.textContent = originalText; + btn.disabled = false; + }, 3000); + } +}; diff --git a/static/js/components/commandForm.js b/static/js/components/commandForm.js index 2d48d35..3f8cdaa 100644 --- a/static/js/components/commandForm.js +++ b/static/js/components/commandForm.js @@ -144,8 +144,10 @@ window.renderBuildQueuePreview = function() { el.innerHTML = 'Build queue: empty'; return; } - const items = town.build_queue.map(o => - `${o.building_type || o.name || JSON.stringify(o)}` - ).join(''); + const items = town.build_queue.map(o => { + const raw = o.building_type || o.name || ""; + const nameGr = window.BUILDING_NAMES_GR[raw] || raw || JSON.stringify(o); + return `${nameGr}`; + }).join(''); el.innerHTML = `
Current queue
${items}`; }; diff --git a/static/js/components/townViewer.js b/static/js/components/townViewer.js index 8e812de..f31cdc1 100644 --- a/static/js/components/townViewer.js +++ b/static/js/components/townViewer.js @@ -160,6 +160,11 @@ window.renderTownDetails = function() {
${window.RES_ICONS.iron} Ασήμι: ${resHtml(resObj.iron || 0, reservedIron)}
${window.RES_ICONS.pop} Πληθυσμός: ${resObj.population || 0}
`; + + const mCap = resObj.market_capacity || 0; + document.getElementById('td-market').innerHTML = ` + 📦 Εμπορική Χωρητικότητα: ${window.fmt(mCap)} + `; const godName = t.god ? t.god.charAt(0).toUpperCase() + t.god.slice(1) : 'Κανένας'; const seaStr = t.sea != null ? `Θ${t.sea}` : '—'; diff --git a/templates/dashboard.html b/templates/dashboard.html index 505c6f9..4ab18de 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -27,7 +27,10 @@
-

Towns

+
+

Towns

+ +
@@ -63,6 +66,7 @@
Ποροι
+