Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Set reporting core #629

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified TSH.exe
Binary file not shown.
103,966 changes: 103,965 additions & 1 deletion assets/characters.json

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/GamesManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# I'm gonna use this file to take notes for now

# Process
# Clic sur un boutou au niveau du scoreboard
# Appel de TSHDataManager.instance.ReportGame, avec en paramètre le GameManager
# Selon la réponse, le dialogue appelle GamesManager.report
# Puis utilise self.SetSetGames en récupérant GamesManager.getGames

# This should actually become a SetManager and straight up replace the current system for auto updates (which keeps the current set in the closure of a lambda)
# SetManager would contain
# - The current set id
# - The entrant IDs
# Maybe it would completely manage the autoUpdate timer ? Or maybe it would just keep the information and get called by the autoUpdate timer ?
# In any case, this class would represent the "current set", which could be
# - Nonexistent : The current match is not linked to a specific bracket match. No need for a SetManager.
# - Linked : This object exists and contains all the IDs required to update the score.
# - Updating : Same but also auto-updating

# Voir comment ça interagit avec le stage strike !!!!

class GamesManager:
def __init__(self, p1Id, p2Id) -> None:
self.games = []

def GetGames(self) -> dict:
return self.games

def ReportGame(self, winnerId, p1Id, p2Id):
pass



2 changes: 1 addition & 1 deletion src/TSHAboutWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .StateManager import StateManager
from .TSHGameAssetManager import TSHGameAssetManager
from .TSHPlayerDB import TSHPlayerDB
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager


class TSHAboutWidget(QDialog):
Expand Down
10 changes: 5 additions & 5 deletions src/TSHBracketWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .StateManager import StateManager
from .TSHGameAssetManager import TSHGameAssetManager
from .TSHPlayerDB import TSHPlayerDB
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager
from .TSHPlayerListSlotWidget import TSHPlayerListSlotWidget
from .TSHBracketView import TSHBracketView
from .TSHPlayerList import TSHPlayerList
Expand Down Expand Up @@ -35,9 +35,9 @@ def __init__(self, *args):

StateManager.Set("bracket", {})

