Add support for playersinks db

Select a default skin depending on the player tag and the character
name.
master
Lertsenem 2020-07-20 18:44:49 +02:00
parent 4f115740b5
commit 7bd09dc959
2 changed files with 34 additions and 11 deletions

View File

@ -2,6 +2,7 @@ import argparse
import configparser
import datetime
import html
import json
import logging
import os, os.path
import sys
@ -50,7 +51,7 @@ def main():
init_parser.add_argument(
"--imgdir", "-ID",
default = "res/ssbu",
default = "res/ssbu/chars",
help = "The directory we should download the resources to",
)
@ -66,9 +67,15 @@ def main():
)
top8_parser.add_argument(
"--imgdir", "-ID",
default = "res/ssbu",
default = "res/ssbu/chars",
help = "The directories containing images",
)
top8_parser.add_argument(
"--playerskinsdb", "-PD",
default = "res/ssbu/playerskins/lyon.json",
help = "A CSV file matching player tags, characters and " \
"preferred skins",
)
top8_parser.add_argument(
"--templatesdir", "-TD",
default = "templates",
@ -165,6 +172,13 @@ def main():
# -------------------------------------------------------------------------
if args.command == "top8":
# Initialize PLAYERSKINS db
log.debug("loading playerskins db from '{}'" \
.format(args.playerskinsdb))
with open(args.playerskinsdb, "r") as f:
smashgg.PLAYERSKINS = json.load(f)
#
tournament = None
top_players = {}
@ -255,7 +269,6 @@ def main():
"dir_root": args.rootdir,
"dir_res_ssbu": os.path.join(
args.imgdir,
"chars",
),
}

View File

@ -15,15 +15,16 @@ API_URL = "{scheme}://{host}/{endpoint}".format(
endpoint = API_ENDPOINT,
)
CHARACTERS = { c.smashggid : c.name for c in characters_ssbu.EVERYONE }
PLAYERSKINS = {}
# =============================================================================
# -----------------------------------------------------------------------------
class Player():
"""A Player, as registered by the smash.gg API, and their characters
choices and placement in a tournament"""
# TODO fill missing chars
CHARACTERS = { c.smashggid : c.name for c in characters_ssbu.EVERYONE }
# -------------------------------------------------------------------------
def __init__(
self,
@ -49,11 +50,20 @@ class Player():
# -------------------------------------------------------------------------
def add_character_selection(self, character, win):
try:
character = (self.CHARACTERS[character], "00")
except KeyError:
if type(character) != tuple:
character = (character, "00")
if type(character) != tuple:
try:
charname = CHARACTERS[character]
except KeyError:
charname = character # Unknown char -> sgg id
try:
skin = PLAYERSKINS[self.gamerTag.lower()][charname]
except KeyError:
skin = "00" # default skin
character = ( charname, skin )
try:
self.chars[character] += ( 1.01 if win else 1.00 )