Skip to content

Commit

Permalink
Version 1.6.1 (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVG207 authored Aug 1, 2023
2 parents e2e403c + 3c760e2 commit b9e0b6b
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 11 deletions.
21 changes: 20 additions & 1 deletion umalauncher/carrotjuicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ def handle_response(self, message):
self.screen_state_handler.carrotjuicer_state = new_state
return

# Team Building
if 'scout_ranking_state' in data:
if data.get("own_team_info") and data['own_team_info'].get('team_score') and self.screen_state_handler:
team_score = data['own_team_info'].get('team_score')
leader_chara_id = data['own_team_info'].get('entry_chara_array',[{}])[0].get('trained_chara', {}).get('card_id')

if team_score and leader_chara_id:
logger.debug(f"Team score: {team_score}, leader chara id: {leader_chara_id}")
self.screen_state_handler.carrotjuicer_state = screenstate_utils.make_scouting_state(self.screen_state_handler, team_score, leader_chara_id)

# League of Heroes
if 'heroes_id' in data:
if data.get("own_team_info") and data['own_team_info']['team_name'] and data['own_team_info']['league_score'] and self.screen_state_handler:
Expand Down Expand Up @@ -342,10 +352,19 @@ def handle_response(self, message):
if event_data['event_contents_info']['support_card_id'] and event_data['event_contents_info']['support_card_id'] not in supports:
# Random support card event
logger.debug("Random support card detected")

self.browser.execute_script("""document.getElementById("boxSupportExtra").click();""")
self.browser.execute_script(
"""
document.getElementById(arguments[0].toString()).click();
var cont = document.getElementById("30021").parentElement.parentElement;
var ele = cont.getElementById(arguments[0].toString());
if (ele) {
ele.click();
} else {
cont.querySelector("img[src=\"/images/ui/close.png\"]").click();
}
""",
event_data['event_contents_info']['support_card_id']
)
Expand Down
33 changes: 33 additions & 0 deletions umalauncher/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,37 @@
23000: "Platinum 2",
26000: "Platinum 3",
30000: "Platinum 4"
}

SCOUTING_SCORE_TO_RANK_DICT = {
0: "No rank",
60000: "E",
63000: "E1",
66000: "E2",
69000: "E3",
72000: "D",
76000: "D1",
80000: "D2",
85000: "D3",
90000: "C",
95000: "C1",
100000: "C2",
105000: "C3",
110000: "B",
115000: "B1",
120000: "B2",
125000: "B3",
130000: "A",
135000: "A1",
140000: "A2",
145000: "A3",
150000: "A4",
155000: "A5",
160000: "S",
165000: "S1",
170000: "S2",
180000: "S3",
190000: "S4",
200000: "S5",
210000: "SS"
}
2 changes: 2 additions & 0 deletions umalauncher/helper_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def calc_bond_gain(partner_id, amount):

scheduled_races.append({
"turn": turn,
"fans": program_data['need_fan_count'],
"thumb_url": thumb_url
})

Expand All @@ -292,6 +293,7 @@ def calc_bond_gain(partner_id, amount):
"scenario_id": data['chara_info']['scenario_id'],
"energy": data['chara_info']['vital'],
"max_energy": data['chara_info']['max_vital'],
"fans": data['chara_info']['fans'],
"scheduled_races": scheduled_races,
"gm_fragments": gm_fragments,
"gl_stats": gl_stats,
Expand Down
9 changes: 8 additions & 1 deletion umalauncher/helper_table_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ def generate_schedule(self, main_info):
turns_left = next_race['turn'] - cur_turn
text = f"<p>{turns_left} turn{'' if turns_left == 1 else 's'} until</p>"
img = f"<img width=100 height=50 src=\"{next_race['thumb_url']}\"/>"
return f"""<div id="schedule" style="display: flex; align-items: center; gap: 0.5rem;">{text}{img}</div>"""

fan_warning = ""

if main_info['fans'] < next_race['fans']:
fans_needed = next_race['fans'] - main_info['fans']
fan_warning = f"""<p style="color: orange; margin: 0;"><b>{fans_needed}</b> more fans needed!</p>"""

return f"""<div id="schedule" style="display: flex; flex-direction: column; justify-content: center; align-items: center;"><div id="schedule-race-container" style="display: flex; align-items: center; gap: 0.5rem;">{text}{img}</div>{fan_warning}</div>"""

def to_dict(self):
return {
Expand Down
21 changes: 16 additions & 5 deletions umalauncher/horsium.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def edge_setup(helper_url):
)

