feat: updated collector
This commit is contained in:
35
extension/modules/ui/components/settings.js
Normal file
35
extension/modules/ui/components/settings.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Styles, createElement } from '../ui_styles.js';
|
||||
|
||||
export const Settings = {
|
||||
init(container) {
|
||||
const section = createElement('div', Styles.section);
|
||||
section.innerHTML = `<h4 style="${Styles.header}">⚙️ Settings</h4>`;
|
||||
|
||||
const content = createElement('div', Styles.content);
|
||||
|
||||
// Debug Toggle
|
||||
const debugRow = createElement('div', Styles.row);
|
||||
const debugLabel = createElement('span', '', {}, 'Debug Mode');
|
||||
const debugToggle = createElement('input', '', { type: 'checkbox' });
|
||||
|
||||
// Sync with state
|
||||
if (window.MagicBot && window.MagicBot.settings) {
|
||||
debugToggle.checked = window.MagicBot.settings.debug;
|
||||
}
|
||||
|
||||
debugToggle.onchange = (e) => {
|
||||
if (window.MagicBot) {
|
||||
if (!window.MagicBot.settings) window.MagicBot.settings = {};
|
||||
window.MagicBot.settings.debug = e.target.checked;
|
||||
console.log(`[MagicBot] Debug Mode: ${e.target.checked ? 'ON' : 'OFF'}`);
|
||||
}
|
||||
};
|
||||
|
||||
debugRow.appendChild(debugLabel);
|
||||
debugRow.appendChild(debugToggle);
|
||||
content.appendChild(debugRow);
|
||||
|
||||
section.appendChild(content);
|
||||
container.appendChild(section);
|
||||
}
|
||||
};
|
||||
@@ -30,8 +30,8 @@ export const ModelOverlay = {
|
||||
}
|
||||
|
||||
const MB = window.MagicBot;
|
||||
if (!MB || !MB.state || !MB.state.inventory) {
|
||||
container.innerHTML = '<div style="color:red">No State Data</div>';
|
||||
if (!MB || !MB.state || !MB.state.garden || !MB.state.garden.tileObjects) {
|
||||
container.innerHTML = '<div style="color:red">No Garden Data</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,55 +40,68 @@ export const ModelOverlay = {
|
||||
|
||||
// Header Info
|
||||
const header = createElement('div', 'padding: 5px; background: rgba(0,0,0,0.2); margin-bottom: 5px; border-radius: 4px;');
|
||||
const rainProb = MB.weatherTracker ? (MB.weatherTracker.probabilities.rain * 100).toFixed(0) : '?';
|
||||
const frostProb = MB.weatherTracker ? (MB.weatherTracker.probabilities.frost * 100).toFixed(0) : '?';
|
||||
const probs = MB.automation && MB.automation.weatherTracker ? MB.automation.weatherTracker.probabilities : null;
|
||||
|
||||
const rainProb = probs ? (probs.P_Next_Rain_Thunderstorm * 100).toFixed(0) : '?';
|
||||
const frostProb = probs ? (probs.P_Next_Frost * 100).toFixed(0) : '?';
|
||||
const nextEventHrs = probs ? probs.Time_Until_Next_Event_Hrs.toFixed(2) : '?';
|
||||
|
||||
const tracker = MB.automation ? MB.automation.weatherTracker : null;
|
||||
const currentEvent = tracker ? tracker.currentEvent : 'None';
|
||||
|
||||
header.innerHTML = `
|
||||
<div><b>Weather Probabilities:</b> Rain: ${rainProb}% | Frost: ${frostProb}%</div>
|
||||
<div><b>Weather:</b> ${currentEvent || 'Clear'}</div>
|
||||
<div><b>Next Event:</b> ${nextEventHrs} hrs (Rain: ${rainProb}%, Frost: ${frostProb}%)</div>
|
||||
<div><b>Smart Harvest:</b> ${MB.automation && MB.automation.smartHarvest ? '<span style="color:#bada55">ON</span>' : '<span style="color:#ff5252">OFF</span>'}</div>
|
||||
`;
|
||||
list.appendChild(header);
|
||||
|
||||
const plots = MB.state.inventory.items.filter(i => i.itemType === 'Plot');
|
||||
if (plots.length === 0) {
|
||||
container.innerHTML += '<div style="padding:10px">No Plots Found</div>';
|
||||
const garden = MB.state.garden;
|
||||
const tiles = garden ? garden.tileObjects : {};
|
||||
const activeCrops = [];
|
||||
|
||||
if (tiles) {
|
||||
Object.keys(tiles).forEach(key => {
|
||||
|
||||
const tile = tiles[key];
|
||||
if (tile.slots) {
|
||||
tile.slots.forEach((slot, idx) => {
|
||||
activeCrops.push({
|
||||
id: key,
|
||||
idx: idx,
|
||||
name: slot.species || tile.species || 'Unknown',
|
||||
endTime: slot.endTime,
|
||||
startTime: slot.startTime,
|
||||
mutations: slot.mutations || []
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (activeCrops.length === 0) {
|
||||
container.innerHTML += '<div style="padding:10px">No Active Crops Found</div>';
|
||||
container.appendChild(list);
|
||||
return;
|
||||
}
|
||||
|
||||
plots.forEach(plot => {
|
||||
if (!plot.properties) return;
|
||||
const crop = plot.properties.crop;
|
||||
if (!crop) return; // Empty plot
|
||||
|
||||
// Limit to first 50 to prevent lag if huge farm
|
||||
activeCrops.slice(0, 50).forEach(crop => {
|
||||
const row = createElement('div', 'background: rgba(255,255,255,0.05); padding: 5px; border-radius: 4px; display: flex; flex-direction: column; gap: 2px;');
|
||||
|
||||
// Basic Crop Info
|
||||
const name = crop.name;
|
||||
const stage = crop.stage;
|
||||
const totalStages = crop.stages;
|
||||
const isReady = stage >= totalStages;
|
||||
|
||||
// Value Calculation (Simple approximation if actual vals not available)
|
||||
const sellPrice = crop.sellPrice || 0;
|
||||
const currentVal = isReady ? sellPrice : 0;
|
||||
|
||||
// Decision Logic Inspection
|
||||
// We can't easily "spy" on the exact decision function result without modifying it to store state,
|
||||
// but we can replicate the visual indicators.
|
||||
const now = Date.now();
|
||||
const isReady = now >= crop.endTime;
|
||||
const timeLeft = Math.max(0, (crop.endTime - now) / 60000).toFixed(1); // Minutes
|
||||
|
||||
let statusColor = '#aaa';
|
||||
let statusText = 'Growing';
|
||||
let statusText = `${timeLeft} min`;
|
||||
|
||||
if (isReady) {
|
||||
// Check mutation potential
|
||||
const nextWeather = MB.weatherTracker ? MB.weatherTracker.nextEvent : 'Unknown';
|
||||
const hasMutation = crop.mutations && crop.mutations.length > 0;
|
||||
|
||||
if (hasMutation) {
|
||||
statusText = 'Ready (Mutated!)';
|
||||
statusColor = '#bada55'; // Green
|
||||
statusText = `Ready (${crop.mutations.join(', ')})`;
|
||||
statusColor = '#bada55';
|
||||
} else {
|
||||
// This is where we'd ideally show the "Wait vs Harvest" logic
|
||||
// For now, let's show the current value and a theoretical max if waiting
|
||||
statusText = 'Ready';
|
||||
statusColor = '#fff';
|
||||
}
|
||||
@@ -96,18 +109,9 @@ export const ModelOverlay = {
|
||||
|
||||
row.innerHTML = `
|
||||
<div style="font-weight:bold; display:flex; justify-content:space-between;">
|
||||
<span style="color:${Styles.colors.primary}">${name}</span>
|
||||
<span style="color:${Styles.colors.primary}">${crop.name} <span style="font-size:9px; color:#555">#${crop.id}</span></span>
|
||||
<span style="color:${statusColor}">${statusText}</span>
|
||||
</div>
|
||||
<div style="display:flex; justify-content:space-between; color:#888;">
|
||||
<span>Stage: ${stage}/${totalStages}</span>
|
||||
<span>Value: ${currentVal}</span>
|
||||
</div>
|
||||
<!--
|
||||
<div style="font-size:9px; color:#666;">
|
||||
EV: ??? | Boundary: ???
|
||||
</div>
|
||||
-->
|
||||
`;
|
||||
list.appendChild(row);
|
||||
});
|
||||
|
||||
@@ -83,4 +83,4 @@ export const PetsOverlay = {
|
||||
container.appendChild(list);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import { Teleport } from './components/teleport.js';
|
||||
import { Automation } from './components/automation.js';
|
||||
import { Harvest } from './components/harvest.js';
|
||||
import { Diet } from './components/diet.js';
|
||||
|
||||
import { Settings } from './components/settings.js';
|
||||
import { Visualizers } from './components/visualizers.js';
|
||||
|
||||
import { GardenOverlay } from './overlays/garden.js';
|
||||
@@ -62,6 +64,8 @@ import { ModelOverlay } from './overlays/model_overlay.js'; // Added
|
||||
try { Automation.init(content); } catch (e) { console.error('Automation Init Failed', e); }
|
||||
try { Harvest.init(content); } catch (e) { console.error('Harvest Init Failed', e); }
|
||||
try { Diet.init(content); } catch (e) { console.error('Diet Init Failed', e); }
|
||||
try { Diet.init(content); } catch (e) { console.error('Diet Init Failed', e); }
|
||||
try { Settings.init(content); } catch (e) { console.error('Settings Init Failed', e); }
|
||||
try { Visualizers.init(content); } catch (e) { console.error('Visualizers Init Failed', e); }
|
||||
|
||||
this.sidebar.appendChild(content);
|
||||
|
||||
Reference in New Issue
Block a user