File tree Expand file tree Collapse file tree 7 files changed +36
-13
lines changed
Expand file tree Collapse file tree 7 files changed +36
-13
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,9 @@ Glubfub!
9999The chicken is ready!
100100Rock Lobster!
101101Gimmie! Gimmie! Gimmie!
102+ :3
103+ YIPPEE!!!!
104+ paws at you
102105
103106.DATERANGE 12-15 12-26
104107Ho! Ho! Ho!
Original file line number Diff line number Diff line change 11#include " DateRange.hpp"
22
3+ // Very strict algorithm at the moment, must be formatted as "MM-DD MM-DD"
4+ // Leading 0 not required for single digit months
35geode::Result<> DateRange::parse (const std::string& str, size_t start)
46{
7+ int sM , sD , eM, eD;
8+ char delimiter;
59 std::istringstream istrs (str.substr (start));
6- if (!(std::chrono::from_stream (istrs, " %m-%d" , m_Start) &&
7- istrs >> std::ws &&
8- std::chrono::from_stream (istrs, " %m-%d" , m_End)))
9- {
10- return geode::Err (" Failed to parse DateRange" );
11- }
10+ istrs >> sM >> delimiter >> sD >> std::ws >> eM >> delimiter >> eD;
11+ if (delimiter != ' -' )
12+ return geode::Err (" Error parsing date format! Improper delimiter!" );
13+ if (istrs.fail ())
14+ return geode::Err (" Stringstream failed!" );
15+
16+ m_Start =
17+ std::chrono::month_day (std::chrono::month (sM ), std::chrono::day (sD ));
18+ m_End =
19+ std::chrono::month_day (std::chrono::month (eM), std::chrono::day (eD));
20+
21+ if (!m_Start.ok ())
22+ return geode::Err (" Start not OK! (Incorrect date format?)" );
23+ if (!m_End.ok ())
24+ return geode::Err (" End not OK! (Incorrect date format?)" );
1225
13- if (istrs.fail ()) return geode::Err (" Stringstream failed!" );
14- if (!m_Start.ok ()) return geode::Err (" Start not OK!" );
15- if (!m_End.ok ()) return geode::Err (" End not OK!" );
1626 return geode::Ok ();
1727}
1828
Original file line number Diff line number Diff line change @@ -6,8 +6,12 @@ class DateRange
66 std::chrono::month_day m_Start;
77 std::chrono::month_day m_End;
88public:
9+ // *MUST* be formatted "MM-DD MM-DD" no leading 0 required.
910 geode::Result<> parse (const std::string& str, size_t start = 0 );
11+ // Returns true if supplied date is within this date range.
1012 bool inRange (const std::chrono::year_month_day& currentDate) const ;
13+ // Returns starting date.
1114 inline const std::chrono::month_day& getStart () const { return m_Start; }
15+ // Returns ending date.
1216 inline const std::chrono::month_day& getEnd () const { return m_End; }
1317};
Original file line number Diff line number Diff line change @@ -46,8 +46,7 @@ class $modify(ST_MenuLayer, MenuLayer)
4646 float scaleSpeed = Mod::get ()->getSettingValue <float >(" scaling-speed" );
4747 m_fields->m_SplashText = ScalingLabel::create (m_fields->m_SplashStr .c_str (), " goldFont.fnt" , scaleSpeed);
4848
49- // The scale here is an inverse scaling function for text used pretty often for UI.
50- m_fields->m_SplashText ->setScale (0 .5f / (1 .0f + 0 .05f * strlen (m_fields->m_SplashText ->getLabel ()->getString ())));
49+ m_fields->m_SplashText ->resetLabelScale ();
5150 m_fields->m_SplashText ->setPosition (
5251 // The magic numbers are the percentage offset to get the anchor point at the bottom right
5352 // of the actual text and not the sprite.
@@ -65,7 +64,7 @@ class $modify(ST_MenuLayer, MenuLayer)
6564 {
6665 MenuLayer::onEnter ();
6766 m_fields->m_SplashText ->getLabel ()->setString (m_fields->m_SplashStr .c_str ());
68- m_fields->m_SplashText ->setScale ( 0 . 5f / ( 1 . 0f + 0 . 05f * strlen (m_fields-> m_SplashText -> getLabel ()-> getString ())) );
67+ m_fields->m_SplashText ->resetLabelScale ( );
6968 }
7069
7170 void onExit ()
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ void ScalingLabel::update(float dt)
2727 m_Label->setScale (newScale);
2828}
2929
30+ void ScalingLabel::resetLabelScale ()
31+ {
32+ // The scale here is an inverse scaling function for text used pretty often for UI.
33+ this ->setScale (0 .5f / (1 .0f + 0 .05f * strlen (this ->getLabel ()->getString ())));
34+ }
35+
3036ScalingLabel* ScalingLabel::create (std::string text, std::string fntFile, float scalingFactor)
3137{
3238 auto ret = new ScalingLabel (text, fntFile, scalingFactor);
Original file line number Diff line number Diff line change @@ -20,5 +20,6 @@ class ScalingLabel : public CCNode
2020 inline void setScalingFactor (float scalingFactor) { m_ScalingFactor = scalingFactor; }
2121 bool init () override ;
2222 void update (float dt) override ;
23+ void resetLabelScale ();
2324 static ScalingLabel* create (std::string text, std::string fntFile, float scalingFactor = 0 .5f );
2425};
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ bool SplashRead::loadFile(std::filesystem::path filePath)
1111 m_FileStream.open (filePath);
1212 if (!m_FileStream.is_open ())
1313 {
14- log::error (" File failed to open! May not exist!" );
14+ log::error (" File failed to open! May not exist or may be open in another program !" );
1515 return false ;
1616 }
1717
You can’t perform that action at this time.
0 commit comments