Skip to content

Commit

Permalink
why do i do this?
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhar committed Jul 2, 2023
1 parent a6ba185 commit 15fc9c9
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 21 deletions.
53 changes: 51 additions & 2 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import argparse
import asyncio
import copy
import collections
import copy
import datetime
import functools
import hashlib
Expand Down Expand Up @@ -955,7 +955,16 @@ def register_location_checks(ctx: Context, team: int, slot: int, locations: typi
logging.info('(Team #%d) %s sent %s to %s (%s)' % (
team + 1, ctx.player_names[(team, slot)], ctx.item_names[item_id],
ctx.player_names[(team, target_player)], ctx.location_names[location]))
info_text = json_format_send_event(new_item, target_player)

if ctx.item_names[item_id].endswith(" Stone"):
info_text = json_format_stone_event(new_item, target_player)
elif ctx.item_names[item_id].startswith("the dusted"):
info_text = json_format_dust_event(new_item, target_player)
elif ctx.item_names[item_id] == "Triforce Piece":
info_text = json_format_triforce_event(new_item, target_player)
else:
info_text = json_format_send_event(new_item, target_player)

ctx.broadcast_team(team, [info_text])

ctx.location_checks[team, slot] |= new_locations
Expand Down Expand Up @@ -1036,6 +1045,46 @@ def json_format_send_event(net_item: NetworkItem, receiving_player: int):
"item": net_item}


def json_format_stone_event(net_item: NetworkItem, receiving_player: int):
parts = []
NetUtils.add_json_text(parts, net_item, type=NetUtils.JSONTypes.player_id)
NetUtils.add_json_text(parts, " found the ")
NetUtils.add_json_item(parts, net_item.item, net_item.player, net_item.flags)
NetUtils.add_json_text(parts, " (")
NetUtils.add_json_location(parts, net_item.location, net_item.player)
NetUtils.add_json_text(parts, ")")

return {"cmd": "PrintJSON", "data": parts, "type": "ItemSend",
"receiving": receiving_player,
"item": net_item}


def json_format_triforce_event(net_item: NetworkItem, receiving_player: int):
parts = []
NetUtils.add_json_text(parts, net_item, type=NetUtils.JSONTypes.player_id)
NetUtils.add_json_text(parts, " also found a ")
NetUtils.add_json_item(parts, net_item.item, net_item.player, net_item.flags)
NetUtils.add_json_text(parts, "taped to the back of the stone!")

return {"cmd": "PrintJSON", "data": parts, "type": "ItemSend",
"receiving": receiving_player,
"item": net_item}


def json_format_dust_event(net_item: NetworkItem, receiving_player: int):
parts = []
NetUtils.add_json_text(parts, net_item, type=NetUtils.JSONTypes.player_id)
NetUtils.add_json_text(parts, " found ")
NetUtils.add_json_item(parts, net_item.item, net_item.player, net_item.flags)
NetUtils.add_json_text(parts, ". (")
NetUtils.add_json_location(parts, net_item.location, net_item.player)
NetUtils.add_json_text(parts, ")")

return {"cmd": "PrintJSON", "data": parts, "type": "ItemSend",
"receiving": receiving_player,
"item": net_item}


