Skip to content

Commit

Permalink
Save and display country origins (#152)
Browse files Browse the repository at this point in the history
Closes #149
  • Loading branch information
MichaelMakesGames authored May 15, 2024
1 parent 01a8a24 commit 3cd906f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions stellarisdashboard/dashboard_app/history_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def country_details(self, country_model: datamodel.Country) -> Dict[str, str]:
"Civics": ", ".join(
[game_info.lookup_key(c) for c in sorted(gov.civics)]
),
"Origin": game_info.lookup_key(country_model.origin or "UNKNOWN")
}
)
for key, countries in country_model.diplo_relation_details().items():
Expand Down
1 change: 1 addition & 0 deletions stellarisdashboard/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ class Country(Base):
country_type = Column(String(50))
primary_color = Column(String(80))
secondary_color = Column(String(80))
origin = Column(String(80))

game = relationship("Game", back_populates="countries")
capital = relationship("Planet", foreign_keys=[capital_planet_id], post_update=True)
Expand Down
8 changes: 7 additions & 1 deletion stellarisdashboard/parsing/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _identify_player_country(self):
else:
self._other_players.add(player["country"])
if playercountry is None:
raise ValueError(
logger.warn(
f"Could not find player matching Multiplayer username {config.CONFIG.mp_username}"
)
return playercountry
Expand Down Expand Up @@ -425,6 +425,7 @@ def extract_data_from_gamestate(self, dependencies):
flag_colors = country_data_dict.get("flag", {}).get("colors", [])
primary_color = flag_colors[0] if len(flag_colors) >= 1 else "black"
secondary_color = flag_colors[1] if len(flag_colors) >= 2 else primary_color
origin = country_data_dict.get("government", {}).get("origin")
country_model = (
self._session.query(datamodel.Country)
.filter_by(game=self._db_game, country_id_in_game=country_id)
Expand All @@ -444,6 +445,7 @@ def extract_data_from_gamestate(self, dependencies):
country_name=country_name,
primary_color=primary_color,
secondary_color=secondary_color,
origin=origin
)
if country_id == self._basic_info.player_country_id:
country_model.first_player_contact_date = 0
Expand All @@ -453,9 +455,13 @@ def extract_data_from_gamestate(self, dependencies):
or country_type != country_model.country_type
or primary_color != country_model.primary_color
or secondary_color != country_model.secondary_color
or origin != country_model.origin
):
country_model.country_name = country_name
country_model.country_type = country_type
country_model.primary_color = primary_color
country_model.secondary_color = secondary_color
country_model.origin = origin
self._session.add(country_model)
self.countries_by_ingame_id[country_id] = country_model

Expand Down

0 comments on commit 3cd906f

Please sign in to comment.