diff --git a/Extension/scripts/Auto-Image.js b/Extension/scripts/Auto-Image.js index 114b5c9..fa8c943 100644 --- a/Extension/scripts/Auto-Image.js +++ b/Extension/scripts/Auto-Image.js @@ -51,6 +51,12 @@ function getText(key, params) { console.log('%c🚀 WPlace AutoBot Auto-Image Starting...', 'color: #00ff41; font-weight: bold; font-size: 16px;'); + const buyTypes = [ + 'none', + 'max_charges', + 'paint_charges' + ]; + // CONFIGURATION CONSTANTS const CONFIG = { COOLDOWN_DEFAULT: 31000, @@ -319,6 +325,10 @@ function getText(key, params) { COORDINATE_BLOCK_WIDTH: 6, COORDINATE_BLOCK_HEIGHT: 2, autoSwap: true, + autoBuy: buyTypes[2], + autoBuyToggle: false, + maxChargesStopEnable: false, + maxChargesBeforeStop: 1500, }; // Expose CONFIG globally for the utils manager and other modules @@ -760,13 +770,13 @@ function getText(key, params) { this.accounts = []; this.currentIndex = 0; } - + // Load accounts from storage async loadAccounts() { try { // Get tokens from localStorage const tokens = JSON.parse(localStorage.getItem("accounts")) || []; - + // Get account info from storage const infoAccountsResult = await new Promise((resolve) => { if (typeof chrome !== 'undefined' && chrome.storage) { @@ -778,9 +788,9 @@ function getText(key, params) { resolve([]); } }); - + console.log(`📥 [ACCOUNT MANAGER] Loading ${tokens.length} accounts`); - + this.accounts = tokens.map((token, index) => { const info = infoAccountsResult.find(acc => acc.token === token); return { @@ -795,14 +805,14 @@ function getText(key, params) { lastImported: info?.lastImported || null }; }); - + // Find current account index this.currentIndex = this.accounts.findIndex(acc => acc.isCurrent); if (this.currentIndex === -1) this.currentIndex = 0; - + console.log(`✅ [ACCOUNT MANAGER] Loaded ${this.accounts.length} accounts, current index: ${this.currentIndex}`); console.log(`🎯 [ACCOUNT MANAGER] Current account: ${this.getCurrentAccount()?.displayName || 'None'}`); - + // Auto-refresh account statuses after loading if (this.accounts.length > 0) { console.log('🔄 [ACCOUNT MANAGER] Auto-refreshing account statuses...'); @@ -816,7 +826,7 @@ function getText(key, params) { } }, 100); } - + return this.accounts; } catch (error) { console.error('❌ [ACCOUNT MANAGER] Error loading accounts:', error); @@ -825,37 +835,37 @@ function getText(key, params) { return []; } } - + // Simple linear switching switchToNext() { if (this.accounts.length === 0) return null; - + const previousIndex = this.currentIndex; this.currentIndex = (this.currentIndex + 1) % this.accounts.length; - + console.log(`🔄 [ACCOUNT MANAGER] Switching: ${previousIndex} → ${this.currentIndex}`); console.log(`🎯 [ACCOUNT MANAGER] Target: ${this.accounts[this.currentIndex].displayName}`); - + // Update current flags this.accounts.forEach((acc, idx) => { acc.isCurrent = idx === this.currentIndex; }); - + return this.accounts[this.currentIndex]; } - + getCurrentAccount() { return this.accounts[this.currentIndex] || null; } - + getAccountByIndex(index) { return this.accounts[index] || null; } - + updateAccountData(tokenOrData, dataObject = null) { let accountData; let targetAccount; - + if (dataObject !== null) { // Called with (token, dataObject) format const token = tokenOrData; @@ -870,7 +880,7 @@ function getText(key, params) { accountData = tokenOrData; targetAccount = this.getCurrentAccount(); } - + if (targetAccount && accountData) { // Update all provided properties if (accountData.charges !== undefined || accountData.Charges !== undefined) { @@ -896,19 +906,19 @@ function getText(key, params) { if (accountData.cooldown !== undefined) { targetAccount.cooldown = accountData.cooldown; } - + console.log(`📊 [ACCOUNT MANAGER] Updated ${targetAccount.displayName}: ⚡${targetAccount.Charges}/${targetAccount.Max} 💧${targetAccount.Droplets}${targetAccount.isCurrent ? ' (CURRENT)' : ''}`); } } - + getAccountCount() { return this.accounts.length; } - + getAllAccounts() { return [...this.accounts]; // Return copy to prevent direct mutation } - + setCurrentIndex(index) { if (index >= 0 && index < this.accounts.length) { this.currentIndex = index; @@ -917,7 +927,7 @@ function getText(key, params) { console.warn(`⚠️ [ACCOUNT MANAGER] Invalid index ${index}, keeping current: ${this.currentIndex}`); } } - + getNextAccount() { if (this.accounts.length === 0) return null; const nextIndex = (this.currentIndex + 1) % this.accounts.length; @@ -955,6 +965,7 @@ function getText(key, params) { region: null, minimized: false, lastPosition: { x: 0, y: 0 }, + lastPaintedPosition: { x: 0, y: 0 }, // Track last successfully painted coordinate estimatedTime: 0, language: 'en', paintingSpeed: CONFIG.PAINTING_SPEED.DEFAULT, // pixels batch size @@ -967,7 +978,7 @@ function getText(key, params) { initialSetupComplete: false, // Track if initial startup setup is complete (only happens once) overlayOpacity: CONFIG.OVERLAY.OPACITY_DEFAULT, blueMarbleEnabled: CONFIG.OVERLAY.BLUE_MARBLE_DEFAULT, - ditheringEnabled: true, + ditheringEnabled: false, // Advanced color matching settings colorMatchingAlgorithm: 'lab', enableChromaPenalty: true, @@ -1376,25 +1387,25 @@ function getText(key, params) { console.log('🔍 [DEBUG] RestoreProgress: Starting restoration...'); console.log('🔍 [DEBUG] SavedData exists:', !!savedData); console.log('🔍 [DEBUG] SavedData.state exists:', !!savedData?.state); - + if (!savedData || !savedData.state) { console.error('❌ [DEBUG] RestoreProgress: Invalid savedData or missing state'); return false; } - + console.log('🔍 [DEBUG] Current window.state keys before restore:', Object.keys(window.state || {})); console.log('🔍 [DEBUG] SavedData.state keys:', Object.keys(savedData.state)); - + console.log('🔍 [DEBUG] Performing Object.assign...'); Object.assign(window.state, savedData.state); - + // Reset session-specific flags when loading a new save file window.state.preFilteringDone = false; window.state.progressResetDone = false; console.log('🔄 Reset session flags for new save file load'); - + console.log('✅ [DEBUG] Object.assign completed successfully'); - + // Restore available colors from old save files (backward compatibility) if (savedData.state.availableColors && Array.isArray(savedData.state.availableColors)) { console.log('🔍 [DEBUG] Restoring availableColors, count:', savedData.state.availableColors.length); @@ -1409,7 +1420,7 @@ function getText(key, params) { console.log('🔍 [DEBUG] Restoring imageData...'); console.log('🔍 [DEBUG] ImageData type check - pixels is array:', Array.isArray(savedData.imageData.pixels)); console.log('🔍 [DEBUG] ImageData pixels length:', savedData.imageData.pixels?.length); - + window.state.imageData = { ...savedData.imageData, pixels: new Uint8ClampedArray(savedData.imageData.pixels), @@ -1427,7 +1438,7 @@ function getText(key, params) { } else { console.log('🔍 [DEBUG] No paintedMap found in savedData (this is normal for extracted data)'); } - + console.log('✅ [DEBUG] RestoreProgress completed successfully'); console.log('🔍 [DEBUG] Final window.state.imageLoaded:', window.state.imageLoaded); console.log('🔍 [DEBUG] Final window.state.totalPixels:', window.state.totalPixels); @@ -1490,44 +1501,44 @@ function getText(key, params) { try { console.log('🔍 [DEBUG] Starting file upload process...'); const data = await Utils.createFileUploader(); - + console.log('🔍 [DEBUG] File upload completed. Data type:', typeof data); console.log('🔍 [DEBUG] Data exists:', !!data); - + if (!data) { console.error('❌ [DEBUG] No data received from file uploader'); throw new Error('No data received from file'); } - + console.log('🔍 [DEBUG] Data keys:', Object.keys(data)); console.log('🔍 [DEBUG] Data.state exists:', !!data.state); console.log('🔍 [DEBUG] Data.imageData exists:', !!data.imageData); console.log('🔍 [DEBUG] Data.version:', data.version); console.log('🔍 [DEBUG] Data.timestamp:', data.timestamp); - + if (!data.state) { console.error('❌ [DEBUG] Missing state object in loaded data'); console.log('🔍 [DEBUG] Available top-level keys:', Object.keys(data)); throw new Error('Invalid file format - missing state object'); } - + console.log('🔍 [DEBUG] State object keys:', Object.keys(data.state)); console.log('🔍 [DEBUG] State.imageLoaded:', data.state.imageLoaded); console.log('🔍 [DEBUG] State.totalPixels:', data.state.totalPixels); console.log('🔍 [DEBUG] State.startPosition:', data.state.startPosition); console.log('🔍 [DEBUG] State.region:', data.state.region); - + if (data.imageData) { console.log('🔍 [DEBUG] ImageData width:', data.imageData.width); console.log('🔍 [DEBUG] ImageData height:', data.imageData.height); console.log('🔍 [DEBUG] ImageData pixels length:', data.imageData.pixels?.length); console.log('🔍 [DEBUG] ImageData totalPixels:', data.imageData.totalPixels); } - + console.log('🔍 [DEBUG] Calling restoreProgress...'); const success = Utils.restoreProgress(data); console.log('🔍 [DEBUG] RestoreProgress result:', success); - + return success; } catch (error) { console.error('❌ [DEBUG] Error in loadProgressFromFile:', error); @@ -1540,22 +1551,22 @@ function getText(key, params) { try { console.log('🔍 [DEBUG] Starting Art-Extractor file upload process...'); const data = await Utils.createFileUploader(); - + console.log('🔍 [DEBUG] File upload completed. Data type:', typeof data); console.log('🔍 [DEBUG] Data exists:', !!data); console.log('📖 Raw loaded data:', data); - + if (!data) { console.error('❌ [DEBUG] No data received from file uploader'); return null; } - + console.log('🔍 [DEBUG] Data keys:', Object.keys(data)); console.log('🔍 [DEBUG] Data.state exists:', !!data.state); console.log('🔍 [DEBUG] Data.imageData exists:', !!data.imageData); console.log('🔍 [DEBUG] Data.version:', data.version); console.log('🔍 [DEBUG] Data.timestamp:', data.timestamp); - + console.log('🔍 [DEBUG] Returning raw data object for Load Extracted feature'); return data; } catch (error) { @@ -2425,6 +2436,19 @@ function getText(key, params) { +
+
+
+ + Auto Buy Charges +
+ +
+
+
@@ -2992,6 +3016,15 @@ function getText(key, params) { Height: 0px + + +
+ +
+