Core: remove "names" from multidata (#1928)

This commit is contained in:
Fabian Dill 2023-07-05 21:51:38 +02:00 committed by GitHub
parent e920692ec3
commit d8a8997684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -368,7 +368,6 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
multidata = { multidata = {
"slot_data": slot_data, "slot_data": slot_data,
"slot_info": slot_info, "slot_info": slot_info,
"names": names, # TODO: remove after 0.3.9
"connect_names": {name: (0, player) for player, name in world.player_name.items()}, "connect_names": {name: (0, player) for player, name in world.player_name.items()},
"locations": locations_data, "locations": locations_data,
"checks_in_area": checks_in_area, "checks_in_area": checks_in_area,

View File

@ -1,7 +1,7 @@
import collections import collections
import datetime import datetime
import typing import typing
from typing import Counter, Optional, Dict, Any, Tuple from typing import Counter, Optional, Dict, Any, Tuple, List
from uuid import UUID from uuid import UUID
from flask import render_template from flask import render_template
@ -9,7 +9,7 @@ from jinja2 import pass_context, runtime
from werkzeug.exceptions import abort from werkzeug.exceptions import abort
from MultiServer import Context, get_saving_second from MultiServer import Context, get_saving_second
from NetUtils import SlotType from NetUtils import SlotType, NetworkSlot
from Utils import restricted_loads from Utils import restricted_loads
from worlds import lookup_any_item_id_to_name, lookup_any_location_id_to_name, network_data_package from worlds import lookup_any_item_id_to_name, lookup_any_location_id_to_name, network_data_package
from worlds.alttp import Items from worlds.alttp import Items
@ -264,16 +264,17 @@ def get_static_room_data(room: Room):
multidata = Context.decompress(room.seed.multidata) multidata = Context.decompress(room.seed.multidata)
# in > 100 players this can take a bit of time and is the main reason for the cache # in > 100 players this can take a bit of time and is the main reason for the cache
locations: Dict[int, Dict[int, Tuple[int, int, int]]] = multidata['locations'] locations: Dict[int, Dict[int, Tuple[int, int, int]]] = multidata['locations']
names: Dict[int, Dict[int, str]] = multidata["names"] names: List[List[str]] = multidata.get("names", [])
games = {} games = multidata.get("games", {})
groups = {} groups = {}
custom_locations = {} custom_locations = {}
custom_items = {} custom_items = {}
if "slot_info" in multidata: if "slot_info" in multidata:
games = {slot: slot_info.game for slot, slot_info in multidata["slot_info"].items()} slot_info_dict: Dict[int, NetworkSlot] = multidata["slot_info"]
groups = {slot: slot_info.group_members for slot, slot_info in multidata["slot_info"].items() games = {slot: slot_info.game for slot, slot_info in slot_info_dict.items()}
groups = {slot: slot_info.group_members for slot, slot_info in slot_info_dict.items()
if slot_info.type == SlotType.group} if slot_info.type == SlotType.group}
names = [[slot_info.name for slot, slot_info in sorted(slot_info_dict.items())]]
for game in games.values(): for game in games.values():
if game not in multidata["datapackage"]: if game not in multidata["datapackage"]:
continue continue
@ -290,8 +291,7 @@ def get_static_room_data(room: Room):
{id_: name for name, id_ in game_data["location_name_to_id"].items()}) {id_: name for name, id_ in game_data["location_name_to_id"].items()})
custom_items.update( custom_items.update(
{id_: name for name, id_ in game_data["item_name_to_id"].items()}) {id_: name for name, id_ in game_data["item_name_to_id"].items()})
elif "games" in multidata:
games = multidata["games"]
seed_checks_in_area = checks_in_area.copy() seed_checks_in_area = checks_in_area.copy()
use_door_tracker = False use_door_tracker = False
@ -341,7 +341,7 @@ def _get_player_tracker(tracker: UUID, tracked_team: int, tracked_player: int, w
precollected_items, games, slot_data, groups, saving_second, custom_locations, custom_items = \ precollected_items, games, slot_data, groups, saving_second, custom_locations, custom_items = \
get_static_room_data(room) get_static_room_data(room)
player_name = names[tracked_team][tracked_player - 1] player_name = names[tracked_team][tracked_player - 1]
location_to_area = player_location_to_area[tracked_player] location_to_area = player_location_to_area.get(tracked_player, {})
inventory = collections.Counter() inventory = collections.Counter()
checks_done = {loc_name: 0 for loc_name in default_locations} checks_done = {loc_name: 0 for loc_name in default_locations}
@ -373,7 +373,9 @@ def _get_player_tracker(tracker: UUID, tracked_team: int, tracked_player: int, w
if recipient in slots_aimed_at_player: # a check done for the tracked player if recipient in slots_aimed_at_player: # a check done for the tracked player
attribute_item_solo(inventory, item) attribute_item_solo(inventory, item)
if ms_player == tracked_player: # a check done by the tracked player if ms_player == tracked_player: # a check done by the tracked player
checks_done[location_to_area[location]] += 1 area_name = location_to_area.get(location, None)
if area_name:
checks_done[area_name] += 1
checks_done["Total"] += 1 checks_done["Total"] += 1
specific_tracker = game_specific_trackers.get(games[tracked_player], None) specific_tracker = game_specific_trackers.get(games[tracked_player], None)
if specific_tracker and not want_generic: if specific_tracker and not want_generic:
@ -1508,8 +1510,8 @@ def get_LttP_multiworld_tracker(tracker: UUID):
checks_done[team][player][player_location_to_area[player][location]] += 1 checks_done[team][player][player_location_to_area[player][location]] += 1
checks_done[team][player]["Total"] += 1 checks_done[team][player]["Total"] += 1
percent_total_checks_done[team][player] = int( percent_total_checks_done[team][player] = int(
checks_done[team][player]["Total"] / seed_checks_in_area[player]["Total"] * 100) if \ checks_done[team][player]["Total"] / len(player_locations) * 100) if \
seed_checks_in_area[player]["Total"] else 100 player_locations else 100
for (team, player), game_state in multisave.get("client_game_state", {}).items(): for (team, player), game_state in multisave.get("client_game_state", {}).items():
if player in groups: if player in groups: