Moved table size to table class. Edited table constructor.
This commit is contained in:
@@ -18,7 +18,6 @@ class Guild:
|
|||||||
"""
|
"""
|
||||||
self._guild_id: int = guild_id
|
self._guild_id: int = guild_id
|
||||||
self._highscore_channel_id: int = 0
|
self._highscore_channel_id: int = 0
|
||||||
self._highscore_size: int = 3
|
|
||||||
self._submission_channel_id: int = 0
|
self._submission_channel_id: int = 0
|
||||||
self._table_map: dict = {}
|
self._table_map: dict = {}
|
||||||
self._username_length: int = 12
|
self._username_length: int = 12
|
||||||
@@ -47,7 +46,6 @@ class Guild:
|
|||||||
"""
|
"""
|
||||||
guild = cls(guild_id)
|
guild = cls(guild_id)
|
||||||
guild.highscore_channel = data["highscore_channel_id"]
|
guild.highscore_channel = data["highscore_channel_id"]
|
||||||
guild.highscore_size = data["highscore_size"]
|
|
||||||
guild.submission_channel = data["submission_channel_id"]
|
guild.submission_channel = data["submission_channel_id"]
|
||||||
guild.username_length = data["username_length"]
|
guild.username_length = data["username_length"]
|
||||||
guild.verification_channel = data["verification_channel_id"]
|
guild.verification_channel = data["verification_channel_id"]
|
||||||
@@ -88,29 +86,6 @@ class Guild:
|
|||||||
"""
|
"""
|
||||||
self._highscore_channel_id = channel
|
self._highscore_channel_id = channel
|
||||||
|
|
||||||
@property
|
|
||||||
def highscore_size(self) -> int:
|
|
||||||
"""
|
|
||||||
Getter for highscore size. How many ranks to print in each highscore message.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
int: highscore size
|
|
||||||
"""
|
|
||||||
return self._highscore_size
|
|
||||||
|
|
||||||
@highscore_size.setter
|
|
||||||
def highscore_size(self, size: int) -> None:
|
|
||||||
"""
|
|
||||||
Setter for highscore size.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
size (int): highscore size
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
_type_: _description_
|
|
||||||
"""
|
|
||||||
self._highscore_size = size
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def submission_channel(self) -> int:
|
def submission_channel(self) -> int:
|
||||||
"""
|
"""
|
||||||
@@ -216,7 +191,6 @@ class Guild:
|
|||||||
data: dict = {}
|
data: dict = {}
|
||||||
|
|
||||||
data["highscore_channel_id"] = self.highscore_channel
|
data["highscore_channel_id"] = self.highscore_channel
|
||||||
data["highscore_size"] = self.highscore_size
|
|
||||||
data["submission_channel_id"] = self.submission_channel
|
data["submission_channel_id"] = self.submission_channel
|
||||||
data["tables"] = {}
|
data["tables"] = {}
|
||||||
data["username_length"] = self.username_length
|
data["username_length"] = self.username_length
|
||||||
|
|||||||
+33
-9
@@ -8,18 +8,18 @@ from data.category import Category # pylint: disable=import-error
|
|||||||
class Table:
|
class Table:
|
||||||
"""Stores a table's information a list of categories."""
|
"""Stores a table's information a list of categories."""
|
||||||
|
|
||||||
def __init__(self, name: str, message_id: int, category_map: dict) -> None:
|
def __init__(self, name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Default constructor for Table class.
|
Default constructor for Table class.
|
||||||
|
Creates object and fills out class variables with defaults.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Table's name
|
name (str): Table's name
|
||||||
message_id (int): message id of message table is displayed on in discord
|
|
||||||
category_map (dict): map of Categories
|
|
||||||
"""
|
"""
|
||||||
self._name: str = name
|
self._name: str = name
|
||||||
self._message_id: int = message_id
|
self._message_id: int = 0
|
||||||
self._categories_map: dict = category_map
|
self._categories_map: dict = {}
|
||||||
|
self._size = 3
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""
|
"""
|
||||||
@@ -42,13 +42,16 @@ class Table:
|
|||||||
Returns:
|
Returns:
|
||||||
Table: Populated Table object
|
Table: Populated Table object
|
||||||
"""
|
"""
|
||||||
message_id = data["message_id"]
|
table = cls(table_name)
|
||||||
category_map = {}
|
|
||||||
|
table.message_id = data["message_id"]
|
||||||
|
table.size = data["table_size"]
|
||||||
|
|
||||||
for cat_name, cat in data["categories"].items():
|
for cat_name, cat in data["categories"].items():
|
||||||
category = Category.from_dict(cat_name, cat)
|
category = Category.from_dict(cat_name, cat)
|
||||||
category_map[cat_name] = category
|
table.add_category(category)
|
||||||
|
|
||||||
return cls(table_name, message_id, category_map)
|
return table
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def categories(self) -> "list[Category]":
|
def categories(self) -> "list[Category]":
|
||||||
@@ -90,6 +93,26 @@ class Table:
|
|||||||
"""
|
"""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self) -> int:
|
||||||
|
"""
|
||||||
|
Getter for size of table.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Size of table
|
||||||
|
"""
|
||||||
|
return self._size
|
||||||
|
|
||||||
|
@size.setter
|
||||||
|
def size(self, size: int) -> None:
|
||||||
|
"""
|
||||||
|
Setter for size of table.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
size (int): New size of table
|
||||||
|
"""
|
||||||
|
self._size = size
|
||||||
|
|
||||||
def add_category(self, category: Category) -> None:
|
def add_category(self, category: Category) -> None:
|
||||||
"""
|
"""
|
||||||
Adds a Category to categories map. Shouldn't exist already.
|
Adds a Category to categories map. Shouldn't exist already.
|
||||||
@@ -124,6 +147,7 @@ class Table:
|
|||||||
"""
|
"""
|
||||||
data = {}
|
data = {}
|
||||||
data["message_id"] = self.message_id
|
data["message_id"] = self.message_id
|
||||||
|
data["table_size"] = self.size
|
||||||
data["categories"] = {}
|
data["categories"] = {}
|
||||||
for category in self.categories:
|
for category in self.categories:
|
||||||
data["categories"][category.name] = category.to_dict()
|
data["categories"][category.name] = category.to_dict()
|
||||||
|
|||||||
@@ -330,5 +330,6 @@
|
|||||||
"ascending": true,
|
"ascending": true,
|
||||||
"is_time_record": false
|
"is_time_record": false
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
"table_size": 3
|
||||||
|
}
|
||||||
+1
-3
@@ -30,10 +30,8 @@ def format_highscore_message(guild: Guild, table: Table) -> str:
|
|||||||
ret_string += f"{category.name}".ljust(26, " ")
|
ret_string += f"{category.name}".ljust(26, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
highscore_size = guild.highscore_size
|
|
||||||
|
|
||||||
# list rankings in a single line. Start with first place for each category and then continue
|
# list rankings in a single line. Start with first place for each category and then continue
|
||||||
for i in range(highscore_size):
|
for i in range(table.size):
|
||||||
for category in table.categories:
|
for category in table.categories:
|
||||||
if len(category.scores) > i:
|
if len(category.scores) > i:
|
||||||
# pad username to max length.
|
# pad username to max length.
|
||||||
|
|||||||
Reference in New Issue
Block a user