started making voices actually display
This commit is contained in:
parent
f7542fe9f9
commit
d49eb98aed
12
games.py
12
games.py
|
@ -1,7 +1,6 @@
|
||||||
import json, random, os, math, jsonpickle
|
import json, random, os, math, jsonpickle, weather
|
||||||
import database as db
|
import database as db
|
||||||
import weather
|
from gametext import base_string, appearance_outcomes, game_strings_base
|
||||||
from gametext import base_string, appearance_outcomes
|
|
||||||
|
|
||||||
data_dir = "data"
|
data_dir = "data"
|
||||||
games_config_file = os.path.join(data_dir, "games_config.json")
|
games_config_file = os.path.join(data_dir, "games_config.json")
|
||||||
|
@ -223,6 +222,7 @@ class game(object):
|
||||||
self.max_innings = config()["default_length"]
|
self.max_innings = config()["default_length"]
|
||||||
self.bases = {1 : None, 2 : None, 3 : None}
|
self.bases = {1 : None, 2 : None, 3 : None}
|
||||||
self.weather = weather.Weather(self)
|
self.weather = weather.Weather(self)
|
||||||
|
self.voice = game_strings_base()
|
||||||
self.current_batter = None
|
self.current_batter = None
|
||||||
|
|
||||||
def occupied_bases(self):
|
def occupied_bases(self):
|
||||||
|
@ -519,8 +519,9 @@ class game(object):
|
||||||
result = self.at_bat()
|
result = self.at_bat()
|
||||||
|
|
||||||
self.weather.activate(self, result) # possibly modify result in-place
|
self.weather.activate(self, result) # possibly modify result in-place
|
||||||
|
self.voice.activate(self.last_update[0], result)
|
||||||
|
|
||||||
if "text_only" in result:
|
if "text_only" in result or "twopart" in result:
|
||||||
return (result, 0)
|
return (result, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -535,6 +536,9 @@ class game(object):
|
||||||
defenders = defense_team.lineup.copy()
|
defenders = defense_team.lineup.copy()
|
||||||
defenders.append(defense_team.pitcher)
|
defenders.append(defense_team.pitcher)
|
||||||
defender = random.choice(defenders) #pitcher can field outs now :3
|
defender = random.choice(defenders) #pitcher can field outs now :3
|
||||||
|
result["defender"] = defender
|
||||||
|
result["defense_team"] = defense_team
|
||||||
|
result["offense_team"] = offense_team
|
||||||
|
|
||||||
if result["ishit"]: #if batter gets a hit:
|
if result["ishit"]: #if batter gets a hit:
|
||||||
self.get_batter().game_stats["hits"] += 1
|
self.get_batter().game_stats["hits"] += 1
|
||||||
|
|
62
gametext.py
62
gametext.py
|
@ -16,11 +16,11 @@ class appearance_outcomes(Enum):
|
||||||
grandslam = "hits a grand slam!"
|
grandslam = "hits a grand slam!"
|
||||||
|
|
||||||
class game_strings_base(object):
|
class game_strings_base(object):
|
||||||
default_format = ("defender",)
|
def __init__(self):
|
||||||
diff_formats = {fielderschoice: ("defender", "base_string")}
|
self.intro_counter = 1
|
||||||
no_formats = [strikeoutlooking, strikeoutswinging, doubleplay, walk, single, double, triple, homerun, grandslam]
|
|
||||||
|
default_format = ("defender",)
|
||||||
|
|
||||||
intro_counter = 1
|
|
||||||
intro_formats = []
|
intro_formats = []
|
||||||
intro = [("🎆", "Play ball!")]
|
intro = [("🎆", "Play ball!")]
|
||||||
|
|
||||||
|
@ -37,21 +37,45 @@ class game_strings_base(object):
|
||||||
triple = "hits a triple!"
|
triple = "hits a triple!"
|
||||||
homerun = "hits a dinger!"
|
homerun = "hits a dinger!"
|
||||||
grandslam = "hits a grand slam!"
|
grandslam = "hits a grand slam!"
|
||||||
|
|
||||||
twoparts = []
|
twoparts = []
|
||||||
|
|
||||||
def check_for_twopart(game, gamestring): #will check just before atbat is generated
|
diff_formats = {fielderschoice: ("defender", "base_string")}
|
||||||
return gamestring in twoparts
|
no_formats = [strikeoutlooking, strikeoutswinging, doubleplay, walk, single, double, triple, homerun, grandslam]
|
||||||
|
|
||||||
|
def activate(self, lastupdate, currentupdate):
|
||||||
|
#try:
|
||||||
|
if "text" in lastupdate and self.check_for_twopart(getattr(self, lastupdate["text"].name)[lastupdate["voiceindex"]]):
|
||||||
|
currentupdate.clear()
|
||||||
|
currentupdate.update({
|
||||||
|
"text": getattr(self, lastupdate["text"].name)[lastupdate["text_index"][1]],
|
||||||
|
"twopart": True,
|
||||||
|
'defender': lastupdate['defender'],
|
||||||
|
'base': lastupdate['base'],
|
||||||
|
'batter': lastupdate['batter'],
|
||||||
|
'runner': lastupdate['runner'],
|
||||||
|
'defense_team': lastupdate['defense_team'],
|
||||||
|
'offense_team': lastupdate['offense_team']
|
||||||
|
})
|
||||||
|
#except:
|
||||||
|
#pass
|
||||||
|
|
||||||
|
def check_for_twopart(self, gamestring):
|
||||||
|
return gamestring in self.twoparts
|
||||||
|
|
||||||
|
def format_gamestring(self, gamestring, game):
|
||||||
|
if gamestring in self.no_formats:
|
||||||
|
return gamestring
|
||||||
|
elif gamestring in self.diff_formats:
|
||||||
|
return gamestring.format(*parse_formats(self.diff_formats[gamestring], game))
|
||||||
|
else:
|
||||||
|
return gamestring.format(*parse_formats(self.default_format, game))
|
||||||
|
|
||||||
class TheGoddesses(game_strings_base):
|
class TheGoddesses(game_strings_base):
|
||||||
diff_formats = {groundout[3][1] : ("batter",),
|
|
||||||
flyout[0][1]: ("batter",), flyout[2][1]: ("defender", "batter"),
|
|
||||||
fielderschoice[0]: ("defender", "fc_out", "batter"), fielderschoice[1]: ("base_string", "fc_out"),
|
|
||||||
doubleplay[0]: ("defender", "defense_team"), doubleplay[1]: ("defender", "defense_team"),
|
|
||||||
sacrifice[0][0]: ("runner",), sacrifice[1]: ("runner",),
|
|
||||||
single[0][1]: ("batter",)}
|
|
||||||
no_formats = strikeoutlooking + strikeoutswinging + walk + single[1:] + [flyout[4][0], sacrifice[0][1]]
|
|
||||||
|
|
||||||
intro_counter = 2
|
def __init__(self):
|
||||||
|
self.intro_counter = 3
|
||||||
|
|
||||||
intro = [("💜", "This game is now blessed 💜\nI'm Sakimori,"), ("🌺", "and i'm xvi! the sim16 goddesses are live and on-site, bringing you today's game~"), ("🎆", "Play ball!!")]
|
intro = [("💜", "This game is now blessed 💜\nI'm Sakimori,"), ("🌺", "and i'm xvi! the sim16 goddesses are live and on-site, bringing you today's game~"), ("🎆", "Play ball!!")]
|
||||||
|
|
||||||
strikeoutlooking = ["watches a slider barely catch the outside corner. Hang up a ꓘ!",
|
strikeoutlooking = ["watches a slider barely catch the outside corner. Hang up a ꓘ!",
|
||||||
|
@ -97,7 +121,15 @@ class TheGoddesses(game_strings_base):
|
||||||
triple = "hits a triple!"
|
triple = "hits a triple!"
|
||||||
homerun = "hits a dinger!"
|
homerun = "hits a dinger!"
|
||||||
grandslam = "hits a grand slam!"
|
grandslam = "hits a grand slam!"
|
||||||
twoparts = [groundout[1], groundout[3], flyout[0], flyout[2], flyout[4], walk[2], single[0]]
|
|
||||||
|
diff_formats = {groundout[3][1] : ("batter",),
|
||||||
|
flyout[0][1]: ("batter",), flyout[2][1]: ("defender", "batter"),
|
||||||
|
fielderschoice[0]: ("defender", "fc_out", "batter"), fielderschoice[1]: ("base_string", "fc_out"),
|
||||||
|
doubleplay[0]: ("defender", "defense_team"), doubleplay[1]: ("defender", "defense_team"),
|
||||||
|
sacrifice[0][0]: ("runner",), sacrifice[1]: ("runner",),
|
||||||
|
single[0][1]: ("batter",)}
|
||||||
|
no_formats = strikeoutlooking + strikeoutswinging + walk + single[1:] + [flyout[4][0], sacrifice[0][1]]
|
||||||
|
twoparts = [groundout[1], groundout[3], flyout[0], flyout[2], flyout[4], walk[2], single[0], sacrifice[0]]
|
||||||
|
|
||||||
|
|
||||||
def parse_formats(format_tuple, game):
|
def parse_formats(format_tuple, game):
|
||||||
|
|
|
@ -3,6 +3,7 @@ from leagues import league_structure
|
||||||
from league_storage import league_exists
|
from league_storage import league_exists
|
||||||
from flask import Flask, url_for, Response, render_template, request, jsonify, send_from_directory, abort
|
from flask import Flask, url_for, Response, render_template, request, jsonify, send_from_directory, abort
|
||||||
from flask_socketio import SocketIO, emit
|
from flask_socketio import SocketIO, emit
|
||||||
|
from random import randrange
|
||||||
import database as db
|
import database as db
|
||||||
|
|
||||||
app = Flask("the-prestige", static_folder='simmadome/build/', subdomain_matching=True)
|
app = Flask("the-prestige", static_folder='simmadome/build/', subdomain_matching=True)
|
||||||
|
@ -142,8 +143,13 @@ def update_loop():
|
||||||
state["home_score"] = this_game.teams["home"].score #update_pause = 0
|
state["home_score"] = this_game.teams["home"].score #update_pause = 0
|
||||||
#victory_lap = False
|
#victory_lap = False
|
||||||
if not this_game.play_has_begun: #weather_emoji
|
if not this_game.play_has_begun: #weather_emoji
|
||||||
state["update_emoji"] = "🎆" #weather_text
|
if state["start_delay"] - this_game.voice.intro_counter > -1:
|
||||||
state["update_text"] = "Play ball!" #they also need a timestamp
|
state["update_emoji"] = "🪑" #weather_text
|
||||||
|
state["update_text"] = "The broadcast booth is being prepared..." #they also need a timestamp
|
||||||
|
else:
|
||||||
|
state["update_emoji"] = this_game.voice.intro[-this_game.voice.intro_counter][0]
|
||||||
|
state["update_text"] = this_game.voice.intro[-this_game.voice.intro_counter][1]
|
||||||
|
this_game.voice.intro_counter -= 1
|
||||||
state["start_delay"] -= 1
|
state["start_delay"] -= 1
|
||||||
|
|
||||||
state["display_top_of_inning"] = state["top_of_inning"]
|
state["display_top_of_inning"] = state["top_of_inning"]
|
||||||
|
@ -218,12 +224,20 @@ def update_loop():
|
||||||
name, out_at_base_string = this_game.last_update[0]['fc_out']
|
name, out_at_base_string = this_game.last_update[0]['fc_out']
|
||||||
updatestring = f"{this_game.last_update[0]['batter']} {this_game.last_update[0]['text'].value.format(name, out_at_base_string)} {this_game.last_update[0]['defender']}{punc}"
|
updatestring = f"{this_game.last_update[0]['batter']} {this_game.last_update[0]['text'].value.format(name, out_at_base_string)} {this_game.last_update[0]['defender']}{punc}"
|
||||||
else:
|
else:
|
||||||
updatestring = f"{this_game.last_update[0]['batter']} {this_game.last_update[0]['text'].value} {this_game.last_update[0]['defender']}{punc}"
|
text_list = getattr(this_game.voice, this_game.last_update[0]["text"].name)
|
||||||
|
voice_index = randrange(0, len(text_list))
|
||||||
|
updatestring = text_list[voice_index]
|
||||||
|
this_game.last_update[0]["voiceindex"] = voice_index
|
||||||
|
if this_game.voice.check_for_twopart(updatestring):
|
||||||
|
updatestring = updatestring[0]
|
||||||
|
this_game.last_update[0]["twopart"] = True
|
||||||
|
updatestring = this_game.voice.format_gamestring(updatestring, this_game)
|
||||||
|
|
||||||
if this_game.last_update[1] > 0:
|
if this_game.last_update[1] > 0:
|
||||||
updatestring += f"{this_game.last_update[1]} runs scored!"
|
updatestring += f"{this_game.last_update[1]} runs scored!"
|
||||||
|
|
||||||
|
|
||||||
state["update_text"] = updatestring
|
state["update_text"] = f"{this_game.last_update[0]['batter']} {updatestring}"
|
||||||
|
|
||||||
this_game.weather.modify_atbat_message(this_game, state)
|
this_game.weather.modify_atbat_message(this_game, state)
|
||||||
|
|
||||||
|
@ -247,4 +261,4 @@ def update_loop():
|
||||||
state["update_pause"] -= 1
|
state["update_pause"] -= 1
|
||||||
|
|
||||||
socketio.emit("states_update", game_states)
|
socketio.emit("states_update", game_states)
|
||||||
time.sleep(8)
|
time.sleep(3)
|
|
@ -1,4 +1,4 @@
|
||||||
import discord, json, math, os, roman, games, asyncio, random, main_controller, threading, time, urllib, leagues, datetime
|
import discord, json, math, os, roman, games, asyncio, random, main_controller, threading, time, urllib, leagues, datetime, gametext
|
||||||
import database as db
|
import database as db
|
||||||
import onomancer as ono
|
import onomancer as ono
|
||||||
from league_storage import league_exists, season_save, season_restart
|
from league_storage import league_exists, season_save, season_restart
|
||||||
|
@ -1684,11 +1684,14 @@ async def watch_game(channel, newgame, user = None, league = None):
|
||||||
|
|
||||||
main_controller.master_games_dic[id] = (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):
|
def prepare_game(newgame, league = None, weather_name = None, voice = None):
|
||||||
if weather_name is None and newgame.weather.name == "Sunny":
|
if weather_name is None and newgame.weather.name == "Sunny":
|
||||||
weathers = weather.all_weathers()
|
weathers = weather.all_weathers()
|
||||||
newgame.weather = weathers[random.choice(list(weathers.keys()))](newgame)
|
newgame.weather = weathers[random.choice(list(weathers.keys()))](newgame)
|
||||||
|
|
||||||
|
if voice is None:
|
||||||
|
newgame.voice = gametext.TheGoddesses()
|
||||||
|
|
||||||
state_init = {
|
state_init = {
|
||||||
"away_name" : newgame.teams['away'].name,
|
"away_name" : newgame.teams['away'].name,
|
||||||
"home_name" : newgame.teams['home'].name,
|
"home_name" : newgame.teams['home'].name,
|
||||||
|
@ -1698,7 +1701,7 @@ def prepare_game(newgame, league = None, weather_name = None):
|
||||||
"victory_lap" : False,
|
"victory_lap" : False,
|
||||||
"weather_emoji" : newgame.weather.emoji,
|
"weather_emoji" : newgame.weather.emoji,
|
||||||
"weather_text" : newgame.weather.name,
|
"weather_text" : newgame.weather.name,
|
||||||
"start_delay" : 3,
|
"start_delay" : 5,
|
||||||
"end_delay" : 9
|
"end_delay" : 9
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue