Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show in the console two or more weapons skins using the config #141 #164

Closed
wants to merge 10 commits into from
20 changes: 11 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def program_exit(status: int): # so we don't need to import the entire sys modu
message="Do you want to run vRY now?", default=True
).execute()
if run_app:
os.system('mode 150,35')
os.system('mode 175,35')
os.system('cls')
else:
os._exit(0)
else:
os.system('mode 150,35')
os.system('mode 175,35')
os.system('cls')
except Exception as e:
print("Something went wrong while running configurator!")
Expand Down Expand Up @@ -248,7 +248,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu
server = "New server"
presences.wait_for_presence(namesClass.get_players_puuid(Players))
names = namesClass.get_names_from_puuids(Players)
loadouts = loadoutsClass.get_match_loadouts(coregame.get_coregame_match_id(), Players, cfg.weapon, valoApiSkins, names, state="game")
loadouts = loadoutsClass.get_match_loadouts(coregame.get_coregame_match_id(), Players, cfg.weapons, valoApiSkins, names, cfg, state="game")
# with alive_bar(total=len(Players), title='Fetching Players', bar='classic2') as bar:
isRange = False
playersLoaded = 1
Expand Down Expand Up @@ -378,7 +378,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu
# views = get_views(names[player["Subject"]])

# skin
skin = loadouts[player["Subject"]]
skins = loadouts[player["Subject"]]

# RANK
rankName = NUMBERTORANKS[playerRank["rank"]]
Expand Down Expand Up @@ -415,7 +415,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu
agent,
name,
# views,
skin,
*[skins[weapon] for weapon in cfg.weapons],
rankName,
rr,
peakRank,
Expand Down Expand Up @@ -574,7 +574,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu
agent,
name,
# views,
"",
*["" for _ in cfg.weapons],
rankName,
rr,
peakRank,
Expand Down Expand Up @@ -664,7 +664,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu
table.add_row_table([party_icon,
agent,
name,
"",
*["" for weapon in cfg.weapons],
rankName,
rr,
peakRank,
Expand All @@ -690,8 +690,10 @@ def program_exit(status: int): # so we don't need to import the entire sys modu

if game_state == "MENUS":
table.set_runtime_col_flag('Party', False)
table.set_runtime_col_flag('Agent',False)
table.set_runtime_col_flag('Skin',False)
table.set_runtime_col_flag('Agent', False)
for weapon in cfg.weapons:
table.set_runtime_col_flag(weapon, False)


if game_state == "INGAME":
if isRange:
Expand Down
31 changes: 19 additions & 12 deletions src/Loadouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, Requests, log, colors, Server, current_map):
self.Server = Server
self.current_map = current_map

def get_match_loadouts(self, match_id, players, weaponChoose, valoApiSkins, names, state="game"):
def get_match_loadouts(self, match_id, players, weaponChoose, valoApiSkins, names, cfg, state="game"):
playersBackup = players
weaponLists = {}
valApiWeapons = requests.get("https://valorant-api.com/v1/weapons").json()
Expand All @@ -34,18 +34,25 @@ def get_match_loadouts(self, match_id, players, weaponChoose, valoApiSkins, name
inv = PlayerInventorys["Loadouts"][invindex]
if state == "game":
inv = inv["Loadout"]

weaponLists[players[player]["Subject"]] = {}
for weapon in valApiWeapons["data"]:
if weapon["displayName"].lower() == weaponChoose.lower():
skin_id = \
inv["Items"][weapon["uuid"].lower()]["Sockets"]["bcef87d6-209b-46c6-8b19-fbe40bd95abc"]["Item"][
"ID"]
for skin in valoApiSkins.json()["data"]:
if skin_id.lower() == skin["uuid"].lower():
rgb_color = self.colors.get_rgb_color_from_skin(skin["uuid"].lower(), valoApiSkins)
# if rgb_color is not None:
weaponLists.update({players[player]["Subject"]: color(skin["displayName"], fore=rgb_color)})
# else:
# weaponLists.update({player["Subject"]: color(skin["Name"], fore=rgb_color)})
if weapon["displayName"].lower() not in [weapon.lower() for weapon in weaponChoose]:
continue
skin_id = \
inv["Items"][weapon["uuid"].lower()]["Sockets"]["bcef87d6-209b-46c6-8b19-fbe40bd95abc"]["Item"]["ID"]

for skin in valoApiSkins.json()["data"]:
if skin_id.lower() != skin["uuid"].lower():
continue
rgb_color = self.colors.get_rgb_color_from_skin(skin["uuid"].lower(), valoApiSkins)
# if rgb_color is not None:
skin_name = " ".join(skin["displayName"].split(" ")[0:-1])

weaponLists[players[player]["Subject"]][weapon["displayName"]] = (color(skin_name, fore=rgb_color))
# else:
# weaponLists.update({player["Subject"]: color(skin["Name"], fore=rgb_color)})

final_json = self.convertLoadoutToJsonArray(PlayerInventorys, playersBackup, state, names)
self.Server.send_message(json.dumps(final_json))
return weaponLists
Expand Down
22 changes: 13 additions & 9 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ def __init__(self, log):

self.log(f"got cooldown with value '{self.cooldown}'")

if not self.weapon_check(config["weapon"]):
self.weapon = "vandal" # if the user manually entered a wrong name into the config file, this will be the default until changed by the user.
else:
self.weapon = config["weapon"]
weapons = [weapon.strip() for weapon in config["weapons"].split(",")]
if not self.weapon_checks(weapons):
self.weapons = ["vandal", "phantom"] # if the user manually entered a wrong name into the config file, this will be the default until changed by the user.
self.log(f"Invalid weapon name in config, defaulting to vandal")
else:
self.weapons = weapons

def get_feature_flag(self,key):
return self.__dict__.get("flags",DEFAULT_CONFIG["flags"]).get(key,DEFAULT_CONFIG["flags"][key])
Expand All @@ -71,8 +73,10 @@ def config_dialog(self, fileToWrite: TextIOWrapper):
json.dump(jsonToWrite, fileToWrite, indent=4)
return jsonToWrite

def weapon_check(self, name):
if name in [weapon["displayName"] for weapon in requests.get("https://valorant-api.com/v1/weapons").json()["data"]]:
return True
else:
return False
def weapon_checks(self, names):
weapon_data = requests.get("https://valorant-api.com/v1/weapons").json()["data"]
weapon_names = [weapon["displayName"] for weapon in weapon_data]
for name in names:
if name not in weapon_names:
return False
return True
16 changes: 14 additions & 2 deletions src/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def configure():
"Exit Configurator"
]

def weapon_prompt(cfg):
cfg |= prompt(weapon_amount_question(config=cfg))
weapons = []
for i in range(cfg["weapon_amount"]):
cfg |= prompt(weapon_question(config=cfg, index=i))
weapons.append(cfg[f"weapon"])
cfg["weapons"] = ", ".join(weapons)
return cfg

changed_config = {}
while True:
loop_config = user_config | changed_config
Expand All @@ -45,17 +54,20 @@ def configure():
).execute()

if choice is menu_choices[0]:
changed_config |= prompt([weapon_question(config=loop_config)])
changed_config |= weapon_prompt(loop_config)
elif choice is menu_choices[1]:
changed_config |= prompt([table_question(config=loop_config)])
elif choice is menu_choices[2]:
changed_config |= prompt([flags_question(config=loop_config)])
elif choice is menu_choices[4]:
changed_config |= weapon_prompt(loop_config)
changed_config |= prompt(basic_questions(config=loop_config))
elif choice is menu_choices[5]:
changed_config |= prompt(advance_questions(config=loop_config))
changed_config |= weapon_prompt(loop_config)
changed_config |= prompt(basic_questions(config=loop_config))
elif choice is menu_choices[7]:
proceed=True
proceed = True
break
else:
proceed = (not len(changed_config.keys()) > 0) or inquirer.confirm(
Expand Down
50 changes: 26 additions & 24 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,30 @@
]

DEFAULT_CONFIG = {
"cooldown": 10,
"port": 1100,
"weapon": "Vandal",
"chat_limit": 5,
"table": {
"skin": True,
"rr": True,
"peakrank": True,
"previousrank" : False,
"leaderboard": True,
"headshot_percent": True,
"winrate": True,
"kd": False,
"level": True
},
"flags": {
"last_played": True,
"auto_hide_leaderboard": True,
"pre_cls": False,
"game_chat": True,
"peak_rank_act": True,
"discord_rpc": True,
"aggregate_rank_rr": True
}
"cooldown": 10,
"port": 1100,
"weapon_amount": 2,
"weapons": "Vandal, Phantom",
"chat_limit": 5,
"hide_skin_weapon_suffix": True,
"table": {
"skin": True,
"rr": True,
"peakrank": True,
"previousrank" : False,
"leaderboard": True,
"headshot_percent": True,
"winrate": True,
"kd": False,
"level": True
},
"flags": {
"last_played": True,
"auto_hide_leaderboard": True,
"pre_cls": False,
"game_chat": True,
"peak_rank_act": True,
"discord_rpc": True,
"aggregate_rank_rr": True
}
}
26 changes: 17 additions & 9 deletions src/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@
"aggregate_rank_rr": "Display Rank and Ranked Rating in the same column"
}

weapon_question = lambda config: {
"type": "fuzzy",
"name": "weapon",
"message": "Please select a weapon to show skin for:",
"default": config.get("weapon","Vandal"),
"choices": WEAPONS,
}
weapon_amount_question = lambda config: {
"type": "number",
"name": "weapon_amount",
"message": "Please select the amount of weapons to display:",
"min_allowed": 0,
"max_allowed": 100,
"filter": lambda ans: int(ans)
}

weapon_question = lambda config, index: {
"type": "fuzzy",
"name": f"weapon",
"message": f"Please select a weapon to display at position {index + 1}:",
"choices": WEAPONS
}


table_question = lambda config: {
"type": "checkbox",
Expand Down Expand Up @@ -76,11 +85,10 @@
}

basic_questions = lambda config: [
weapon_question(config=config),
table_question(config=config),
chat_limit_question(config=config)
]

advance_questions = lambda config: [
port_question(config=config),
] + basic_questions(config=config)
]
14 changes: 11 additions & 3 deletions src/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
from rich.table import Table as RichTable
from rich.console import Console as RichConsole

TABLE_COLUMN_NAMES = Literal[
from src.config import Config
from src.logs import Logging


Logging = Logging()
log = Logging.log
cfg = Config(log)

TABLE_COLUMN_NAMES = Literal [
"Party",
"Agent",
"Name",
"Skin",
*[weapon for weapon in cfg.weapons],
"Rank",
"RR",
"Peak Rank",
Expand All @@ -29,7 +37,7 @@ def __init__(self, config, chatlog, log):
True, # Party
True, # Agent
True, # Name
bool(config.table.get("skin", True)), # Skin
*([True for _ in cfg.weapons] if len(cfg.weapons) > 0 else [False]),
True, # Rank
bool(config.table.get("rr", True)), # RR
bool(config.table.get("peakrank", True)), # Peak Rank
Expand Down