auth.py 1.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

import logging

11
from PyQt5.QtCore import Qt
12 13

import modules
14 15
from module import Module
from player import Side, Player, PlayerGuest
16

17 18 19
class AuthModuleBase(Module):
	def __init__(self, parent, widget):
		super().__init__(parent, widget)
20
		self.players = {Side.Left: list(), Side.Right: list()}
21

22 23 24
	def load(self):
		pass
		
25
	def unload(self):
26
		self.players = {Side.Left: list(), Side.Right: list()}
27

28
	def other(self, **kwargs):		
29
		for key, val in kwargs.items():
30 31 32
			if key=='rfid' and 'source' in kwargs:
				side = kwargs['source']
				self.addPlayer(side, Player.fromRFID(val))
33

34 35
	def keyPressEvent(self, e):
		if e.key() == Qt.Key_Escape:
36
			self.handleCancel()
37
			
38 39
		elif e.key() == Qt.Key_Return:
			self.handleDone()
40 41 42 43 44 45 46 47 48
			
		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)
			self.send(type(self), rfid=rfid, source=side)

	def addPlayer(self, side, player):
		logging.warning('Base function meant to be reimplemented')
	
49
	def handleCancel(self):
50 51
		self.switchModule(modules.MenuModule)

52 53
	def handleDone(self):
		self.send(modules.GameModule, players=self.players)
54
		self.switchModule(modules.GameModule)