Skip to content

Commit 9b5530a

Browse files
committed
Proper fix for console type logic.
1 parent c394705 commit 9b5530a

9 files changed

+47
-21
lines changed

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void ConsoleTypeDetector_Home::make_overlays(VideoOverlaySet& items) const{
2828
}
2929
items.add(m_color, m_bottom_line);
3030
}
31-
ConsoleType ConsoleTypeDetector_Home::detect(const ImageViewRGB32& screen){
31+
ConsoleType ConsoleTypeDetector_Home::detect_only(const ImageViewRGB32& screen){
3232
if (m_console.state().console_type_confirmed()){
3333
return m_console.state().console_type();
3434
}
@@ -41,10 +41,12 @@ ConsoleType ConsoleTypeDetector_Home::detect(const ImageViewRGB32& screen){
4141
}else{
4242
state = ConsoleType::Switch1;
4343
}
44-
45-
m_console.state().set_console_type(m_console, state);
44+
m_last = state;
4645
return state;
4746
}
47+
void ConsoleTypeDetector_Home::commit_to_cache(){
48+
m_console.state().set_console_type(m_console, m_last);
49+
}
4850

4951

5052

@@ -56,7 +58,7 @@ ConsoleTypeDetector_StartGameUserSelect::ConsoleTypeDetector_StartGameUserSelect
5658
void ConsoleTypeDetector_StartGameUserSelect::make_overlays(VideoOverlaySet& items) const{
5759
items.add(m_color, m_bottom_line);
5860
}
59-
ConsoleType ConsoleTypeDetector_StartGameUserSelect::detect(const ImageViewRGB32& screen){
61+
ConsoleType ConsoleTypeDetector_StartGameUserSelect::detect_only(const ImageViewRGB32& screen){
6062
if (m_console.state().console_type_confirmed()){
6163
return m_console.state().console_type();
6264
}
@@ -69,9 +71,12 @@ ConsoleType ConsoleTypeDetector_StartGameUserSelect::detect(const ImageViewRGB32
6971
}else{
7072
state = ConsoleType::Switch1;
7173
}
72-
74+
m_last = state;
7375
return state;
7476
}
77+
void ConsoleTypeDetector_StartGameUserSelect::commit_to_cache(){
78+
m_console.state().set_console_type(m_console, m_last);
79+
}
7580

7681

7782

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@ class ConsoleTypeDetector_Home{
2424
ConsoleTypeDetector_Home(ConsoleHandle& console, Color color = COLOR_RED);
2525

2626
void make_overlays(VideoOverlaySet& items) const;
27-
ConsoleType detect(const ImageViewRGB32& screen);
27+
ConsoleType detect_only(const ImageViewRGB32& screen);
28+
void commit_to_cache();
2829

2930
private:
3031
ConsoleHandle& m_console;
3132
Color m_color;
3233
ImageFloatBox m_bottom_line;
34+
ConsoleType m_last;
3335
};
3436

3537
class ConsoleTypeDetector_StartGameUserSelect{
3638
public:
3739
ConsoleTypeDetector_StartGameUserSelect(ConsoleHandle& console, Color color = COLOR_RED);
3840

3941
void make_overlays(VideoOverlaySet& items) const;
40-
ConsoleType detect(const ImageViewRGB32& screen);
42+
ConsoleType detect_only(const ImageViewRGB32& screen);
43+
void commit_to_cache();
4144

4245
private:
4346
ConsoleHandle& m_console;
4447
Color m_color;
4548
ImageFloatBox m_bottom_line;
49+
ConsoleType m_last;
4650
};
4751

4852

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ void HomeMenuDetector::make_overlays(VideoOverlaySet& items) const{
3838
// This miraculously works on both Switch 1 and Switch 2.
3939
//
4040
bool HomeMenuDetector::detect(const ImageViewRGB32& screen){
41+
if (detect_only(screen)){
42+
m_console_type.commit_to_cache();
43+
return true;
44+
}else{
45+
return false;
46+
}
47+
}
48+
bool HomeMenuDetector::detect_only(const ImageViewRGB32& screen){
4149
ImageStats stats_bottom_row = image_stats(extract_box_reference(screen, m_bottom_row));
4250
// cout << stats_bottom_row.average << stats_bottom_row.stddev << endl;
4351
bool white;
@@ -102,7 +110,7 @@ bool HomeMenuDetector::detect(const ImageViewRGB32& screen){
102110
}
103111

104112
// Read the console type only when we have confirmed the home menu.
105-
m_console_type.detect(screen);
113+
m_console_type.detect_only(screen);
106114

107115
return true;
108116
}

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "CommonFramework/ImageTools/ImageBoxes.h"
1212
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
1313
#include "CommonTools/VisualDetector.h"
14-
#include "NintendoSwitch/NintendoSwitch_ConsoleState.h"
1514
#include "NintendoSwitch_ConsoleTypeDetector.h"
1615

1716
namespace PokemonAutomation{
@@ -25,6 +24,7 @@ class HomeMenuDetector : public StaticScreenDetector{
2524

2625
virtual void make_overlays(VideoOverlaySet& items) const override;
2726
virtual bool detect(const ImageViewRGB32& screen) override;
27+
bool detect_only(const ImageViewRGB32& screen);
2828

2929
private:
3030
Color m_color;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ void StartGameUserSelectDetector::make_overlays(VideoOverlaySet& items) const{
3030
m_switch1.make_overlays(items);
3131
m_switch2.make_overlays(items);
3232
}
33+
bool StartGameUserSelectDetector::detect(const ImageViewRGB32& screen){
34+
if (detect_only(screen)){
35+
m_console.state().set_console_type(m_console, m_console_type);
36+
return true;
37+
}else{
38+
return false;
39+
}
40+
}
3341
bool StartGameUserSelectDetector::detect_only(const ImageViewRGB32& screen){
34-
ConsoleType type = m_type_detector.detect(screen);
42+
ConsoleType type = m_type_detector.detect_only(screen);
3543
// cout << "detection: " << (int)x << endl;
3644
m_console_type = type;
3745

@@ -50,14 +58,6 @@ bool StartGameUserSelectDetector::detect_only(const ImageViewRGB32& screen){
5058
"Invalid ConsoleType: " + std::to_string((int)type)
5159
);
5260
}
53-
bool StartGameUserSelectDetector::detect(const ImageViewRGB32& screen){
54-
if (detect_only(screen)){
55-
m_console.state().set_console_type(m_console, m_console_type);
56-
return true;
57-
}else{
58-
return false;
59-
}
60-
}
6161

6262

6363

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class StartGameUserSelectDetector : public StaticScreenDetector{
5959
StartGameUserSelectDetector(ConsoleHandle& console, Color color = COLOR_RED);
6060

6161
virtual void make_overlays(VideoOverlaySet& items) const override;
62-
bool detect_only(const ImageViewRGB32& screen);
6362
virtual bool detect(const ImageViewRGB32& screen) override;
63+
bool detect_only(const ImageViewRGB32& screen);
6464

6565
private:
6666
ConsoleHandle& m_console;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ void UpdatePopupDetector::make_overlays(VideoOverlaySet& items) const{
2929
m_switch2.make_overlays(items);
3030
}
3131
bool UpdatePopupDetector::detect(const ImageViewRGB32& screen){
32-
ConsoleType type = m_type_detector.detect(screen);
32+
if (detect_only(screen)){
33+
m_type_detector.commit_to_cache();
34+
return true;
35+
}else{
36+
return false;
37+
}
38+
}
39+
bool UpdatePopupDetector::detect_only(const ImageViewRGB32& screen){
40+
ConsoleType type = m_type_detector.detect_only(screen);
3341

3442
if (type == ConsoleType::Unknown){
3543
return false;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class UpdatePopupDetector : public StaticScreenDetector{
6262

6363
virtual void make_overlays(VideoOverlaySet& items) const override;
6464
virtual bool detect(const ImageViewRGB32& screen) override;
65+
bool detect_only(const ImageViewRGB32& screen);
6566

6667
private:
6768
ConsoleTypeDetector_Home m_type_detector;

SerialPrograms/Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_HomeToDateTime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ bool home_to_date_time_with_feedback(ConsoleHandle& console, ProControllerContex
476476
}
477477

478478
ConsoleTypeDetector_Home detector(console);
479-
ConsoleType console_type = detector.detect(console.video().snapshot());
479+
ConsoleType console_type = detector.detect_only(console.video().snapshot());
480480
switch (console_type){
481481
case ConsoleType::Switch1:
482482
return home_to_date_time_switch1_feedback(console, context, to_date_change);

0 commit comments

Comments
 (0)