Converting other functions to use new data storage format.
This commit is contained in:
@@ -23,12 +23,14 @@ def open_highscores_data():
|
|||||||
config = open_highscores_config()
|
config = open_highscores_config()
|
||||||
for boss in config["bosses"]:
|
for boss in config["bosses"]:
|
||||||
data[boss["boss"]] = {"message_id": 0}
|
data[boss["boss"]] = {"message_id": 0}
|
||||||
for category in config["categories"]:
|
boss_categories = {}
|
||||||
|
for key, value in config["categories"].items():
|
||||||
rank_list = []
|
rank_list = []
|
||||||
data[boss["boss"]][category["category"]] = rank_list
|
boss_categories[key] = rank_list
|
||||||
if boss["hardmode"] and category["hardmode"]:
|
if boss["hardmode"] and value["hardmode"]:
|
||||||
rank_list = []
|
rank_list = []
|
||||||
data[boss["boss"]][category["category"] + "_hardmode"] = rank_list
|
boss_categories["Hardmode " + key] = rank_list
|
||||||
|
data[boss["boss"]]["categories"] = boss_categories
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,48 +18,22 @@ def format_highscore_message(boss):
|
|||||||
boss_data = highscores_data[boss_name]
|
boss_data = highscores_data[boss_name]
|
||||||
|
|
||||||
# Gather all categories and add to string
|
# Gather all categories and add to string
|
||||||
for category in highscores_config["categories"]:
|
for key, value in boss_data["categories"].items():
|
||||||
category_name = category["category"]
|
ret_string += f"{key}".ljust(30, " ")
|
||||||
ret_string += f"{category_name}".ljust(30, " ")
|
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
highscore_size = highscores_config["highscore_size"]
|
highscore_size = highscores_config["highscore_size"]
|
||||||
|
|
||||||
# list rankings
|
# 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(highscore_size):
|
||||||
for category in highscores_config["categories"]:
|
for key, value in boss_data["categories"].items():
|
||||||
boss_category_scores = boss_data[category["category"]]
|
if len(value) > i:
|
||||||
if len(boss_category_scores) > i:
|
score = value[i]
|
||||||
score = boss_category_scores[i]
|
ret_string += f"{i+1}: {key} - {score}".ljust(30, " ")
|
||||||
# this is the dumbest solution to a problem iv seen in a while...
|
|
||||||
# I just needed the key and this is the best way to get it without
|
|
||||||
# getting a list of 1 key and parsing that string.
|
|
||||||
for key, value in score.items():
|
|
||||||
ret_string += f"{i+1}: {key} - {value}".ljust(30, " ")
|
|
||||||
else:
|
else:
|
||||||
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
# if boss is hardmode, repeat above for hardmode applicable categories
|
|
||||||
if boss["hardmode"]:
|
|
||||||
for category in highscores_config["categories"]:
|
|
||||||
if category["hardmode"]:
|
|
||||||
category_name = category["category"]
|
|
||||||
ret_string += f"Hardmode {category_name}".ljust(30, " ")
|
|
||||||
|
|
||||||
ret_string += "\n"
|
|
||||||
|
|
||||||
for i in range(highscore_size):
|
|
||||||
for category in highscores_config["categories"]:
|
|
||||||
if category["hardmode"]:
|
|
||||||
hardmode_category = category["category"]
|
|
||||||
boss_category_scores = boss_data[f"{hardmode_category}_hardmode"]
|
|
||||||
if len(boss_category_scores) > i:
|
|
||||||
score = boss_category_scores[i]
|
|
||||||
ret_string += f"{i+1}: {score[0]} - {score[1]}".ljust(30, " ")
|
|
||||||
else:
|
|
||||||
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
|
||||||
ret_string += "\n"
|
|
||||||
return ret_string
|
return ret_string
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user