auth.py 1.33 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)
Antoine Lima's avatar
Antoine Lima committed
20 21
		self.createPlayerList()
		self.numPlayers = 0
22

23 24 25
	def load(self):
		pass
		
26
	def unload(self):
Antoine Lima's avatar
Antoine Lima committed
27 28
		self.createPlayerList()
		self.numPlayers = 0
29

30
	def other(self, **kwargs):		
31
		for key, val in kwargs.items():
32 33
			if key=='rfid' and 'source' in kwargs:
				side = kwargs['source']
Antoine Lima's avatar
Antoine Lima committed
34
				self.numPlayers += 1
35
				self.addPlayer(side, Player.fromRFID(val))
36

37 38
	def keyPressEvent(self, e):
		if e.key() == Qt.Key_Escape:
39
			self.handleCancel()
40
			
41 42
		elif e.key() == Qt.Key_Return:
			self.handleDone()
43 44 45
			
		elif e.key() == Qt.Key_Left or e.key() == Qt.Key_Right:
			side = Side.Left if e.key() == Qt.Key_Left else Side.Right
Antoine Lima's avatar
Antoine Lima committed
46
			rfid = -(2 + self.numPlayers%5)
47 48
			self.send(type(self), rfid=rfid, source=side)

Antoine Lima's avatar
Antoine Lima committed
49
	def createPlayerList(self):
50 51
		logging.warning('Base function meant to be reimplemented')
	
52
	def handleCancel(self):
53 54
		self.switchModule(modules.MenuModule)

55 56
	def handleDone(self):
		self.send(modules.GameModule, players=self.players)
57
		self.switchModule(modules.GameModule)