This repository has been archived by the owner on Dec 9, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutil_game.py
78 lines (61 loc) · 2.49 KB
/
util_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from .custom_driver import client
from .utils import log
from enum import Enum
def close_modal(browser: client) -> None:
el = browser.find("//div[@class='modalContent']")
el = el.find_element_by_xpath(".//a[@class='closeWindow clickable']")
browser.click(el)
def close_welcome_screen(browser: client) -> None:
wc = browser.find("//div[contains(@class, 'welcomeScreen')]")
log("closing welcome-screen")
el = wc.find_element_by_xpath(".//a[@class='closeWindow clickable']")
browser.click(el)
def check_resources(browser: client) -> dict:
resources_list = ["wood", "clay", "iron", "crop"]
resources = {}
for res in resources_list:
find_resources = browser.find("//div[@class='stockContainer {0}']".format(res))
find_resources = find_resources.find_element_by_xpath(
".//div[contains(@class, 'progressbar')]"
)
value = int(find_resources.get_attribute("value"))
resources[res] = value
return resources
class shortcut(Enum):
marketplace = 0
barrack = 1
stable = 2
workshop = 3
def open_shortcut(browser: client, sc: shortcut) -> None:
shortcut_link = browser.find("//div[@id='quickLinks']")
shortcut_link = shortcut_link.find_element_by_xpath(
".//div[contains(@class, 'slotWrapper')]"
)
link = shortcut_link.find_elements_by_xpath(
".//div[contains(@class, 'slotContainer')]"
)
browser.click(link[sc.value], 1)
class overview(Enum):
overview = "optimizely_maintab_Overview"
resources = "optimizely_maintab_Resources"
warehouse = "optimizely_maintab_Store"
culture_points = "optimizely_maintab_CulturePoints"
units = "optimizely_maintab_Troops"
oases = "optimizely_maintab_Oases"
def open_village_overview(browser: client, tab: overview) -> None:
btn = browser.find("//a[@id='villageOverview']")
browser.click(btn, 1)
navi_tab = browser.find(f"//a[@id='{tab.value}']")
classes = navi_tab.get_attribute("class")
if "inactive" in classes:
browser.click(tab, 2)
def old_shortcut(browser: client, shortcut: str) -> None:
shortcut_dict = {"marketplace": 0, "barrack": 1, "stable": 2, "workshop": 3}
shortcut_link = browser.find("//div[@id='quickLinks']")
shortcut_link = shortcut_link.find_element_by_xpath(
".//div[contains(@class, 'slotWrapper')]"
)
link = shortcut_link.find_elements_by_xpath(
".//div[contains(@class, 'slotContainer')]"
)
browser.click(link[shortcut_dict[shortcut.lower()]], 1)