Commit a09cf6ff authored by Antoine Lima's avatar Antoine Lima

Added league authentification

parent 1c83eca5
......@@ -7,6 +7,7 @@ pyuic5 --import-from=ui ui/game.ui -o ui/
pyuic5 --import-from=ui ui/endgame.ui -o ui/
pyuic5 --import-from=ui ui/options.ui -o ui/
pyuic5 --import-from=ui ui/authquick.ui -o ui/
pyuic5 --import-from=ui ui/authleague.ui -o ui/
pyuic5 --import-from=ui ui/leaderboard.ui -o ui/
# Custom widgets
......@@ -17,18 +17,21 @@ from player import Side, Player, PlayerGuest
class AuthModuleBase(Module):
def __init__(self, parent, widget):
super().__init__(parent, widget)
self.players = {Side.Left: list(), Side.Right: list()}
self.numPlayers = 0
def load(self):
def unload(self):
self.players = {Side.Left: list(), Side.Right: list()}
self.numPlayers = 0
def other(self, **kwargs):
for key, val in kwargs.items():
if key=='rfid' and 'source' in kwargs:
side = kwargs['source']
self.numPlayers += 1
self.addPlayer(side, Player.fromRFID(val))
def keyPressEvent(self, e):
......@@ -40,10 +43,10 @@ class AuthModuleBase(Module):
elif e.key() == Qt.Key_Left or e.key() == Qt.Key_Right:
side = Side.Left if e.key() == Qt.Key_Left else Side.Right
rfid = -2*(side.value+1) - (self.players[side][0]!=PlayerGuest)
rfid = -(2 + self.numPlayers%5)
self.send(type(self), rfid=rfid, source=side)
def addPlayer(self, side, player):
def createPlayerList(self):
logging.warning('Base function meant to be reimplemented')
def handleCancel(self):
......@@ -8,17 +8,55 @@ Created on Wed Apr 18 18:34:40 2018
import logging
from PyQt5.QtWidgets import QAbstractItemView
from module import Module
from ui.authquick_ui import Ui_Form as AuthQuickWidget
from modules.auth import AuthModuleBase
from ui.authleague_ui import Ui_Form as AuthLeagueWidget
class AuthLeagueModule(Module):
from player import Side, PlayerEmpty
class AuthLeagueModule(AuthModuleBase):
def __init__(self, parent):
super().__init__(parent, AuthQuickWidget())
super().__init__(parent, AuthLeagueWidget())
def load(self):
logging.debug('Loading AuthLeagueModule')
self.addPlayer(Side.Left, PlayerEmpty)
def unload(self):
logging.debug('Loading AuthLeagueModule')
def createPlayerList(self):
Duplicates the player list to be the same on both sides.
That way, adding a player on the left or on the right have the exact same effect,
and thus the AuthModuleBase code can remain generic.
l = list()
self.players = {Side.Left: l, Side.Right: l}
def addPlayer(self, side, player):
# Add the player if not already in the list
if all([! for p in self.players[side]]):
if player!=PlayerEmpty:
# Update the left side description
self.ui.lblStat1.setText('{} Victories'.format(player.stats.victories))
self.ui.lblStat2.setText('{} Games Played'.format(player.stats.games_played))
self.ui.lblStat3.setText('{} Goals Scored'.format(player.stats.goals_scored))
if player!=PlayerEmpty:
# Update the right side list, making sure that the added player is showed
self.ui.playersList.addItem('{}. {}'.format(len(self.players[side]),
widgetItem = self.ui.playersList.item(self.ui.playersList.count()-1)
self.ui.playersList.scrollToItem(widgetItem, QAbstractItemView.PositionAtBottom)
def handleDone(self):
......@@ -40,7 +40,11 @@ class AuthQuickModule(AuthModuleBase):
def createPlayerList(self):
self.players = {Side.Left: list(), Side.Right: list()}
def addPlayer(self, side, player):
# If there is a placeholder Guest, clear it from the list, we don't need it anymore
if len(self.players[side])>0 and self.players[side][0]==PlayerGuest:
......@@ -51,6 +51,13 @@ class Player():
player = Player(id, 'Enzo', 'Arobaz')
player.stats.goals_scored = 1
elif id==-10:
player = Player(id, 'Name', '')
player.stats.victories = ''
player.stats.time_played = ''
player.stats.games_played = ''
player.stats.goals_scored = ''
player = Player(id, fname, lname, pic_url)
......@@ -88,3 +95,4 @@ class Stat():
self.goals_scored = 0
PlayerGuest = Player.fromRFID(-1)
PlayerEmpty = Player.fromRFID(-10)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment