Skip to content

Commit

Permalink
WebHost: Fix player tracker issue with items missing from data package.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhar committed Jan 3, 2024
1 parent 0df0955 commit dffa9e9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
32 changes: 28 additions & 4 deletions WebHostLib/templates/genericTracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@

{% for id, count in inventory.items() if count > 0 %}
<tr>
<td>{{ item_id_to_name[game][id] }}</td>
<td>
{% if item_id_to_name[game][id] %}
{{ item_id_to_name[game][id] }}
{% else %}
Unknown Item #{{ id }}
{% endif %}
</td>
<td>{{ count }}</td>
<td>{{ received_items[id] }}</td>
</tr>
Expand All @@ -69,7 +75,13 @@

{%- for location in locations -%}
<tr>
<td>{{ location_id_to_name[game][location] }}</td>
<td>
{% if location_id_to_name[game][location] %}
{{ location_id_to_name[game][location] }}
{% else %}
Unknown Location #{{ id }}
{% endif %}
</td>
<td class="center-column">
{% if location in checked_locations %}✔{% endif %}
</td>
Expand Down Expand Up @@ -109,8 +121,20 @@
{{ player_names_with_alias[(team, hint.receiving_player)] }}
{% endif %}
</td>
<td>{{ item_id_to_name[games[(team, hint.receiving_player)]][hint.item] }}</td>
<td>{{ location_id_to_name[games[(team, hint.finding_player)]][hint.location] }}</td>
<td>
{% if item_id_to_name[games[(team, hint.receiving_player)]][hint.item] %}
{{ item_id_to_name[games[(team, hint.receiving_player)]][hint.item] }}
{% else %}
Unknown Item #{{ id }}
{% endif %}
</td>
<td>
{% if location_id_to_name[games[(team, hint.finding_player)]][hint.location] %}
{{ location_id_to_name[games[(team, hint.finding_player)]][hint.location] }}
{% else %}
Unknown Location #{{ id }}
{% endif %}
</td>
<td>{{ games[(team, hint.finding_player)] }}</td>
<td>{% if hint.entrance %}{{ hint.entrance }}{% else %}Vanilla{% endif %}</td>
<td class="center-column">{% if hint.found %}✔{% endif %}</td>
Expand Down
16 changes: 14 additions & 2 deletions WebHostLib/templates/multitrackerHintTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@
<tr>
<td>{{ player_names_with_alias[(team, hint.finding_player)] }}</td>
<td>{{ player_names_with_alias[(team, hint.receiving_player)] }}</td>
<td>{{ item_id_to_name[games[(team, hint.receiving_player)]][hint.item] }}</td>
<td>{{ location_id_to_name[games[(team, hint.finding_player)]][hint.location] }}</td>
<td>
{% if item_id_to_name[games[(team, hint.receiving_player)]][hint.item] %}
{{ item_id_to_name[games[(team, hint.receiving_player)]][hint.item] }}
{% else %}
Unknown Item #{{ id }}
{% endif %}
</td>
<td>
{% if location_id_to_name[games[(team, hint.finding_player)]][hint.location] %}
{{ location_id_to_name[games[(team, hint.finding_player)]][hint.location] }}
{% else %}
Unknown Location #{{ id }}
{% endif %}
</td>
<td>{{ games[(team, hint.finding_player)] }}</td>
<td>{% if hint.entrance %}{{ hint.entrance }}{% else %}Vanilla{% endif %}</td>
<td class="center-column">{% if hint.found %}✔{% endif %}</td>
Expand Down
6 changes: 3 additions & 3 deletions WebHostLib/tracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import collections
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Set, Tuple
from uuid import UUID
Expand Down Expand Up @@ -115,10 +116,10 @@ def get_player_received_items(self, team: int, player: int) -> List[NetworkItem]
return self._multisave.get("received_items", {}).get((team, player, True), [])

@_cache_results
def get_player_inventory_counts(self, team: int, player: int) -> Dict[int, int]:
def get_player_inventory_counts(self, team: int, player: int) -> collections.Counter:
"""Retrieves a dictionary of all items received by their id and their received count."""
items = self.get_player_received_items(team, player)
inventory = {item: 0 for item in self.item_id_to_name[self.get_player_game(team, player)]}
inventory = collections.Counter()
for item in items:
inventory[item.item] += 1

Expand Down Expand Up @@ -389,7 +390,6 @@ def render_generic_multiworld_tracker(tracker_data: TrackerData, enabled_tracker

# TODO: This is a temporary solution until a proper Tracker API can be implemented for tracker templates and data to
# live in their respective world folders.
import collections

from worlds import network_data_package

Expand Down

0 comments on commit dffa9e9

Please sign in to comment.