Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ def get_ip():
table.set_default_field_names()
table.reset_runtime_col_flags()

# check if short ranks should be used
if cfg.get_feature_flag("short_ranks"):
Ranks = SHORT_NUMBERTORANKS
else:
Ranks = NUMBERTORANKS

try:

# loop = asyncio.get_event_loop()
Expand Down Expand Up @@ -475,7 +481,7 @@ def get_ip():
skin = loadouts.get(player["Subject"], "")

# RANK
rankName = NUMBERTORANKS[playerRank["rank"]]
rankName = Ranks[playerRank["rank"]]
if cfg.get_feature_flag("aggregate_rank_rr") and cfg.table.get(
"rr"
):
Expand All @@ -497,10 +503,10 @@ def get_ip():
peakRankAct = ""

# PEAK RANK
peakRank = NUMBERTORANKS[playerRank["peakrank"]] + peakRankAct
peakRank = Ranks[playerRank["peakrank"]] + peakRankAct

# PREVIOUS RANK
previousRank = NUMBERTORANKS[previousPlayerRank["rank"]]
previousRank = Ranks[previousPlayerRank["rank"]]

# LEADERBOARD
leaderboard = playerRank["leaderboard"]
Expand Down Expand Up @@ -731,7 +737,7 @@ def get_ip():
# skin = loadouts[player["Subject"]]

# RANK
rankName = NUMBERTORANKS[playerRank["rank"]]
rankName = Ranks[playerRank["rank"]]
if cfg.get_feature_flag("aggregate_rank_rr") and cfg.table.get(
"rr"
):
Expand All @@ -752,10 +758,10 @@ def get_ip():
if not cfg.get_feature_flag("peak_rank_act"):
peakRankAct = ""
# PEAK RANK
peakRank = NUMBERTORANKS[playerRank["peakrank"]] + peakRankAct
peakRank = Ranks[playerRank["peakrank"]] + peakRankAct

# PREVIOUS RANK
previousRank = NUMBERTORANKS[previousPlayerRank["rank"]]
previousRank = Ranks[previousPlayerRank["rank"]]

# LEADERBOARD
leaderboard = playerRank["leaderboard"]
Expand Down Expand Up @@ -808,6 +814,7 @@ def get_ip():

# bar()
if game_state == "MENUS":
server = ""
already_played_with = []
Players = menu.get_party_members(Requests.puuid, presence)
names = namesClass.get_names_from_puuids(Players)
Expand Down Expand Up @@ -877,7 +884,7 @@ def get_ip():
name = color(names[player["Subject"]], fore=(76, 151, 237))

# RANK
rankName = NUMBERTORANKS[playerRank["rank"]]
rankName = Ranks[playerRank["rank"]]
if cfg.get_feature_flag(
"aggregate_rank_rr"
) and cfg.table.get("rr"):
Expand All @@ -900,11 +907,11 @@ def get_ip():

# PEAK RANK
peakRank = (
NUMBERTORANKS[playerRank["peakrank"]] + peakRankAct
Ranks[playerRank["peakrank"]] + peakRankAct
)

# PREVIOUS RANK
previousRank = NUMBERTORANKS[previousPlayerRank["rank"]]
previousRank = Ranks[previousPlayerRank["rank"]]

# LEADERBOARD
leaderboard = playerRank["leaderboard"]
Expand Down Expand Up @@ -970,7 +977,6 @@ def get_ip():
else:
table.set_title(f"VALORANT status: {title}")

server = ""
if title is not None:
if cfg.get_feature_flag("auto_hide_leaderboard") and (
not is_leaderboard_needed
Expand Down
38 changes: 36 additions & 2 deletions src/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
from colr import color

version = "2.80"
version = "2.90"
enablePrivateLogging = True
hide_names = True
hide_levels = True
Expand Down Expand Up @@ -125,6 +125,37 @@
color('Radiant', fore=(255, 253, 205)),
]

SHORT_NUMBERTORANKS = [
color('UnR', fore=(46, 46, 46)),
color('UnR', fore=(46, 46, 46)),
color('UnR', fore=(46, 46, 46)),
color('Iron 1', fore=(72, 69, 62)),
color('Iron 2', fore=(72, 69, 62)),
color('Iron 3', fore=(72, 69, 62)),
color('Bron 1', fore=(187, 143, 90)),
color('Bron 2', fore=(187, 143, 90)),
color('Bron 3', fore=(187, 143, 90)),
color('Silv 1', fore=(174, 178, 178)),
color('Silv 2', fore=(174, 178, 178)),
color('Silv 3', fore=(174, 178, 178)),
color('Gold 1', fore=(197, 186, 63)),
color('Gold 2', fore=(197, 186, 63)),
color('Gold 3', fore=(197, 186, 63)),
color('Plat 1', fore=(24, 167, 185)),
color('Plat 2', fore=(24, 167, 185)),
color('Plat 3', fore=(24, 167, 185)),
color('Dia 1', fore=(216, 100, 199)),
color('Dia 2', fore=(216, 100, 199)),
color('Dia 3', fore=(216, 100, 199)),
color('Asc 1', fore=(24, 148, 82)),
color('Asc 2', fore=(24, 148, 82)),
color('Asc 3', fore=(24, 148, 82)),
color('Imm 1', fore=(221, 68, 68)),
color('Imm 2', fore=(221, 68, 68)),
color('Imm 3', fore=(221, 68, 68)),
color('Rad', fore=(255, 253, 205)),
]

