Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
CaitSith2 2021-11-25 16:38:43 -08:00
commit 4dfa1e3227
7 changed files with 53 additions and 38 deletions

View File

@ -126,7 +126,7 @@ def faq(lang):
@app.route('/seed/<suuid:seed>') @app.route('/seed/<suuid:seed>')
def viewSeed(seed: UUID): def view_seed(seed: UUID):
seed = Seed.get(id=seed) seed = Seed.get(id=seed)
if not seed: if not seed:
abort(404) abort(404)

View File

@ -76,7 +76,7 @@ def generate(race=False):
handle_generation_failure(e) handle_generation_failure(e)
return render_template("seedError.html", seed_error=(e.__class__.__name__ + ": " + str(e))) return render_template("seedError.html", seed_error=(e.__class__.__name__ + ": " + str(e)))
return redirect(url_for("viewSeed", seed=seed_id)) return redirect(url_for("view_seed", seed=seed_id))
return render_template("generate.html", race=race) return render_template("generate.html", race=race)
@ -143,7 +143,7 @@ def wait_seed(seed: UUID):
seed_id = seed seed_id = seed
seed = Seed.get(id=seed_id) seed = Seed.get(id=seed_id)
if seed: if seed:
return redirect(url_for("viewSeed", seed=seed_id)) return redirect(url_for("view_seed", seed=seed_id))
generation = Generation.get(id=seed_id) generation = Generation.get(id=seed_id)
if not generation: if not generation:

View File

@ -9,7 +9,7 @@
{% include 'header/grassHeader.html' %} {% include 'header/grassHeader.html' %}
<div id="host-room"> <div id="host-room">
{% if room.owner == session["_id"] %} {% if room.owner == session["_id"] %}
Room created from <a href="{{ url_for("viewSeed", seed=room.seed.id) }}">Seed #{{ room.seed.id|suuid }}</a> Room created from <a href="{{ url_for("view_seed", seed=room.seed.id) }}">Seed #{{ room.seed.id|suuid }}</a>
<br> <br>
{% endif %} {% endif %}
{% if room.tracker %} {% if room.tracker %}

View File

@ -1,7 +1,7 @@
{% macro list_rooms(rooms) -%} {% macro list_rooms(rooms) -%}
<ul> <ul>
{% for room in rooms %} {% for room in rooms %}
<li><a href="{{ url_for("hostRoom", room=room.id) }}">Room #{{ room.id|suuid }}</a></li> <li><a href="{{ url_for("host_room", room=room.id) }}">Room #{{ room.id|suuid }}</a></li>
{% endfor %} {% endfor %}
{{ caller() }} {{ caller() }}
</ul> </ul>

View File

