From 03c7aa26f1f72186291dfcd96250c9ef829b0d0c Mon Sep 17 00:00:00 2001 From: shinkuan Date: Sun, 26 May 2024 14:28:04 +0800 Subject: [PATCH] Add MajsoulURL Settings --- client.py | 12 ++++++++++++ client.tcss | 23 +++++++++++++++++++++++ mitm.py | 9 +++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/client.py b/client.py index 4d0ca04..bfe3a6e 100644 --- a/client.py +++ b/client.py @@ -467,6 +467,7 @@ def __init__(self, *args, **kwargs) -> None: self.value_playwright_setting_enable_checkbox = settings["Playwright"]["enable"] self.value_playwright_setting_width_input = settings["Playwright"]["width"] self.value_playwright_setting_height_input = settings["Playwright"]["height"] + self.value_majsoul_url_input = settings["MajsoulURL"] def compose(self) -> ComposeResult: self.port_setting_mitm_label = Label("MITM Port", id="port_setting_mitm_label") @@ -517,6 +518,11 @@ def compose(self) -> ComposeResult: self.playwright_setting_container = Vertical(self.playwright_setting_enable_container, self.playwright_setting_resolution_container, id="playwright_setting_container") self.playwright_setting_container.border_title = "Playwright" + self.majsoul_url_label = Label("Majsoul URL", id="majsoul_url_label") + self.majsoul_url_input = Input(placeholder="URL", type="text", id="majsoul_url_input", value=self.value_majsoul_url_input) + self.majsoul_url_container = Horizontal(self.majsoul_url_label, self.majsoul_url_input, id="majsoul_url_container") + self.majsoul_url_container.border_title = "Majsoul" + self.setting_save_button = Button("Save", variant="warning", id="setting_save_button") self.remove_this_then_you_badluck_for_100years_and_get_hit_by_a_car_then_die = HoverLink("Akagi is Free and Open Sourced on GitHub.\n本程式Akagi在GitHub上完全開源且免費。如果你是付費取得的,你已經被賣家欺騙,請立即舉報、差評、退款。", "https://github.com/shinkuan/Akagi", id="remove_this_you_die") @@ -528,6 +534,7 @@ def compose(self) -> ComposeResult: self.overlay_setting_container, self.autoplay_setting_container, self.playwright_setting_container, + self.majsoul_url_container, self.setting_save_button, self.remove_this_then_you_badluck_for_100years_and_get_hit_by_a_car_then_die, id="setting_container" @@ -615,6 +622,10 @@ def playwright_setting_height_input_changed(self, event: Input.Changed) -> None: except: pass + @on(Input.Changed, "#majsoul_url_input") + def majsoul_url_input_changed(self, event: Input.Changed) -> None: + self.value_majsoul_url_input = event.value + @on(Button.Pressed, "#setting_save_button") def setting_save_button_pressed(self) -> None: with open("settings.json", "r") as f: @@ -632,6 +643,7 @@ def setting_save_button_pressed(self) -> None: settings["Playwright"]["enable"] = self.value_playwright_setting_enable_checkbox settings["Playwright"]["width"] = self.value_playwright_setting_width_input settings["Playwright"]["height"] = self.value_playwright_setting_height_input + settings["MajsoulURL"] = self.value_majsoul_url_input with open("settings.json", "w") as f: json.dump(settings, f, indent=4) diff --git a/client.tcss b/client.tcss index 4ce32a8..3dafcc8 100644 --- a/client.tcss +++ b/client.tcss @@ -622,6 +622,29 @@ Button.action_nukidora.-active { border-title-align: center; } +#majsoul_url_label { + padding: 1 0; + width: 11; + height: 3; + align: center middle; + margin: 0 1; +} + +#majsoul_url_input { + width: 1fr; + align: center top; + margin: 0 1; +} + +#majsoul_url_container { + width: 1fr; + height: auto; + align: center top; + margin: 0; + border: round $accent; + border-title-align: center; +} + #remove_this_you_die { width: 1fr; height: auto; diff --git a/mitm.py b/mitm.py index 5304268..d1145f0 100644 --- a/mitm.py +++ b/mitm.py @@ -188,7 +188,7 @@ def serve_forever(self): class PlaywrightController: - def __init__(self, width, height, mitm_port): + def __init__(self, width, height, mitm_port, majsoul_url): self.playwrightContextManager = sync_playwright() self.playwright = self.playwrightContextManager.__enter__() self.chromium = self.playwright.chromium @@ -212,8 +212,8 @@ def __init__(self, width, height, mitm_port): self.page = self.browser.new_page() - self.page.goto('https://game.mahjongsoul.com/') - # self.page.goto('https://game.maj-soul.com/1/') + self.page.goto(majsoul_url) + # self.page.goto('https://game.mahjongsoul.com/') print(f'go to page success, url: {self.page.url}') self._t3c_width = self.width * 0.16 @@ -448,6 +448,7 @@ def exit(self): playwright_height = settings["Playwright"]["height"] autohu = settings["Autohu"] scale = playwright_width / 16 + majsoul_url = settings["MajsoulURL"] mitm_host="127.0.0.1" rpc_host="127.0.0.1" @@ -489,7 +490,7 @@ def exit(self): playwright_controller = None page = None if enable_playwright: - playwright_controller = PlaywrightController(playwright_width, playwright_height, mitm_port) + playwright_controller = PlaywrightController(playwright_width, playwright_height, mitm_port, majsoul_url) click_list = [] evaluate_list = []