This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerQueue.py
62 lines (51 loc) · 1.79 KB
/
PlayerQueue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class PlayerQueue:
queue = {}
empty = True
def get(self):
"""Retrieves all players currently in the queue and clears the queue
Returns:
dict: Contains all queued players
"""
q = self.queue.copy()
self.queue = {}
self.empty = True
return q
def updateEmpty(self):
"""Updates the empty variable based on amount of queued players
"""
self.empty = len(self.queue) == 0
def delete(self, name: str):
"""Removes the player by given argument from the playerqueue
Args:
name (str): Name of the player to remove
"""
for i,element in enumerate(self.queue):
if element[0] == name:
del self.queue[i]
self.updateEmpty()
def add(self, name: str, rank = "UNK", stars = -1, origin = "UNK"):
"""Adds a player to the playerqueue by name, rank and stars
Args:
name (str): The name of the player
rank (str): The rank of the player
stars (int): The amount of stars for the player
"""
if not name in self.queue:
info = {"rank": rank, "stars": stars, "origin": origin}
else:
info = self.queue[name]
rank = rank if rank != "UNK" else info.get("rank")
stars = stars if stars != -1 else info.get("stars")
origin = origin if origin != "UNK" else info.get("origin")
info = {
"rank": rank,
"stars": stars,
"origin": origin
}
self.queue[name] = info
self.updateEmpty()
def reset(self):
"""Resets the list maintained
"""
self.queue = {}
self.updateEmpty()