def get_intended_text(input_text: str, possible_answers) -> typing.Tuple[str, bool, str]:
picks = Utils.get_fuzzy_results(input_text, possible_answers, limit=2)
if len(picks) > 1:
Expand Down
49 changes: 49 additions & 0 deletions WebHostLib/static/assets/gauntletTracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
window.addEventListener('load', () => {
// Reload tracker every 15 seconds
const url = window.location;
setInterval(() => {
const ajax = new XMLHttpRequest();
ajax.onreadystatechange = () => {
if (ajax.readyState !== 4) { return; }

// Create a fake DOM using the returned HTML
const domParser = new DOMParser();
const fakeDOM = domParser.parseFromString(ajax.responseText, 'text/html');

// Update item tracker
document.getElementById('inventory-table').innerHTML = fakeDOM.getElementById('inventory-table').innerHTML;
// Update only counters in the location-table
let counters = document.getElementsByClassName('counter');
const fakeCounters = fakeDOM.getElementsByClassName('counter');
for (let i = 0; i < counters.length; i++) {
counters[i].innerHTML = fakeCounters[i].innerHTML;
}
};
ajax.open('GET', url);
ajax.send();
}, 15000)

// Collapsible advancement sections
const categories = document.getElementsByClassName("location-category");
for (let i = 0; i < categories.length; i++) {
let hide_id = categories[i].id.split('-')[0];
if (hide_id == 'Total') {
continue;
}
categories[i].addEventListener('click', function() {
// Toggle the advancement list
document.getElementById(hide_id).classList.toggle("hide");
// Change text of the header
const tab_header = document.getElementById(hide_id+'-header').children[0];
const orig_text = tab_header.innerHTML;
let new_text;
if (orig_text.includes("▼")) {
new_text = orig_text.replace("▼", "▲");
}
else {
new_text = orig_text.replace("▲", "▼");
}
tab_header.innerHTML = new_text;
});
}
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions WebHostLib/static/styles/gauntletTracker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#player-tracker-wrapper{
margin: 0;
}

#inventory-table{
border-top: 2px solid #000000;
border-left: 2px solid #000000;
border-right: 2px solid #000000;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
padding: 3px 3px 10px;
width: 384px;
background-color: #42b149;
}

#inventory-table td{
width: 40px;
height: 40px;
text-align: center;
vertical-align: middle;
}

#inventory-table img{
height: 100%;
max-width: 40px;
max-height: 40px;
filter: grayscale(100%) contrast(75%) brightness(30%);
}

#inventory-table img.acquired{
filter: none;
}

#inventory-table div.counted-item {
position: relative;
}

#inventory-table div.item-count {
position: absolute;
color: white;
font-family: "Minecraftia", monospace;
font-weight: bold;
bottom: 0;
right: 0;
}

#location-table{
width: 384px;
border-left: 2px solid #000000;
border-right: 2px solid #000000;
border-bottom: 2px solid #000000;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background-color: #42b149;
padding: 0 3px 3px;
font-family: "Minecraftia", monospace;
font-size: 14px;
cursor: default;
}

#location-table th{
vertical-align: middle;
text-align: left;
padding-right: 10px;
}

#location-table td{
padding-top: 2px;
padding-bottom: 2px;
line-height: 20px;
}

#location-table td.counter {
text-align: right;
font-size: 14px;
}

#location-table td.toggle-arrow {
text-align: right;
}

#location-table tr#Total-header {
font-weight: bold;
}

#location-table img{
height: 100%;
max-width: 30px;
max-height: 30px;
}

#location-table tbody.locations {
font-size: 12px;
}

#location-table td.location-name {
padding-left: 16px;
}

