Skip to content

Commit

Permalink
Add MajsoulURL Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shinkuan committed May 26, 2024
1 parent 107d0cf commit 03c7aa2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
23 changes: 23 additions & 0 deletions client.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 03c7aa2

Please sign in to comment.