TSHTournamentDataProvider.instance.signals.tournament_phases_updated.connect(
TSHTournamentDataManager.instance.signals.tournament_phases_updated.connect(
self.UpdatePhases)
TSHTournamentDataProvider.instance.signals.tournament_phasegroup_updated.connect(
TSHTournamentDataManager.instance.signals.tournament_phasegroup_updated.connect(
self.UpdatePhaseGroup)

self.signals = TSHBracketWidgetSignals()
Expand Down Expand Up @@ -113,7 +113,7 @@ def __init__(self, *args):
updateIcon = QImage("./assets/icons/undo.svg").scaled(24, 24)
self.btRefreshPhase.setIcon(QIcon(QPixmap.fromImage(updateIcon)))
self.btRefreshPhase.clicked.connect(lambda: [
TSHTournamentDataProvider.instance.GetTournamentPhases()
TSHTournamentDataManager.instance.GetTournamentPhases()
])

self.btRefreshPhaseGroup: QPushButton = self.findChild(
Expand Down Expand Up @@ -243,7 +243,7 @@ def PhaseGroupChanged(self):
StateManager.Set("bracket.phaseGroup", "")

if self.phaseGroupSelection.currentData() != None:
TSHTournamentDataProvider.instance.GetTournamentPhaseGroup(
TSHTournamentDataManager.instance.GetTournamentPhaseGroup(
self.phaseGroupSelection.currentData().get("id"))

def RebuildBracket(self, playerNumber, seedMap=None, customSeeding=False):
Expand Down
4 changes: 3 additions & 1 deletion src/TSHGameAssetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def run(self):
try:
url = 'https://api.start.gg/characters'
r = requests.get(url, allow_redirects=True)
r_json = json.loads(r.text)
r_json = json.dumps(r_json, indent=2)

open('./assets/characters.json.tmp', 'wb').write(r.content)
open('./assets/characters.json.tmp', 'wt', encoding="utf-8").write(r_json)

try:
# Test if downloaded JSON is valid
Expand Down
4 changes: 2 additions & 2 deletions src/TSHPlayerList.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .StateManager import StateManager
from .TSHGameAssetManager import TSHGameAssetManager
from .TSHPlayerDB import TSHPlayerDB
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager


class TSHPlayerListWidgetSignals(QObject):
Expand Down Expand Up @@ -57,7 +57,7 @@ def ChildDataChangedEmit(self):
self.signals.DataChanged.emit()

def LoadFromStandingsClicked(self):
TSHTournamentDataProvider.instance.GetStandings(
TSHTournamentDataManager.instance.GetStandings(
self.slotNumber.value(), self.signals.UpdateData)

def LoadFromStandings(self, data):
Expand Down
2 changes: 1 addition & 1 deletion src/TSHPlayerListSlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .StateManager import StateManager
from .TSHGameAssetManager import TSHGameAssetManager
from .TSHPlayerDB import TSHPlayerDB
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager


class TSHPlayerListSlotWidgetSignals(QObject):
Expand Down
4 changes: 2 additions & 2 deletions src/TSHPlayerListWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .StateManager import StateManager
from .TSHGameAssetManager import TSHGameAssetManager
from .TSHPlayerDB import TSHPlayerDB
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager
from .TSHPlayerList import TSHPlayerList


Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self, *args, base="player_list"):
StateManager.ReleaseSaving()

def LoadFromStandingsClicked(self):
TSHTournamentDataProvider.instance.GetStandings(
TSHTournamentDataManager.instance.GetStandings(
self.slotNumber.value(), self.signals.UpdateData)

def LoadFromStandings(self, data):
Expand Down
2 changes: 1 addition & 1 deletion src/TSHScoreboardPlayerWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .StateManager import StateManager
from .TSHGameAssetManager import TSHGameAssetManager
from .TSHPlayerDB import TSHPlayerDB
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager
from .Helpers.TSHLocaleHelper import TSHLocaleHelper
from .Workers import Worker
import threading
Expand Down
2 changes: 1 addition & 1 deletion src/TSHScoreboardStageWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def run(self):
)
rulesets = deep_get(data, "entities.ruleset")
open('./assets/rulesets.json',
'w').write(json.dumps(rulesets))
'w').write(json.dumps(rulesets, indent=4))
self.parent().startggRulesets = rulesets
logger.info("startgg Rulesets downloaded from startgg")
self.parent().signals.rulesets_changed.emit()
Expand Down
46 changes: 23 additions & 23 deletions src/TSHScoreboardWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .TSHScoreboardPlayerWidget import TSHScoreboardPlayerWidget
from .SettingsManager import SettingsManager
from .StateManager import StateManager
from .TSHTournamentDataProvider import TSHTournamentDataProvider
from .TSHTournamentDataProvider import TSHTournamentDataManager
from .TSHStatsUtil import TSHStatsUtil
from .TSHHotkeys import TSHHotkeys

Expand Down Expand Up @@ -207,7 +207,7 @@ def __init__(self, scoreboardNumber=1, *args):
hbox.addWidget(self.btLoadStreamSet)
self.btLoadStreamSet.clicked.connect(
self.signals.StreamSetSelection.emit)
TSHTournamentDataProvider.instance.signals.twitch_username_updated.connect(
TSHTournamentDataManager.instance.signals.twitch_username_updated.connect(
self.UpdateStreamButton)

self.btLoadStreamSetOptions = QPushButton()
Expand All @@ -229,9 +229,9 @@ def __init__(self, scoreboardNumber=1, *args):
self.btLoadPlayerSet.clicked.connect(
self.signals.UserSetSelection.emit)
hbox.addWidget(self.btLoadPlayerSet)
TSHTournamentDataProvider.instance.signals.user_updated.connect(
TSHTournamentDataManager.instance.signals.user_updated.connect(
self.UpdateUserSetButton)
TSHTournamentDataProvider.instance.signals.tournament_changed.connect(
TSHTournamentDataManager.instance.signals.tournament_changed.connect(
self.UpdateUserSetButton)

self.btLoadPlayerSetOptions = QPushButton()
Expand All @@ -243,9 +243,9 @@ def __init__(self, scoreboardNumber=1, *args):
self.LoadUserSetOptionsClicked)
hbox.addWidget(self.btLoadPlayerSetOptions)

TSHTournamentDataProvider.instance.signals.tournament_changed.connect(
TSHTournamentDataManager.instance.signals.tournament_changed.connect(
self.UpdateBottomButtons)
TSHTournamentDataProvider.instance.signals.tournament_changed.emit()
TSHTournamentDataManager.instance.signals.tournament_changed.emit()

self.selectSetWindow = TSHSelectSetWindow(self)

Expand Down Expand Up @@ -465,9 +465,9 @@ def ToggleElements(self, action: QAction, elements):
pw.findChild(QWidget, element).setVisible(action.isChecked())

def UpdateBottomButtons(self):
if TSHTournamentDataProvider.instance.provider and TSHTournamentDataProvider.instance.provider.url:
if TSHTournamentDataManager.instance.provider and TSHTournamentDataManager.instance.provider.url:
self.btSelectSet.setText(
QApplication.translate("app", "Load set from {0}").format(TSHTournamentDataProvider.instance.provider.url))
QApplication.translate("app", "Load set from {0}").format(TSHTournamentDataManager.instance.provider.url))
self.btSelectSet.setEnabled(True)
self.btLoadStreamSet.setEnabled(True)
if self.scoreboardNumber <= 1:
Expand Down Expand Up @@ -633,9 +633,9 @@ def ResetScore(self):
self.scoreColumn.findChild(QSpinBox, "score_right").setValue(0)

def AutoUpdate(self, data):
TSHTournamentDataProvider.instance.GetMatch(
TSHTournamentDataManager.instance.GetMatch(
self, data.get("id"), overwrite=False)
TSHTournamentDataProvider.instance.GetStreamQueue()
TSHTournamentDataManager.instance.GetStreamQueue()

def NewSetSelected(self, data):
if not SettingsManager.Get("general.disable_autoupdate", False):
Expand All @@ -662,7 +662,7 @@ def NewSetSelected(self, data):
StateManager.BlockSaving()

try:
TSHTournamentDataProvider.instance.GetStreamQueue()
TSHTournamentDataManager.instance.GetStreamQueue()

if data.get("id") != None and data.get("id") != self.lastSetSelected:
StateManager.Unset(f'score.{self.scoreboardNumber}.stage_strike')
Expand All @@ -678,7 +678,7 @@ def NewSetSelected(self, data):
StateManager.Set(
f"score.{self.scoreboardNumber}.teamsSwapped", self.teamsSwapped)

TSHTournamentDataProvider.instance.GetMatch(
TSHTournamentDataManager.instance.GetMatch(
self, data["id"], overwrite=True)

if not SettingsManager.Get("general.disable_autoupdate", False):
Expand All @@ -687,12 +687,12 @@ def NewSetSelected(self, data):

if data.get("auto_update") == "stream":
self.autoUpdateTimer.timeout.connect(
lambda setId=data: TSHTournamentDataProvider.instance.LoadStreamSet(self, SettingsManager.Get("twitch_username")))
lambda setId=data: TSHTournamentDataManager.instance.LoadStreamSet(self, SettingsManager.Get("twitch_username")))

if data.get("auto_update") == "user":
self.autoUpdateTimer.timeout.connect(
lambda setId=data: TSHTournamentDataProvider.instance.LoadUserSet(
self, SettingsManager.Get(TSHTournamentDataProvider.instance.provider.name+"_user")))
lambda setId=data: TSHTournamentDataManager.instance.LoadUserSet(
self, SettingsManager.Get(TSHTournamentDataManager.instance.provider.name+"_user")))
finally:
for p in self.playerWidgets:
p.dataLock.release()
Expand All @@ -718,11 +718,11 @@ def LoadSetClicked(self):

def LoadStreamSetClicked(self):
self.lastSetSelected = None
TSHTournamentDataProvider.instance.LoadStreamSet(
TSHTournamentDataManager.instance.LoadStreamSet(
self, SettingsManager.Get("twitch_username"))

def LoadStreamSetOptionsClicked(self):
TSHTournamentDataProvider.instance.SetTwitchUsername(self)
TSHTournamentDataManager.instance.SetTwitchUsername(self)

def UpdateStreamButton(self):
if SettingsManager.Get("twitch_username"):
Expand All @@ -738,8 +738,8 @@ def UpdateStreamButton(self):

def UpdateUserSetButton(self):
provider = None
if TSHTournamentDataProvider.instance.provider:
provider = TSHTournamentDataProvider.instance.provider.name
if TSHTournamentDataManager.instance.provider:
provider = TSHTournamentDataManager.instance.provider.name
if provider and SettingsManager.Get(provider+"_user"):
self.btLoadPlayerSet.setText(
QApplication.translate("app", "Load user set ({0})").format(SettingsManager.Get(provider+'_user')))
Expand All @@ -752,14 +752,14 @@ def UpdateUserSetButton(self):
def LoadUserSetClicked(self):
self.lastSetSelected = None
provider = None
if TSHTournamentDataProvider.instance.provider:
provider = TSHTournamentDataProvider.instance.provider.name
if TSHTournamentDataManager.instance.provider:
provider = TSHTournamentDataManager.instance.provider.name
if provider and SettingsManager.Get(provider+"_user"):
TSHTournamentDataProvider.instance.LoadUserSet(
TSHTournamentDataManager.instance.LoadUserSet(
self, SettingsManager.Get(provider+"_user"))

def LoadUserSetOptionsClicked(self):
TSHTournamentDataProvider.instance.SetUserAccount(self)
TSHTournamentDataManager.instance.SetUserAccount(self)

# Used for score change commands
# Change <team>(0, 1) score by <change>(+X, -X)
Expand Down
6 changes: 3 additions & 3 deletions src/TSHSelectSetWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from qtpy.QtCore import *
from loguru import logger

from src.TSHTournamentDataProvider import TSHTournamentDataProvider
from src.TSHTournamentDataProvider import TSHTournamentDataManager


class TSHSelectSetWindow(QDialog):
Expand Down Expand Up @@ -73,7 +73,7 @@ def filterList(text):
qr.moveCenter(cp)
self.move(qr.topLeft())

TSHTournamentDataProvider.instance.signals.get_sets_finished.connect(
TSHTournamentDataManager.instance.signals.get_sets_finished.connect(
self.SetSets)

def eventFilter(self, obj, event):
Expand All @@ -84,7 +84,7 @@ def eventFilter(self, obj, event):

def LoadSets(self):
self.proxyModel.setSourceModel(QStandardItemModel())
TSHTournamentDataProvider.instance.LoadSets(
TSHTournamentDataManager.instance.LoadSets(
showFinished=self.showFinished.isChecked())

def SetSets(self, sets):
Expand Down
Loading