]> git.sesse.net Git - pkanalytics/commitdiff
Show formation name in the status bar.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 29 May 2023 13:38:53 +0000 (15:38 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 29 May 2023 13:38:53 +0000 (15:38 +0200)
events.cpp
events.h
formations.h
main.cpp

index ad70407bdfae7754022551e53ca601fc8e4801c6..9826f0ecbbc487e8a23ec1932f4b4b52e0d66a39 100644 (file)
@@ -314,6 +314,8 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t)
        s.our_score = 0;
        s.their_score = 0;
        s.attack_state = Status::NOT_STARTED;
+       s.offensive_formation = 0;
+       s.defensive_formation = 0;
        s.stoppage = false;
        s.pull_state = Status::SHOULD_PULL;
        uint64_t last_gained_possession = 0;
@@ -388,6 +390,20 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t)
                                last_stoppage = 0;
                        }
                }
+               if (e.type == "formation_offense") {
+                       if (e.formation_id) {
+                               s.offensive_formation = *e.formation_id;
+                       } else {
+                               s.offensive_formation = 0;
+                       }
+               }
+               if (e.type == "formation_defense") {
+                       if (e.formation_id) {
+                               s.defensive_formation = *e.formation_id;
+                       } else {
+                               s.defensive_formation = 0;
+                       }
+               }
        }
        if (s.stoppage && last_stoppage != 0) {
                time_spent_in_stoppage += (t - last_stoppage);
index 6dc2faf2f069e3d0d8c8c35e0cdf54a8c7113e90..8922496dc854284fcf4298aec6fabdd3f1d6950d 100644 (file)
--- a/events.h
+++ b/events.h
@@ -38,6 +38,7 @@ public:
        struct Status {
                unsigned our_score, their_score;
                enum { NOT_STARTED, OFFENSE, DEFENSE } attack_state;
+               unsigned offensive_formation, defensive_formation;
                bool stoppage;
                enum { NOT_PULLING, SHOULD_PULL, PULL_IN_AIR } pull_state;
                unsigned num_passes;
index aa85c79feb97b57838b63d8f276f927a33fa3f00..c02317329588a3ff305090d1d2276c17c00b311e 100644 (file)
@@ -29,7 +29,14 @@ public:
                }
                return formations[row - 1].formation_id;
        }
-       std::string get_formation_name_by_id(unsigned formation_id);
+       std::string get_formation_name_by_id(unsigned formation_id) {
+               for (unsigned i = 0; i < formations.size(); ++i) {
+                       if (formations[i].formation_id == formation_id) {
+                               return formations[i].name;
+                       }
+               }
+               abort();
+       }
        unsigned get_row_from_id(unsigned formation_id) {
                for (unsigned i = 0; i < formations.size(); ++i) {
                        if (formations[i].formation_id == formation_id) {
index 42d42cc0899300aefd254b5f3682e3856f308388..01b158373c1bc9cf620744055134dbe8a5a3ddf9 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -301,15 +301,23 @@ void MainWindow::update_status(uint64_t t)
 {
        EventsModel::Status s = events->get_status_at(t);
        char buf[256];
-       const char *offense = "not started";
+       std::string formation = "Not started";
        if (s.attack_state == EventsModel::Status::OFFENSE) {
-               offense = "offense";
+               if (s.offensive_formation != 0) {
+                       formation = offensive_formations->get_formation_name_by_id(s.offensive_formation);
+               } else {
+                       formation = "Offense";
+               }
        } else if (s.attack_state == EventsModel::Status::DEFENSE) {
-               offense = "defense";
+               if (s.defensive_formation != 0) {
+                       formation = defensive_formations->get_formation_name_by_id(s.defensive_formation);
+               } else {
+                       formation = "Defense";
+               }
        }
 
        snprintf(buf, sizeof(buf), "%d–%d | %s | %d passes, %d sec possession",
-               s.our_score, s.their_score, offense, s.num_passes, s.possession_sec);
+               s.our_score, s.their_score, formation.c_str(), s.num_passes, s.possession_sec);
        if (s.stoppage_sec > 0) {
                char buf2[256];
                snprintf(buf2, sizeof(buf2), "%s (plus %d sec stoppage)", buf, s.stoppage_sec);