.hide {
display: none;
}
85 changes: 85 additions & 0 deletions WebHostLib/templates/gauntletTracker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>The Infinity Gauntlet</title>
<style>
body {
font-family: sans-serif;
{#background-image: url("../../../static/static/backgrounds/wallpaper.jpg");#}
background-size: cover;
background-color: black;
padding: 0;
margin: 0;
}

.container {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 1rem;
}

h1 {
width: 100%;
color: white;
text-align: center;
}

.items {
width: 100%;
display: flex;
justify-content: space-around;
gap: 1rem;
flex-wrap: wrap;
}

img {
filter: grayscale(1) drop-shadow(0px 0px 12px #000);
}

.acquired {
filter: grayscale(0) drop-shadow(0px 0px 12px #000);
}
</style>
</head>

<body>
<div class="container">
<h1>Found Pieces:</h1>
<div class="items">
<img
src="{{ icons['Space Stone'] }}"
class="{{ 'acquired' if 'Space Stone' in acquired_items }}"
title="Space Stone"
/>
<img
src="{{ icons['Mind Stone'] }}"
class="{{ 'acquired' if 'Mind Stone' in acquired_items }}"
title="Mind Stone"
/>
<img
src="{{ icons['Reality Stone'] }}"
class="{{ 'acquired' if 'Reality Stone' in acquired_items }}"
title="Reality Stone"
/>
<img
src="{{ icons['Power Stone'] }}"
class="{{ 'acquired' if 'Power Stone' in acquired_items }}"
title="Power Stone"
/>
<img
src="{{ icons['Time Stone'] }}"
class="{{ 'acquired' if 'Time Stone' in acquired_items }}"
title="Time Stone"
/>
<img
src="{{ icons['Soul Stone'] }}"
class="{{ 'acquired' if 'Soul Stone' in acquired_items }}"
title="Soul Stone"
/>
</div>
</div>
</body>
</html>
27 changes: 25 additions & 2 deletions WebHostLib/tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import collections
import datetime
import typing
from typing import Counter, Optional, Dict, Any, Tuple
from typing import Any, Counter, Dict, Optional, Tuple
from uuid import UUID

from flask import render_template
Expand Down Expand Up @@ -565,6 +565,28 @@ def __renderMinecraftTracker(multisave: Dict[str, Any], room: Room, locations: D
checks_done=checks_done, checks_in_area=checks_in_area, location_info=location_info,
**display_data)

def __renderGauntletTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int, int]]],
inventory: Counter, team: int, player: int, playerName: str,
seed_checks_in_area: Dict[int, Dict[str, int]], checks_done: Dict[str, int], slot_data: Dict,
saving_second: int) -> str:

icons = {
"Space Stone": "https://static.wikia.nocookie.net/marvelcinematicuniverse/images/0/0a/Space_Stone_VFX.png",
"Mind Stone": "https://static.wikia.nocookie.net/marvelcinematicuniverse/images/e/e4/Mind_Stone_VFX.png",
"Reality Stone": "https://static.wikia.nocookie.net/marvelcinematicuniverse/images/9/9b/Reality_Stone_VFX.png",
"Power Stone": "https://static.wikia.nocookie.net/marvelcinematicuniverse/images/d/d7/Power_Stone_VFX.png",
"Time Stone": "https://static.wikia.nocookie.net/marvelcinematicuniverse/images/f/f0/Time_Stone_VFX.png",
"Soul Stone": "https://static.wikia.nocookie.net/marvelcinematicuniverse/images/1/17/Soul_Stone_VFX.png",
"Wallpaper": "https://c.wallhere.com/photos/fe/3f/The_Legend_of_Zelda_video_games_Nintendo_The_Legend_of_Zelda_Majora's_Mask-223870.jpg!d",
}

return render_template("gauntletTracker.html",
inventory=inventory, icons=icons,
acquired_items={lookup_any_item_id_to_name[id] for id in inventory if
id in lookup_any_item_id_to_name},
player=player, team=team, room=room, player_name=playerName, saving_second = saving_second,
checks_done=checks_done, checks_in_area=checks_in_area)


def __renderOoTTracker(multisave: Dict[str, Any], room: Room, locations: Dict[int, Dict[int, Tuple[int, int, int]]],
inventory: Counter, team: int, player: int, playerName: str,
Expand Down Expand Up @@ -1574,7 +1596,8 @@ def attribute_item(team: int, recipient: int, item: int):
"A Link to the Past": __renderAlttpTracker,
"ChecksFinder": __renderChecksfinder,
"Super Metroid": __renderSuperMetroidTracker,
"Starcraft 2 Wings of Liberty": __renderSC2WoLTracker
"Starcraft 2 Wings of Liberty": __renderSC2WoLTracker,
"Infinity Gauntlet": __renderGauntletTracker,
}

multi_trackers: typing.Dict[str, typing.Callable] = {
Expand Down
2 changes: 1 addition & 1 deletion host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ generator:
# Folder from which the player yaml files are pulled from
player_files_path: "Players"
#amount of players, 0 to infer from player files
players: 0
players: 5
# general weights file, within the stated player_files_path location
# gets used if players is higher than the amount of per-player files found to fill remaining slots
weights_file_path: "weights.yaml"
Expand Down
Loading

0 comments on commit 15fc9c9

Please sign in to comment.