-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
217 lines (192 loc) · 7.13 KB
/
app.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from time import sleep
from loguru import logger as log
from PySide6.QtCore import QSize, QTimer
from PySide6.QtGui import Qt, QIcon, QPixmap
from PySide6.QtWidgets import (
QApplication,
QComboBox,
QHBoxLayout,
QLabel,
QMainWindow,
QVBoxLayout,
QWidget,
QScrollArea,
QFrame,
)
from wuthering import (
AUTHOR,
POOLTYPE,
STANDARD_POOL,
TITLE,
VERSION,
PoolData,
WutheringData,
)
import rc_irons
def spin(index):
return "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"[index]
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
log.debug("Created QMainWindow")
self.setWindowTitle("鳴潮卡池紀錄")
self.setFixedSize(QSize(300, 100))
pixmap = QPixmap(":icons/icon.png")
self.setWindowIcon(QIcon(pixmap))
self.backend = WutheringData()
self.tick_count = 0
layout = QVBoxLayout()
widget = QWidget()
self.center_text = QLabel("你好,鳴潮")
layout.addWidget(
self.center_text, alignment=Qt.AlignmentFlag.AlignCenter
)
widget.setLayout(layout)
self.setCentralWidget(widget)
self.statusBar().showMessage(
f"{TITLE} v{VERSION} | 這我: {AUTHOR}"
)
self.show()
log.debug("Starting QTimer")
self.tick = QTimer()
self.tick.setInterval(42)
self.tick.timeout.connect(self.detect_game)
self.tick.start()
def detect_game(self):
if self.tick_count % 29 == 0 and self.backend.locate_executable():
log.debug("Game detected")
self.center_text.setText(f"鳴潮,啟動!")
sleep(1) # for memes
self.tick.timeout.disconnect(self.detect_game)
self.tick.timeout.connect(self.fetch_payload)
else:
self.center_text.setText(
f"{spin(self.tick_count%10)} 正在等待鳴潮啟動"
)
self.tick_count += 1
def fetch_payload(self):
if self.tick_count % 29 == 0 and self.backend.fetch_payload():
log.debug("Created Payload for API request")
self.tick.timeout.disconnect(self.fetch_payload)
self.tick.timeout.connect(self.populate_data)
else:
self.center_text.setText(
f"{spin(self.tick_count%10)} 缺少資料,請開啟遊戲內抽卡紀錄"
)
self.tick_count += 1
def populate_data(self):
log.debug("Populating data from pool")
if self.tick_count % 18 == 0:
self.center_text.setText("完成")
self.repaint()
self.backend.populate_data()
self.tick.timeout.disconnect(self.populate_data)
self.tick.stop()
self.dropdown_update()
else:
self.center_text.setText(
f"{spin(self.tick_count%10)} 正在整理數據"
)
self.tick_count += 1
def dropdown_update(self, selection: str = POOLTYPE[1]):
log.debug("Refreshed center Dropdown Widget")
self.setFixedSize(QSize(300, 420))
widget = QWidget()
layout = QVBoxLayout()
dropdown = QComboBox()
dropdown.addItems(
[k for k, v in self.backend.data.items() if v and v.attempt]
)
dropdown.setCurrentText(selection)
dropdown.currentTextChanged.connect(self.dropdown_update)
layout.addWidget(dropdown)
content_layout = self.result_content(selection)
layout.addLayout(content_layout)
widget.setLayout(layout)
self.setCentralWidget(widget)
def result_content(self, pool: str) -> None:
log.debug("Content created")
data: PoolData = self.backend.data[pool]
layout = QHBoxLayout()
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
five_ratio = f"{data.get_ratio(5)*100:.2f}%"
five_avg = f"{data.get_average(5)}抽"
five_pool = data.entry.get(5, [])
four_ratio = f"{data.get_ratio(4)*100:.2f}%"
four_avg = f"{data.get_average(4)}抽"
four_pool = data.entry.get(4, [])
four_char = [
_ for _ in data.entry.get(4, []) if _.resourcetype == "角色"
]
four_weap = [
_ for _ in data.entry.get(4, []) if _.resourcetype == "武器"
]
optional = ""
cum = data.get_history(5)
if cum and pool == "角色活動":
hit_miss = (
len([_ for _ in cum if _.name not in STANDARD_POOL])
/ len(cum)
* 100
)
optional = f"保底命中: {hit_miss:.2f}%"
desc = QLabel(
(
f"抽取次數: {data.attempt }\n"
f"目前保底: {data.get_pity }\n"
f"{optional}\n"
"\n5星\n"
f" 機率: {five_ratio }\n"
f" 平均: {five_avg }\n"
f" 總計: {len(five_pool)}\n"
"\n4星\n"
f" 機率: {four_ratio }\n"
f" 平均: {four_avg }\n"
f" 總計: {len(four_pool)}\n"
"\n4星角色\n"
f" 機率: {len(four_char)/len(four_pool):.2f}%\n"
f" 總計: {len(four_char)}\n"
"\n4星武器\n"
f" 機率: {len(four_weap)/len(four_pool):.2f}%\n"
f" 總計: {len(four_weap)}\n"
)
)
desc.setAlignment(Qt.AlignmentFlag.AlignTop)
desc.setFixedWidth(140)
layout.addWidget(desc)
right_col = QVBoxLayout()
right_col.setAlignment(
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
)
right_col.addWidget(QLabel("最近紀錄"))
log.debug("Pool cum data: {}", cum)
scroll = QScrollArea()
scroll.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAlwaysOn
)
scroll.setHorizontalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAlwaysOff
)
scroll.setWidgetResizable(True)
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
inner.layout().setAlignment(Qt.AlignmentFlag.AlignTop)
scroll.setWidget(inner)
for item in cum:
label = QLabel(f"{item.name: <5}{item.pity:>2}抽")
label.setAlignment(Qt.AlignmentFlag.AlignLeft)
label.setStyleSheet("color: cornflowerblue")
if pool == "角色活動" and item.name in STANDARD_POOL:
label.setStyleSheet("color: orangered")
inner.layout().addWidget(label)
right_col.addWidget(scroll)
layout.addLayout(right_col)
return layout
if __name__ == "__main__":
log.remove()
import sys
log.add(sys.stdout, level="DEBUG")
app = QApplication()
window = MainWindow()
log.debug("App Start")
app.exec()