@ -29,8 +29,8 @@
<tbody> <tbody>
{% for room in rooms %} {% for room in rooms %}
<tr> <tr>
<td><a href="{{ url_for("viewSeed", seed=room.seed.id) }}">{{ room.seed.id|suuid }}</a></td> <td><a href="{{ url_for("view_seed", seed=room.seed.id) }}">{{ room.seed.id|suuid }}</a></td>
<td><a href="{{ url_for("hostRoom", room=room.id) }}">{{ room.id|suuid }}</a></td> <td><a href="{{ url_for("host_room", room=room.id) }}">{{ room.id|suuid }}</a></td>
<td>>={{ room.seed.slots|length }}</td> <td>>={{ room.seed.slots|length }}</td>
<td>{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }}</td> <td>{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
<td>{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }}</td> <td>{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }}</td>
@ -55,7 +55,7 @@
<tbody> <tbody>
{% for seed in seeds %} {% for seed in seeds %}
<tr> <tr>
<td><a href="{{ url_for("viewSeed", seed=seed.id) }}">{{ seed.id|suuid }}</a></td> <td><a href="{{ url_for("view_seed", seed=seed.id) }}">{{ seed.id|suuid }}</a></td>
<td>{% if seed.multidata %}>={{ seed.slots|length }}{% else %}1{% endif %} <td>{% if seed.multidata %}>={{ seed.slots|length }}{% else %}1{% endif %}
</td> </td>
<td>{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }}</td> <td>{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>

View File

@ -1,4 +1,5 @@
import collections import collections
import typing
from typing import Counter, Optional, Dict, Any, Tuple from typing import Counter, Optional, Dict, Any, Tuple
from flask import render_template from flask import render_template
@ -10,6 +11,7 @@ from worlds.alttp import Items
from WebHostLib import app, cache, Room from WebHostLib import app, cache, Room
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 from worlds import lookup_any_item_id_to_name, lookup_any_location_id_to_name
from MultiServer import get_item_name_from_id, Context
alttp_icons = { alttp_icons = {
"Blue Shield": r"https://www.zeldadungeon.net/wiki/images/8/85/Fighters-Shield.png", "Blue Shield": r"https://www.zeldadungeon.net/wiki/images/8/85/Fighters-Shield.png",
@ -74,6 +76,7 @@ alttp_icons = {
"Ganons Tower": r"https://gamepedia.cursecdn.com/zelda_gamepedia_en/b/b9/ALttP_Ganon_Sprite.png?version=956f51f054954dfff53c1a9d4f929c74" "Ganons Tower": r"https://gamepedia.cursecdn.com/zelda_gamepedia_en/b/b9/ALttP_Ganon_Sprite.png?version=956f51f054954dfff53c1a9d4f929c74"
} }
def get_alttp_id(item_name): def get_alttp_id(item_name):
return Items.item_table[item_name][2] return Items.item_table[item_name][2]
@ -201,7 +204,10 @@ for item_name, data in Items.item_table.items():
big_key_ids[area] = data[2] big_key_ids[area] = data[2]
ids_big_key[data[2]] = area ids_big_key[data[2]] = area
from MultiServer import get_item_name_from_id, Context # cleanup global namespace
del item_name
del data
del item
def attribute_item(inventory, team, recipient, item): def attribute_item(inventory, team, recipient, item):
@ -268,8 +274,7 @@ def get_static_room_data(room: Room):
for playernumber in range(1, len(names[0]) + 1)} for playernumber in range(1, len(names[0]) + 1)}
result = locations, names, use_door_tracker, player_checks_in_area, player_location_to_area, \ result = locations, names, use_door_tracker, player_checks_in_area, player_location_to_area, \
multidata["precollected_items"], \ multidata["precollected_items"], multidata["games"]
multidata["games"]
_multidata_cache[room.seed.id] = result _multidata_cache[room.seed.id] = result
return result return result
@ -318,22 +323,17 @@ def getPlayerTracker(tracker: UUID, tracked_team: int, tracked_player: int):
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 checks_done[location_to_area[location]] += 1
checks_done["Total"] += 1 checks_done["Total"] += 1
specific_tracker = game_specific_trackers.get(games[tracked_player], None)
if games[tracked_player] == "A Link to the Past": if specific_tracker:
return __renderAlttpTracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name, \ return specific_tracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name,
seed_checks_in_area, checks_done) seed_checks_in_area, checks_done)
elif games[tracked_player] == "Minecraft":
return __renderMinecraftTracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name)
elif games[tracked_player] == "Ocarina of Time":
return __renderOoTTracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name)
elif games[tracked_player] == "Timespinner":
return __renderTimespinnerTracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name)
else: else:
return __renderGenericTracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name) return __renderGenericTracker(multisave, room, locations, inventory, tracked_team, tracked_player, player_name,
seed_checks_in_area, checks_done)
def __renderAlttpTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]], def __renderAlttpTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]],
inventory: Counter, team: int, player: int, playerName: str, inventory: Counter, team: int, player: int, player_name: str,
seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int]) -> str: seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int]) -> str:
# Note the presence of the triforce item # Note the presence of the triforce item
@ -384,7 +384,7 @@ def __renderAlttpTracker(multisave: Dict[str, Any], room: Room, locations: Dict[
player_small_key_locations.add(ids_small_key[item_id]) player_small_key_locations.add(ids_small_key[item_id])
return render_template("lttpTracker.html", inventory=inventory, return render_template("lttpTracker.html", inventory=inventory,
player_name=playerName, room=room, icons=alttp_icons, checks_done=checks_done, player_name=player_name, room=room, icons=alttp_icons, checks_done=checks_done,
checks_in_area=seed_checks_in_area[player], checks_in_area=seed_checks_in_area[player],
acquired_items={lookup_any_item_id_to_name[id] for id in inventory}, acquired_items={lookup_any_item_id_to_name[id] for id in inventory},
small_key_ids=small_key_ids, big_key_ids=big_key_ids, sp_areas=sp_areas, small_key_ids=small_key_ids, big_key_ids=big_key_ids, sp_areas=sp_areas,
@ -394,7 +394,8 @@ def __renderAlttpTracker(multisave: Dict[str, Any], room: Room, locations: Dict[
def __renderMinecraftTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]], def __renderMinecraftTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]],
inventory: Counter, team: int, player: int, playerName: str) -> str: inventory: Counter, team: int, player: int, playerName: str,
seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int]) -> str:
icons = { icons = {
"Wooden Pickaxe": "https://static.wikia.nocookie.net/minecraft_gamepedia/images/d/d2/Wooden_Pickaxe_JE3_BE3.png", "Wooden Pickaxe": "https://static.wikia.nocookie.net/minecraft_gamepedia/images/d/d2/Wooden_Pickaxe_JE3_BE3.png",
@ -494,7 +495,8 @@ def __renderMinecraftTracker(multisave: Dict[str, Any], room: Room, locations: D
def __renderOoTTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]], def __renderOoTTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]],
inventory: Counter, team: int, player: int, playerName: str) -> str: inventory: Counter, team: int, player: int, playerName: str,
seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int]) -> str:
icons = { icons = {
"Fairy Ocarina": "https://static.wikia.nocookie.net/zelda_gamepedia_en/images/9/97/OoT_Fairy_Ocarina_Icon.png", "Fairy Ocarina": "https://static.wikia.nocookie.net/zelda_gamepedia_en/images/9/97/OoT_Fairy_Ocarina_Icon.png",
@ -621,12 +623,14 @@ def __renderOoTTracker(multisave: Dict[str, Any], room: Room, locations: Dict[in
"Gerudo Training Grounds": (67597, 67635), "Gerudo Training Grounds": (67597, 67635),
"Ganon's Castle": (67636, 67673), "Ganon's Castle": (67636, 67673),
} }
def lookup_and_trim(id, area): def lookup_and_trim(id, area):
full_name = lookup_any_location_id_to_name[id] full_name = lookup_any_location_id_to_name[id]
if id == 67673: if id == 67673:
return full_name[13:] # Ganons Tower Boss Key Chest return full_name[13:] # Ganons Tower Boss Key Chest
if area != 'Overworld': if area != 'Overworld':
return full_name[len(area):] # trim dungeon name. leaves an extra space that doesn't display, or trims fully for DC/Jabu/GC # trim dungeon name. leaves an extra space that doesn't display, or trims fully for DC/Jabu/GC
return full_name[len(area):]
return full_name return full_name
checked_locations = multisave.get("location_checks", {}).get((team, player), set()).intersection(set(locations[player])) checked_locations = multisave.get("location_checks", {}).get((team, player), set()).intersection(set(locations[player]))
@ -675,8 +679,10 @@ def __renderOoTTracker(multisave: Dict[str, Any], room: Room, locations: Dict[in
small_key_counts=small_key_counts, boss_key_counts=boss_key_counts, small_key_counts=small_key_counts, boss_key_counts=boss_key_counts,
**display_data) **display_data)
def __renderTimespinnerTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]], def __renderTimespinnerTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]],
inventory: Counter, team: int, player: int, playerName: str) -> str: inventory: Counter, team: int, player: int, playerName: str,
seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int]) -> str:
icons = { icons = {
"Timespinner Wheel": "https://timespinnerwiki.com/mediawiki/images/7/76/Timespinner_Wheel.png", "Timespinner Wheel": "https://timespinnerwiki.com/mediawiki/images/7/76/Timespinner_Wheel.png",
@ -760,7 +766,8 @@ def __renderTimespinnerTracker(multisave: Dict[str, Any], room: Room, locations:
def __renderGenericTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]], def __renderGenericTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int]]],
inventory: Counter, team: int, player: int, playerName: str) -> str: inventory: Counter, team: int, player: int, playerName: str,
seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int]) -> str:
checked_locations = multisave.get("location_checks", {}).get((team, player), set()) checked_locations = multisave.get("location_checks", {}).get((team, player), set())
player_received_items = {} player_received_items = {}
@ -864,3 +871,11 @@ def getTracker(tracker: UUID):
key_locations=group_key_locations, small_key_ids=small_key_ids, big_key_ids=big_key_ids, key_locations=group_key_locations, small_key_ids=small_key_ids, big_key_ids=big_key_ids,
video=video, big_key_locations=group_big_key_locations, video=video, big_key_locations=group_big_key_locations,
hints=hints, long_player_names=long_player_names) hints=hints, long_player_names=long_player_names)
game_specific_trackers: typing.Dict[str, typing.Callable] = {
"Minecraft": __renderMinecraftTracker,
"Ocarina of Time": __renderOoTTracker,
"Timespinner": __renderTimespinnerTracker,
"A Link to the Past": __renderAlttpTracker
}

View File

@ -98,7 +98,7 @@ def uploads():
if type(res) == str: if type(res) == str:
return res return res
elif res: elif res:
return redirect(url_for("viewSeed", seed=res.id)) return redirect(url_for("view_seed", seed=res.id))
else: else:
try: try:
multidata = file.read() multidata = file.read()
@ -109,7 +109,7 @@ def uploads():
else: else:
seed = Seed(multidata=multidata, owner=session["_id"]) seed = Seed(multidata=multidata, owner=session["_id"])
flush() # place into DB and generate ids flush() # place into DB and generate ids
return redirect(url_for("viewSeed", seed=seed.id)) return redirect(url_for("view_seed", seed=seed.id))
else: else:
flash("Not recognized file format. Awaiting a .archipelago file or .zip containing one.") flash("Not recognized file format. Awaiting a .archipelago file or .zip containing one.")
return render_template("hostGame.html") return render_template("hostGame.html")