Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle completely destroyed (removed from gamestate) planets #174

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stellarisdashboard/dashboard_app/history_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def planet_details(self, planet_model: datamodel.Planet):
details = {}

if planet_model.planet_class is None:
details["Planet Class"] = "Unknown Planet Class"
details["Planet Class"] = "Destroyed (no trace remains)"
else:
details["Planet Class"] = game_info.convert_id_to_name(
planet_model.planet_class, remove_prefix="pc"
Expand Down
31 changes: 26 additions & 5 deletions stellarisdashboard/dashboard_app/templates/history_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
{% endif %}
{%- endmacro %}

{% macro render_planet_and_class(event, fallback="an unknown planet") -%}
{% if event["planet"] is not none %}
{% if event["planet"].planet_class is not none %}
the {{ event["planet"].planetclass }} {{ links[event["planet"]] | safe }}
{% else %}
{{ links[event["planet"]] | safe }}
{% endif %}
{% else %}
{{ fallback }}
{% endif %}
{%- endmacro %}

{% macro render_a_an(text) -%}
{% if text.startswith(("a", "e", "i", "o", "u")) %} an {% else %} a {% endif %}
{%- endmacro %}

{% block body %}
{% if not is_filtered_page %}
<div class="ledgerbox">
Expand Down Expand Up @@ -90,7 +106,7 @@ <h2 class="eventlist_header">{{title[object] | safe}}</h2>
{% if "leader" in event %} Under the rule of {{ render_leader(event) }}, the
{% else %} The
{% endif %}
{{ links[event["country"]] | safe }} relocated their capital to the {{ event["planet"].planetclass }} {{ links[event["planet"]] | safe }}
{{ links[event["country"]] | safe }} relocated their capital to {{ render_planet_and_class(event) }}
in the {{ links[event["system"]] | safe }} system.
</span>
</div>
Expand All @@ -100,8 +116,8 @@ <h2 class="eventlist_header">{{title[object] | safe}}</h2>
<div class="eventdescription">
<span class="dateblock">{% if event["is_active"] %}(A){% endif %} {{event["start_date"]}}{% if event["end_date"] != null %} - {{event["end_date"]}}{%endif%}:</span>
<span class="eventtext">
The {{ links[event["country"]] | safe }} colonized the {{ event["planet"].planetclass }}
{{ links[event["planet"]] | safe }} in the {{ links[event["system"]] | safe }} system
The {{ links[event["country"]] | safe }} colonized {{ render_planet_and_class(event) }}
in the {{ links[event["system"]] | safe }} system
{% if "leader" in event%} under the governorship of {{ render_leader(event) }}{% endif %}.
</span>
</div>
Expand Down Expand Up @@ -623,7 +639,7 @@ <h2 class="eventlist_header">{{title[object] | safe}}</h2>
{% else %} The
{% endif %}
{{ links[event["country"]] | safe }} created the {{ event["description"] }} sector{% if "planet" in event %}
with capital on planet {{ links[event["planet"]] | safe }} in the {{ links[event["system"]] | safe }} system
with capital on the planet {{ links[event["planet"]] | safe }} in the {{ links[event["system"]] | safe }} system
{% endif %}.
</span>
</div>
Expand Down Expand Up @@ -689,7 +705,12 @@ <h2 class="eventlist_header">{{title[object] | safe}}</h2>
<span class="dateblock">{{event["start_date"]}}:</span>
<span class="eventtext">
The planet {{ links[event["planet"]] | safe }} in the {{ links[event["system"]] | safe }} system, owned by the
{{ links[event["country"]] | safe }} was destroyed. It is now a {{ event["planet"].planetclass }}.
{{ links[event["country"]] | safe }} was destroyed.
{% if event["planet"].planet_class is not none %}
It is now {{ render_a_an(event["planet"].planetclass) }} {{ event["planet"].planetclass }}.
{% else %}
No trace remains.
{% endif %}
</span>
</div>
</li>
Expand Down
4 changes: 2 additions & 2 deletions stellarisdashboard/parsing/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,8 +1894,8 @@ def extract_data_from_gamestate(self, dependencies: Dict[str, Any]):

def _update_planet_model(self, planet_dict: Dict, planet_model: datamodel.Planet):
planet_class = planet_dict.get("planet_class")
planet_name = dump_name(planet_dict.get("name"))
if planet_model.planet_name != planet_name:
planet_name = dump_name(planet_dict.get("name")) if "name" in planet_dict else None
if planet_name is not None and planet_model.planet_name != planet_name:
planet_model.planet_name = planet_name
self._session.add(planet_model)
if planet_model.planet_class != planet_class:
Expand Down
Loading