BROWSER_LIST = {
'Chrome': chrome_setup,
'Firefox': firefox_setup,
'Chrome': chrome_setup,
'Edge': edge_setup,
}

Expand Down Expand Up @@ -97,14 +97,16 @@ def init_browser(self) -> RemoteWebDriver:

browser_list = []
if browser_name == "Auto":
browser_list = BROWSER_LIST.values()
browser_list = BROWSER_LIST.items()
else:
browser_list = [BROWSER_LIST[browser_name]]
browser_list = [(browser_name, BROWSER_LIST[browser_name])]

for browser_setup in browser_list:
for browser_data in browser_list:
browser_name, browser_setup = browser_data
try:
logger.info("Attempting " + str(browser_setup.__name__))
driver = browser_setup(self.url)
self.browser_name = browser_name
break
except Exception:
logger.error("Failed to start browser")
Expand All @@ -131,7 +133,12 @@ def ensure_tab_open(self):
window_handles = self.driver.window_handles
try:
if self.active_tab_handle in window_handles:
self.driver.switch_to.window(self.active_tab_handle)
if self.browser_name in ['Chrome', 'Edge']:
if self.driver.current_window_handle != self.active_tab_handle:
raise Exception("Wrong window handle")

if self.browser_name == 'Firefox' and self.driver.current_window_handle != self.active_tab_handle:
self.driver.switch_to.window(self.active_tab_handle)

if urls_match(self.driver.current_url, self.url):
from_script = self.driver.execute_script("return window.from_script;")
Expand All @@ -156,6 +163,10 @@ def ensure_tab_open(self):
OLD_DRIVERS.append(self.driver)

self.driver = self.init_browser()

if not self.driver:
return

self.active_tab_handle = self.driver.window_handles[0]
self.driver.switch_to.window(self.active_tab_handle)
self.run_script_at_launch()
Expand Down
1 change: 1 addition & 0 deletions umalauncher/screenstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Location(Enum):
TRAINING = 3
EVENT = 4
LEAGUE_OF_HEROES = 5
SCOUTING_EVENT = 6

class ScreenState:
location = None
Expand Down
12 changes: 12 additions & 0 deletions umalauncher/screenstate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ def make_league_of_heroes_state(handler, team_name, league_score) -> ss.ScreenSt
new_state.location = ss.Location.LEAGUE_OF_HEROES
new_state.main = f"League of Heroes - {team_name}"
new_state.sub = get_league_of_heroes_substate(league_score)
return new_state

def make_scouting_state(handler: ss.ScreenStateHandler, team_score, outfit_id) -> ss.ScreenState:
new_state = ss.ScreenState(handler)
new_state.location = ss.Location.SCOUTING_EVENT
new_state.main = f"Team Building - {team_score} pt."
new_state.sub = f"Rank: {util.scouting_score_to_rank_string(team_score)}"

chara_id = str(outfit_id)[:-2]

new_state.set_chara(chara_id, outfit_id=int(outfit_id), small_text="Team Leader")

return new_state
19 changes: 16 additions & 3 deletions umalauncher/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def log_set_trace():
has_failed_once = False
def do_get_request(url, error_title=None, error_message=None, ignore_timeout=False):
global last_failed_request
global has_failed_once

try:
if not ignore_timeout and last_failed_request is not None:
Expand All @@ -114,8 +115,11 @@ def do_get_request(url, error_title=None, error_message=None, ignore_timeout=Fal
response = requests.get(url)
response.raise_for_status()
return response
except requests.exceptions.RequestException:
if (last_failed_request is None and not has_failed_once) or ignore_timeout:
except:
logger.warning(f"Failed to connect to {url}")
logger.warning(traceback.format_exc())
if ignore_timeout or not has_failed_once:
has_failed_once = True
logger.warning(traceback.format_exc())
show_warning_box(
"Failed to connect to server" if error_title is None else error_title,
Expand Down Expand Up @@ -434,4 +438,13 @@ def heroes_score_to_league_string(score):
current_league = league
else:
break
return current_league
return current_league

def scouting_score_to_rank_string(score):
current_rank = list(constants.SCOUTING_SCORE_TO_RANK_DICT.keys())[0]
for score_threshold, rank in constants.SCOUTING_SCORE_TO_RANK_DICT.items():
if score >= score_threshold:
current_rank = rank
else:
break
return current_rank
2 changes: 1 addition & 1 deletion umalauncher/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import util
import gui

VERSION = "1.6.0"
VERSION = "1.6.1"

def parse_version(version_string: str):
"""Convert version string to tuple."""
Expand Down

0 comments on commit b9e0b6b

Please sign in to comment.