Browse Source

Address code review feedback - improve code organization

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 month ago
parent
commit
c25a2f3f54
2 changed files with 12 additions and 12 deletions
  1. 2 2
      game/map/map_loader.cpp
  2. 10 10
      render/entity/barracks_renderer.cpp

+ 2 - 2
game/map/map_loader.cpp

@@ -258,8 +258,8 @@ void readSpawns(const QJsonArray &arr, std::vector<UnitSpawn> &out) {
     // Parse nation field if present (for backward compatibility, it's optional)
     if (spawn_obj.contains(NATION)) {
       const QString nation_str = spawn_obj.value(NATION).toString();
-      Game::Systems::NationID nation_id;
-      if (Game::Systems::tryParseNationID(nation_str, nation_id)) {
+      if (Game::Systems::NationID nation_id; 
+          Game::Systems::tryParseNationID(nation_str, nation_id)) {
         spawn.nation = nation_id;
       } else {
         qWarning() << "MapLoader: unknown nation" << nation_str 

+ 10 - 10
render/entity/barracks_renderer.cpp

@@ -100,6 +100,15 @@ inline auto makeCarthaginianPalette(const QVector3D &team) -> BarracksPalette {
   return p;
 }
 
+inline auto selectPaletteForNation(const QVector3D &team, 
+                                   Engine::Core::UnitComponent *unit) -> BarracksPalette {
+  if (unit != nullptr && unit->nation_id == Game::Systems::NationID::Carthage) {
+    return makeCarthaginianPalette(team);
+  }
+  // Roman (default)
+  return makePalette(team);
+}
+
 inline void drawCylinder(ISubmitter &out, const QMatrix4x4 &model,
                          const QVector3D &a, const QVector3D &b, float radius,
                          const QVector3D &color, Texture *white) {
@@ -712,16 +721,7 @@ void drawBarracks(const DrawContext &p, ISubmitter &out) {
   Texture *white = p.resources->white();
 
   QVector3D const team(r->color[0], r->color[1], r->color[2]);
-  
-  // Determine nation and select appropriate palette
-  // Default to Roman if nation is not specified
-  BarracksPalette c;
-  if (u != nullptr && u->nation_id == Game::Systems::NationID::Carthage) {
-    c = makeCarthaginianPalette(team);
-  } else {
-    // Roman (default)
-    c = makePalette(team);
-  }
+  BarracksPalette const c = selectPaletteForNation(team, u);
 
   drawFoundation(p, out, unit, white, c);
   drawAnnex(p, out, unit, white, c);