changed timestamp to uuid strings, adjusted variable names in the_prestige and main_controller

This commit is contained in:
Sakimori 2021-01-05 14:26:54 -05:00
parent 8d01a3cc79
commit 803f633a9e
2 changed files with 22 additions and 21 deletions

View File

@ -31,9 +31,9 @@ def handle_new_conn(data):
def update_loop():
while True:
game_states = {}
game_times = iter(master_games_dic.copy().keys())
for game_time in game_times:
this_game, state, discrim_string = master_games_dic[game_time]
game_ids = iter(master_games_dic.copy().keys())
for game_id in game_ids:
this_game, state, discrim_string = master_games_dic[game_id]
test_string = this_game.gamestate_display_full()
state["leagueoruser"] = discrim_string
state["display_inning"] = this_game.inning #games need to be initialized with the following keys in state:
@ -125,16 +125,16 @@ def update_loop():
state["top_of_inning"] = this_game.top_of_inning
game_states[game_time] = state
game_states[game_id] = state
if state["update_pause"] <= 1 and state["start_delay"] < 0:
if this_game.over:
state["update_pause"] = 2
if state["end_delay"] < 0:
master_games_dic.pop(game_time)
master_games_dic.pop(game_id)
else:
state["end_delay"] -= 1
master_games_dic[game_time][1]["end_delay"] -= 1
master_games_dic[game_id][1]["end_delay"] -= 1
else:
this_game.gamestate_update_full()
@ -144,12 +144,12 @@ def update_loop():
data_to_send = []
template = jinja2.Environment(loader=jinja2.FileSystemLoader('templates')).get_template('game_box.html')
for timestamp in game_states:
for id in game_states:
data_to_send.append({
'timestamp' : timestamp,
'league' : game_states[timestamp]['leagueoruser'] if game_states[timestamp]['is_league'] else '',
'state' : game_states[timestamp],
'html' : template.render(state=game_states[timestamp], timestamp=timestamp)
'timestamp' : id,
'league' : game_states[id]['leagueoruser'] if game_states[id]['is_league'] else '',
'state' : game_states[id],
'html' : template.render(state=game_states[id], timestamp=id)
})
socketio.emit("states_update", data_to_send)

View File

@ -2,6 +2,7 @@ import discord, json, math, os, roman, games, asyncio, random, main_controller,
import database as db
import onomancer as ono
from flask import Flask
from uuid import uuid4
class Command:
@ -779,15 +780,15 @@ async def watch_game(channel, newgame, user = None, league = None):
state_init["is_league"] = False
timestamp = str(time.time() * 1000.0)
ext = "?game="+timestamp
id = str(uuid4())
ext = "?game="+id
if league is not None:
ext += "&league=" + urllib.parse.quote_plus(league)
await channel.send(f"{newgame.teams['away'].name} vs. {newgame.teams['home'].name}, starting at {config()['simmadome_url']+ext}")
gamesarray.append((newgame, channel, user, timestamp))
gamesarray.append((newgame, channel, user, id))
main_controller.master_games_dic[timestamp] = (newgame, state_init, discrim_string)
main_controller.master_games_dic[id] = (newgame, state_init, discrim_string)
def prepare_game(newgame, league = None, weather_name = None):
if weather_name is None:
@ -834,9 +835,9 @@ async def start_tournament_round(channel, tourney, seeding = None):
state_init["title"] = f"0 - 0"
discrim_string = tourney.name
timestamp = str(time.time() * 1000.0 + random.randint(0,3000))
current_games.append((this_game, timestamp))
main_controller.master_games_dic[timestamp] = (this_game, state_init, discrim_string)
id = str(uuid4())
current_games.append((this_game, id))
main_controller.master_games_dic[id] = (this_game, state_init, discrim_string)
ext = "?league=" + urllib.parse.quote_plus(tourney.name)
@ -862,9 +863,9 @@ async def continue_tournament_series(tourney, queue, games_list, wins_in_series)
discrim_string = tourney.name
timestamp = str(time.time() * 1000.0 + random.randint(0,3000))
games_list.append((this_game, timestamp))
main_controller.master_games_dic[timestamp] = (this_game, state_init, discrim_string)
id = str(uuid4())
games_list.append((this_game, id))
main_controller.master_games_dic[id] = (this_game, state_init, discrim_string)
return games_list