From 2134c7841af8c8f3f99a8c081e82cd7b6db63342 Mon Sep 17 00:00:00 2001 From: JustEngineer Date: Mon, 13 Oct 2025 16:08:56 +0300 Subject: [PATCH 1/2] fixed total pixel count behavior to ChargeModel system --- Extension/scripts/Auto-Image.js | 38 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Extension/scripts/Auto-Image.js b/Extension/scripts/Auto-Image.js index 93d5040..e6d9e60 100644 --- a/Extension/scripts/Auto-Image.js +++ b/Extension/scripts/Auto-Image.js @@ -4594,25 +4594,18 @@ localStorage.removeItem("lp"); let totalMaxCharges = 0; const accounts = accountManager.getAllAccounts(); if (accounts.length > 0) { - // Use real-time charges for current account, stored data for others - const currentAccount = accountManager.getCurrentAccount(); + // Use ChargeModel (real-time) when available for consistent totals totalAllCharges = accounts.reduce((sum, acc) => { - if (currentAccount && acc.token === currentAccount.token) { - // Use real-time data for current account - return sum + Math.floor(state.displayCharges || state.preciseCurrentCharges || 0); - } else { - // Use stored data for other accounts - return sum + Math.floor(acc.Charges || 0); - } + const node = ChargeModel.get(acc.token); + const charges = Number.isFinite(node?.charges) ? Math.floor(node.charges) : Math.floor(acc.Charges || 0); + const max = Number.isFinite(node?.max) ? Math.floor(node.max) : Math.floor(acc.Max || 0); + const safeCharges = Math.max(0, Math.min(charges, max)); + return sum + safeCharges; }, 0); totalMaxCharges = accounts.reduce((sum, acc) => { - if (currentAccount && acc.token === currentAccount.token) { - // Use real-time max charges for current account - return sum + Math.floor((state.fullChargeData?.max ?? state.maxCharges ?? acc.Max ?? 0)); - } else { - // Use stored data for other accounts - return sum + Math.floor(acc.Max || 0); - } + const node = ChargeModel.get(acc.token); + const max = Number.isFinite(node?.max) ? Math.floor(node.max) : Math.floor(acc.Max || 0); + return sum + Math.max(0, max); }, 0); } @@ -10200,10 +10193,15 @@ localStorage.removeItem("lp"); state.displayCharges = Math.floor(node.charges || 0); state.preciseCurrentCharges = node.charges || 0; await updateStats(); - accountManager.updateAccountData(current.token, { - Charges: Math.floor(node.charges || 0), - Max: Math.floor(node.max || current.Max || 0) - }); + // Refresh server-backed fields (droplets/max) to avoid stale/incorrect UI + try { + const live = await WPlaceService.getCharges(); + accountManager.updateAccountData(current.token, { + Charges: Math.floor(node.charges || 0), + Max: Math.floor(live.max || node.max || current.Max || 0), + Droplets: Math.floor(live.droplets || 0) + }); + } catch {} renderAccountsList(); } catch (e) { console.warn('⚠️ updateCurrentAccountInList failed:', e); From 7a37809ea4469db20187313fa110315b4bb2b9b4 Mon Sep 17 00:00:00 2001 From: JustEngineer Date: Mon, 13 Oct 2025 19:31:50 +0300 Subject: [PATCH 2/2] Add back check for a threshold before painting --- Extension/scripts/Auto-Image.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Extension/scripts/Auto-Image.js b/Extension/scripts/Auto-Image.js index e6d9e60..ae78705 100644 --- a/Extension/scripts/Auto-Image.js +++ b/Extension/scripts/Auto-Image.js @@ -8736,11 +8736,11 @@ localStorage.removeItem("lp"); }; // IMPORTANT: Check charges once at start, then paint until depleted - console.log('🔋 Checking initial charges for painting session'); // Use local charge model to avoid extra API calls + console.log('🔋 Checking initial charges for painting session'); const currentToken = accountManager.getCurrentAccount()?.token; let node = ChargeModel.get(currentToken); - // One-time sync for current account if never synced (safety) + // One-time sync for current account if never synced if (node && !node.lastSyncAt) { try { const sync = await WPlaceService.getCharges(); @@ -8757,6 +8757,22 @@ localStorage.removeItem("lp"); return 'charges_depleted'; } + // If current account has less than threshold charges but another account + // has reached the threshold, switch BEFORE painting anything on the under-threshold account + try { + const threshold = Math.max(1, state.cooldownChargeThreshold || 1); + if (CONFIG.autoSwap && state.displayCharges < threshold) { + console.log(`🛑 Current charges (${state.displayCharges}) < threshold (${threshold}). Checking other accounts before painting...`); + const switched = await selectAndSwitchToAccountWithCharges(threshold); + if (switched) { + console.log('🔀 Switched to an account that met the threshold before painting. Restarting cycle...'); + return 'charges_depleted'; + } + } + } catch (e) { + console.warn('⚠️ Pre-paint switch guard failed:', e); + } + console.log(`🔋 Starting with ${state.displayCharges} charges - painting until depleted`); // Paint pixels until we run out of charges or complete the image