tierDict = {
"0cebb8be-46d7-c12a-d306-e9907bfc5a25": (0, 149, 135),
"e046854e-406c-37f4-6607-19a9ba8426fc": (241, 184, 45),
Expand Down Expand Up @@ -181,6 +212,9 @@
"peak_rank_act": True,
"discord_rpc": True,
"aggregate_rank_rr": True,
"server_id": False
"server_id": False,
"short_ranks": False,
"truncate_skins": True,
"truncate_names": True
}
}
5 changes: 4 additions & 1 deletion src/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"peak_rank_act": "Peak Rank Act",
"discord_rpc": "Discord Rich Presence",
"aggregate_rank_rr": "Display Rank and Ranked Rating in the same column",
"server_id": "Show Server ID"
"server_id": "Show Server Region ID",
"short_ranks": "Short rank names instead of long ones",
"truncate_skins": "Truncate long skin names if the window is too small",
"truncate_names": "Truncate long player names if the window is too small"
}

weapon_question = lambda config: {
Expand Down
111 changes: 90 additions & 21 deletions src/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,40 @@
from rich.table import Table as RichTable
from rich.console import Console as RichConsole

# define constants for all column headers
# avoids "magic strings"
HEADER_PARTY = "Party"
HEADER_AGENT = "Agent"
HEADER_NAME = "Name"
HEADER_SKIN = "Skin"
HEADER_RANK = "Rank"
HEADER_RR = "RR"
HEADER_PEAK_RANK = "Peak Rank"
HEADER_PREVIOUS_RANK = "Previous Act Rank"
HEADER_PREVIOUS_RANK_SHORT = "Last Act"
HEADER_LEADERBOARD_POS = "Pos."
HEADER_HS_PERCENT = "HS"
HEADER_WINRATE = "WR"
HEADER_KD_RATIO = "KD"
HEADER_LEVEL = "Level"
HEADER_EARNED_RR = "ΔRR"


TABLE_COLUMN_NAMES = Literal[
"Party",
"Agent",
"Name",
"Skin",
"Rank",
"RR",
"Peak Rank",
"Previous Act Rank",
"Pos.",
"HS",
"WR",
"KD",
"Level",
"ΔRR",
HEADER_PARTY,
HEADER_AGENT,
HEADER_NAME,
HEADER_SKIN,
HEADER_RANK,
HEADER_RR,
HEADER_PEAK_RANK,
HEADER_PREVIOUS_RANK,
HEADER_LEADERBOARD_POS,
HEADER_HS_PERCENT,
HEADER_WINRATE,
HEADER_KD_RATIO,
HEADER_LEVEL,
HEADER_EARNED_RR,
]


Expand All @@ -44,10 +63,22 @@ def __init__(self, config, log):
bool(config.table.get("earned_rr", True)), # Earned RR
]
self.runtime_col_flags = self.col_flags[:] # making a copy
self.field_names_candidates = list(get_args(TABLE_COLUMN_NAMES))
if "Skin" in self.field_names_candidates:
skin_index = self.field_names_candidates.index("Skin")

candidates = list(get_args(TABLE_COLUMN_NAMES))

# Set column names based on config
if self.config.get_feature_flag("short_ranks"):
self.field_names_candidates = [
HEADER_PREVIOUS_RANK_SHORT if name == HEADER_PREVIOUS_RANK else name
for name in candidates
]
else:
self.field_names_candidates = candidates

if HEADER_SKIN in self.field_names_candidates:
skin_index = self.field_names_candidates.index(HEADER_SKIN)
self.field_names_candidates[skin_index] = self.config.weapon.capitalize()

self.field_names = [
c for c, i in zip(self.field_names_candidates, self.col_flags) if i
]
Expand Down Expand Up @@ -106,9 +137,13 @@ def apply_rows(self):
def reset_runtime_col_flags(self):
self.runtime_col_flags = self.col_flags[:]

def set_runtime_col_flag(self, field_name: TABLE_COLUMN_NAMES, flag: bool):
index = self.field_names_candidates.index(field_name)
self.runtime_col_flags[index] = flag
def set_runtime_col_flag(self, field_name: str, flag: bool):
try:
index = self.field_names_candidates.index(field_name)
self.runtime_col_flags[index] = flag
except ValueError:
self.log(f"Warning: Attempted to set a flag for a non-existent column: {field_name}")


def display(self):
self.log("rows: " + str(self.rows))
Expand Down Expand Up @@ -151,5 +186,39 @@ def set_columns(self):
if flag
]

skin_column_name = self.config.weapon.capitalize()

# Columns that should never be truncated
static_overflow_fold_columns = {
HEADER_HS_PERCENT,
HEADER_KD_RATIO,
HEADER_LEVEL,
HEADER_LEADERBOARD_POS,
}

# Conditional columns
conditional_columns = {
HEADER_NAME: "truncate_names",
skin_column_name: "truncate_skins",
}

for field in self.fields_to_display:
self.rich_table.add_column(field, justify="center")
# Base properties for all columns
kwargs = {"justify": "center"}
apply_fold = False

# Check if the column should always fold (not truncated)
if field in static_overflow_fold_columns:
apply_fold = True
# Check flags
elif field in conditional_columns:
flag_name = conditional_columns[field]
if not self.config.get_feature_flag(flag_name):
apply_fold = True

# Apply
if apply_fold:
kwargs["overflow"] = "fold"

# Columns without rules use base args
self.rich_table.add_column(field, **kwargs)