Skip to content

Commit 44b41dc

Browse files
committed
Move the rest of the date manip stuff into the right places.
1 parent bf9f98c commit 44b41dc

File tree

11 files changed

+613
-577
lines changed

11 files changed

+613
-577
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,8 @@ file(GLOB MAIN_SOURCES
955955
Source/NintendoSwitch/Framework/UI/NintendoSwitch_SwitchSystemWidget.h
956956
Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.cpp
957957
Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h
958-
Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp
959-
Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h
958+
Source/NintendoSwitch/Inference/NintendoSwitch_DateChangeDetector.cpp
959+
Source/NintendoSwitch/Inference/NintendoSwitch_DateChangeDetector.h
960960
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.cpp
961961
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.h
962962
Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.cpp
@@ -990,6 +990,8 @@ file(GLOB MAIN_SOURCES
990990
Source/NintendoSwitch/Options/TurboMacroTable.h
991991
Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.cpp
992992
Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h
993+
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.cpp
994+
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.h
993995
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip_24h.cpp
994996
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip_24h.h
995997
Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip_US.cpp

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
4747
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
4848
#include "NintendoSwitch/NintendoSwitch_Settings.h"
49-
#include "NintendoSwitch/Inference/NintendoSwitch_DateReader.h"
49+
#include "NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.h"
5050
#include "NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.h"
5151
#include "PokemonSV/PokemonSV_Settings.h"
5252
#include "PokemonLA/Programs/PokemonLA_GameEntry.h"
@@ -99,7 +99,6 @@
9999
#include "PokemonSwSh/Inference/PokemonSwSh_ReceivePokemonDetector.h"
100100
#include "PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h"
101101
#include "PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.h"
102-
#include "NintendoSwitch/Inference/NintendoSwitch_DateReader.h"
103102
#include "PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterPrizeReader.h"
104103
#include "PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterJobsDetector.h"
105104
#include "PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.h"
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/* Date Change Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/ImageTools/ImageStats.h"
8+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
9+
#include "NintendoSwitch_DateChangeDetector.h"
10+
11+
namespace PokemonAutomation{
12+
namespace NintendoSwitch{
13+
14+
15+
16+
17+
DateChangeDetector_Switch1::DateChangeDetector_Switch1(Color color)
18+
: m_color(color)
19+
, m_background_top(0.50, 0.02, 0.45, 0.08)
20+
, m_window_top(0.50, 0.36, 0.45, 0.07)
21+
, m_window_text(0.05, 0.36, 0.10, 0.07)
22+
, m_jp_year(0.136, 0.61, 0.11, 0.09)
23+
, m_us_hour(0.473, 0.61, 0.06, 0.09)
24+
, m_jp_month_arrow(0.30, 0.50, 0.05, 0.06)
25+
{}
26+
void DateChangeDetector_Switch1::make_overlays(VideoOverlaySet& items) const{
27+
items.add(m_color, m_background_top);
28+
items.add(m_color, m_window_top);
29+
items.add(m_color, m_window_text);
30+
items.add(m_color, m_jp_year);
31+
items.add(m_color, m_us_hour);
32+
items.add(m_color, m_jp_month_arrow);
33+
}
34+
bool DateChangeDetector_Switch1::detect(const ImageViewRGB32& screen){
35+
ImageStats stats_background_top = image_stats(extract_box_reference(screen, m_background_top));
36+
if (stats_background_top.stddev.sum() > 10){
37+
// cout << "asdf" << endl;
38+
return false;
39+
}
40+
ImageStats stats_window_top = image_stats(extract_box_reference(screen, m_window_top));
41+
// cout << stats_window_top.average << stats_window_top.stddev << endl;
42+
if (stats_window_top.stddev.sum() > 10){
43+
// cout << "qwer" << endl;
44+
return false;
45+
}
46+
ImageStats stats_window_text = image_stats(extract_box_reference(screen, m_window_text));
47+
// cout << stats_window_text.stddev << endl;
48+
if (stats_window_text.stddev.sum() < 100){
49+
// cout << "zxcv" << endl;
50+
return false;
51+
}
52+
// cout << "stats_background_top: " << stats_background_top.average.sum() << endl;
53+
// cout << "stats_window_top: " << stats_window_top.average.sum() << endl;
54+
if (std::abs(stats_background_top.average.sum() - stats_window_top.average.sum()) < 50){
55+
// cout << "xcvb" << endl;
56+
return false;
57+
}
58+
59+
// bool white_theme = stats_window_top.average.sum() > 600;
60+
61+
ImageViewRGB32 year_box = extract_box_reference(screen, m_jp_year);
62+
ImageStats year_stats = image_stats(year_box);
63+
// cout << year_stats.average << year_stats.stddev << endl;
64+
65+
double stddev = year_stats.stddev.sum();
66+
if (stddev < 80){
67+
// cout << "sdfg" << endl;
68+
return false;
69+
}
70+
71+
return true;
72+
}
73+
DateFormat DateChangeDetector_Switch1::detect_date_format(const ImageViewRGB32& screen) const{
74+
ImageViewRGB32 us_hours = extract_box_reference(screen, m_us_hour);
75+
ImageStats stats_us_hours = image_stats(us_hours);
76+
77+
if (stats_us_hours.stddev.sum() > 30){
78+
return DateFormat::US;
79+
}
80+
81+
ImageViewRGB32 jp_arrow = extract_box_reference(screen, m_jp_month_arrow);
82+
ImageStats stats_arrow = image_stats(jp_arrow);
83+
if (stats_arrow.stddev.sum() > 30){
84+
return DateFormat::JP;
85+
}
86+
87+
return DateFormat::EU;
88+
}
89+
90+
91+
92+
DateChangeDetector_Switch2::DateChangeDetector_Switch2(Color color)
93+
: m_color(color)
94+
, m_background_top(0.50, 0.02, 0.45, 0.08)
95+
, m_window_bottom(0.50, 0.80, 0.45, 0.07)
96+
, m_window_text(0.05, 0.02, 0.10, 0.08)
97+
, m_jp_year(0.139, 0.436, 0.088, 0.095)
98+
, m_us_hour(0.473, 0.61, 0.06, 0.09)
99+
, m_jp_month_arrow(0.291705, 0.331675, 0.054986, 0.069652)
100+
{}
101+
void DateChangeDetector_Switch2::make_overlays(VideoOverlaySet& items) const{
102+
items.add(m_color, m_background_top);
103+
items.add(m_color, m_window_bottom);
104+
items.add(m_color, m_window_text);
105+
items.add(m_color, m_jp_year);
106+
items.add(m_color, m_us_hour);
107+
items.add(m_color, m_jp_month_arrow);
108+
}
109+
bool DateChangeDetector_Switch2::detect(const ImageViewRGB32& screen){
110+
ImageStats stats_background_top = image_stats(extract_box_reference(screen, m_background_top));
111+
if (stats_background_top.stddev.sum() > 10){
112+
// cout << "asdf" << endl;
113+
return false;
114+
}
115+
ImageStats stats_window_bottom = image_stats(extract_box_reference(screen, m_window_bottom));
116+
// cout << stats_window_bottom.average << stats_window_top.stddev << endl;
117+
if (stats_window_bottom.stddev.sum() > 10){
118+
// cout << "qwer" << endl;
119+
return false;
120+
}
121+
ImageStats stats_window_text = image_stats(extract_box_reference(screen, m_window_text));
122+
// cout << stats_window_text.stddev << endl;
123+
if (stats_window_text.stddev.sum() < 100){
124+
// cout << "zxcv" << endl;
125+
return false;
126+
}
127+
// cout << "stats_background_top: " << stats_background_top.average.sum() << endl;
128+
// cout << "stats_window_top: " << stats_window_top.average.sum() << endl;
129+
130+
if (euclidean_distance(stats_background_top.average, stats_window_bottom.average) > 10){
131+
// cout << "xcvb" << endl;
132+
return false;
133+
}
134+
135+
// bool white_theme = stats_window_top.average.sum() > 600;
136+
137+
ImageViewRGB32 year_box = extract_box_reference(screen, m_jp_year);
138+
ImageStats year_stats = image_stats(year_box);
139+
// cout << year_stats.average << year_stats.stddev << endl;
140+
141+
double stddev = year_stats.stddev.sum();
142+
if (stddev < 80){
143+
// cout << "sdfg" << endl;
144+
return false;
145+
}
146+
147+
return true;
148+
}
149+
DateFormat DateChangeDetector_Switch2::detect_date_format(const ImageViewRGB32& screen) const{
150+
ImageViewRGB32 us_hours = extract_box_reference(screen, m_us_hour);
151+
ImageStats stats_us_hours = image_stats(us_hours);
152+
153+
if (stats_us_hours.stddev.sum() > 30){
154+
return DateFormat::US;
155+
}
156+
157+
ImageViewRGB32 jp_arrow = extract_box_reference(screen, m_jp_month_arrow);
158+
ImageStats stats_arrow = image_stats(jp_arrow);
159+
if (stats_arrow.stddev.sum() > 30){
160+
return DateFormat::JP;
161+
}
162+
163+
return DateFormat::EU;
164+
}
165+
166+
167+
168+
169+
170+
171+
172+
}
173+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* Date Change Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_NintendoSwitch_DateChangeDetector_H
8+
#define PokemonAutomation_NintendoSwitch_DateChangeDetector_H
9+
10+
#include "Common/Cpp/Color.h"
11+
#include "CommonFramework/ImageTools/ImageBoxes.h"
12+
#include "CommonTools/VisualDetector.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
17+
18+
enum class DateFormat{
19+
US,
20+
EU,
21+
JP,
22+
};
23+
24+
25+
26+
27+
class DateChangeDetector : public StaticScreenDetector{
28+
public:
29+
virtual DateFormat detect_date_format(const ImageViewRGB32& screen) const = 0;
30+
};
31+
class DateChangeDetector_Switch1 : public DateChangeDetector{
32+
public:
33+
DateChangeDetector_Switch1(Color color);
34+
35+
virtual void make_overlays(VideoOverlaySet& items) const override;
36+
virtual bool detect(const ImageViewRGB32& screen) override;
37+
virtual DateFormat detect_date_format(const ImageViewRGB32& screen) const override;
38+
39+
private:
40+
Color m_color;
41+
ImageFloatBox m_background_top;
42+
ImageFloatBox m_window_top;
43+
ImageFloatBox m_window_text;
44+
ImageFloatBox m_jp_year;
45+
ImageFloatBox m_us_hour;
46+
ImageFloatBox m_jp_month_arrow;
47+
};
48+
class DateChangeDetector_Switch2 : public DateChangeDetector{
49+
public:
50+
DateChangeDetector_Switch2(Color color);
51+
52+
virtual void make_overlays(VideoOverlaySet& items) const override;
53+
virtual bool detect(const ImageViewRGB32& screen) override;
54+
virtual DateFormat detect_date_format(const ImageViewRGB32& screen) const override;
55+
56+
private:
57+
Color m_color;
58+
ImageFloatBox m_background_top;
59+
ImageFloatBox m_window_bottom;
60+
ImageFloatBox m_window_text;
61+
ImageFloatBox m_jp_year;
62+
ImageFloatBox m_us_hour;
63+
ImageFloatBox m_jp_month_arrow;
64+
};
65+
66+
67+
68+
69+
}
70+
}
71+
#endif

0 commit comments

Comments
 (0)