Fix dashboard + vision: region checkboxes, upload auto-switch, state detection, analyze endpoint
- Region checkboxes now control which overlays are drawn (?regions= param) - Upload auto-switches capture source (no restart needed) - State detection: check in-game BEFORE loading, require 90% dark for loading - Tighten HSV ranges: health H 0-30 S 50+ V 30+, mana H 200-240 S 40+ V 20+ - Add /api/analyze endpoint with per-region color analysis
This commit is contained in:
parent
67f2e5536a
commit
a665253d4d
5 changed files with 277 additions and 47 deletions
|
|
@ -27,12 +27,19 @@ func NewDetector(config Config, services plugin.EngineServices) *Detector {
|
|||
// DetectState analyzes a screenshot and returns the current game state.
|
||||
func (d *Detector) DetectState(frame image.Image) plugin.GameState {
|
||||
// Priority-based detection:
|
||||
// 1. Check for loading screen
|
||||
// 2. Check for main menu
|
||||
// 3. Check for character select
|
||||
// 4. Check for in-game (health orb visible)
|
||||
// 1. Check for in-game first (health orb visible)
|
||||
// 2. Check for loading screen (but only if not in-game)
|
||||
// 3. Check for main menu
|
||||
// 4. Check for character select
|
||||
// 5. Check for death screen
|
||||
|
||||
if d.isInGame(frame) {
|
||||
vitals := d.ReadVitals(frame)
|
||||
if vitals.HealthPct <= 0.01 { // Consider very low health as dead
|
||||
return plugin.StateDead
|
||||
}
|
||||
return plugin.StateInGame
|
||||
}
|
||||
if d.isLoading(frame) {
|
||||
return plugin.StateLoading
|
||||
}
|
||||
|
|
@ -42,13 +49,6 @@ func (d *Detector) DetectState(frame image.Image) plugin.GameState {
|
|||
if d.isCharacterSelect(frame) {
|
||||
return plugin.StateCharacterSelect
|
||||
}
|
||||
if d.isInGame(frame) {
|
||||
vitals := d.ReadVitals(frame)
|
||||
if vitals.HealthPct <= 0.01 { // Consider very low health as dead
|
||||
return plugin.StateDead
|
||||
}
|
||||
return plugin.StateInGame
|
||||
}
|
||||
return plugin.StateUnknown
|
||||
}
|
||||
|
||||
|
|
@ -98,12 +98,12 @@ func (d *Detector) IsInGame(frame image.Image) bool {
|
|||
}
|
||||
|
||||
func (d *Detector) isLoading(frame image.Image) bool {
|
||||
// Check for loading screen by looking for mostly black screen
|
||||
// This is a simple heuristic - could be improved
|
||||
// Check for loading screen by looking for mostly black screen (>90%)
|
||||
// AND ensuring no health orb colors are present in the health orb region
|
||||
bounds := frame.Bounds()
|
||||
totalPixels := 0
|
||||
darkPixels := 0
|
||||
|
||||
|
||||
// Sample every 10 pixels for performance
|
||||
step := 10
|
||||
for y := bounds.Min.Y; y < bounds.Max.Y; y += step {
|
||||
|
|
@ -112,7 +112,7 @@ func (d *Detector) isLoading(frame image.Image) bool {
|
|||
r, g, b, _ := c.RGBA()
|
||||
// Convert to 8-bit
|
||||
r, g, b = r>>8, g>>8, b>>8
|
||||
|
||||
|
||||
totalPixels++
|
||||
// Consider pixel dark if all channels are below 30
|
||||
if r < 30 && g < 30 && b < 30 {
|
||||
|
|
@ -120,13 +120,35 @@ func (d *Detector) isLoading(frame image.Image) bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if totalPixels == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// If more than 70% of screen is dark, likely loading
|
||||
return float64(darkPixels)/float64(totalPixels) > 0.7
|
||||
|
||||
// Require more than 90% dark screen
|
||||
darkPercentage := float64(darkPixels) / float64(totalPixels)
|
||||
if darkPercentage <= 0.9 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Additional check: ensure no health colors in health orb region
|
||||
healthRegion := d.services.Region("health_orb")
|
||||
if !healthRegion.Empty() {
|
||||
healthColor := vision.ColorRange{
|
||||
LowerH: d.config.Colors.HealthFilled.LowerH,
|
||||
UpperH: d.config.Colors.HealthFilled.UpperH,
|
||||
LowerS: d.config.Colors.HealthFilled.LowerS,
|
||||
UpperS: d.config.Colors.HealthFilled.UpperS,
|
||||
LowerV: d.config.Colors.HealthFilled.LowerV,
|
||||
UpperV: d.config.Colors.HealthFilled.UpperV,
|
||||
}
|
||||
// If health colors are detected in health orb region, it's not loading
|
||||
if d.vision.HasColorInRegion(frame, healthRegion, healthColor) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *Detector) isMainMenu(frame image.Image) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue