-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.py
More file actions
229 lines (181 loc) · 8.33 KB
/
renderer.py
File metadata and controls
229 lines (181 loc) · 8.33 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
import re
from tkinter import Message
from PIL import Image, ImageTk, ImageDraw, ImageFont, ImageEnhance
import util
from config import config
def highlight(message,color):
words = config.get("lobby_chat_words")
for word in words:
if word.lower() in message.lower():
message = "$e"+message
color = "$e"
break
message = re.sub("(\d)\/(\d)",lambda match: f"$e{match.group(1)}/$6{match.group(2)}{color}",message)
message = message.replace("OOF", f"$cOOF{color}")
message = message.replace("( ???)/", f"$d(^{chr(9697)}^)/{color}")
return message
def rainbow(text):
color_pattern = "c6ea9b5" * (len(text)//7+1)
zip_color = lambda texts, colors: "".join(f"${c}{t}" for t, c in zip(texts,colors))
return zip_color(text, color_pattern)
def grayout_dec(num):
if num >= 1000: num = round(num)
elif num >= 100: num = round(num, 1)
elif num >= 0: num = round(num, 2)
if num>=1000:
return f"{num}"
elif num>=100:
#return f"{num:.1f}".replace(".","$c.$7")
return f"{num:.1f}"
else:
#return f"{num:.2f}".replace(".","$c.$7")
return f"{num:.2f}"
class Bedwars:
def render(img, ign, player, font):
data = player.data
hypixel = data.get("hypixel")
def render_skin():
if data.get("skin"):
skin = data.get("skin")
img.paste(skin, (23, 0), skin)
def render_nick():
util.text(img, (65,0), f"$c< Nicked >", font, anchor="C")
util.text(img, (200,0), f"{ign}", font, anchor="C")
def render_normal():
bw = hypixel.bw[0]
star = util.get_star_text(bw.level)
display_name = f"{hypixel.chat.name_color}{ign}"
if bw.winstreak is not None:
ws = bw.winstreak
ws_color = "$" + util.get_string_from_range(config.get("color_bw_ws"), ws)
else:
ws = "-"
ws_color = "$8"
fkdr = bw.fkdr
wlr = bw.wlr
index = bw.index
bblr = bw.bblr
fkdr_color = "$" + util.get_string_from_range(config.get("color_bw_fkdr"), fkdr)
wlr_color = "$" + util.get_string_from_range(config.get("color_bw_wlr"), wlr)
index_color = "$" + util.get_string_from_range(config.get("color_bw_index"), index)
bblr_color = "$" + util.get_string_from_range(config.get("color_bw_bblr"), bblr)
tag = f"$8-"
util.text(img, (3,0), f"{index_color}{chr(9609)}", font, anchor="L")
util.text(img, (50,0), f"{star}", font, anchor="L")
util.text(img, (200,0), f"{display_name}", font, anchor="C")
util.text(img, (330,0), f"{tag}", font, anchor="C")
util.text(img, (390,0), f"{ws_color}{ws}", font, anchor="C")
util.text(img, (450+24,0), f"{fkdr_color}{grayout_dec(fkdr)}", font, anchor="R")
util.text(img, (510+24,0), f"{wlr_color}{grayout_dec(wlr)}", font, anchor="R")
util.text(img, (570+24,0), f"{bblr_color}{grayout_dec(bblr)}", font, anchor="R")
util.text(img, (640+24,0), f"{bw.final_kills}", font, anchor="R")
util.text(img, (710+24,0), f"{bw.wins}", font, anchor="R")
def render_error():
util.text(img, (65,0), f"$c(error)", font, anchor="C")
util.text(img, (200,0), f"$7{ign}", font, anchor="C")
util.text(img, (330,0), f"$8{player.error_message}", font, anchor="L")
def render_loading():
util.text(img, (70,0), f"$8{ign} (fetching stats..)", font)
if player.nicked:
render_nick()
elif data.get("hypixel"):
render_normal()
elif player.error_message:
render_error()
else:
render_loading()
render_skin()
def header(img, font):
util.text(img, (65,0), "$bLEVEL", font, anchor="C", bold=True)
util.text(img, (200,0), "$bUSERNAME", font, anchor="C", bold=True)
util.text(img, (330,0), "$bTAG", font, anchor="C", bold=True)
util.text(img, (390,0), "$bWS", font, anchor="C", bold=True)
util.text(img, (450,0), "$bFKDR", font, anchor="C", bold=True)
util.text(img, (510,0), "$bWLR", font, anchor="C", bold=True)
util.text(img, (570,0), "$bBBLR", font, anchor="C", bold=True)
util.text(img, (640,0), "$bFINALS", font, anchor="C", bold=True)
util.text(img, (710,0), "$bWINS", font, anchor="C", bold=True)
def sort_function(player):
hypixel = player.data.get("hypixel")
if player.nicked: return 99999999999999
if not hypixel: return -99999999999999
return hypixel.bw[0].index
def sort(players):
return sorted(list(players), key=lambda ign: Bedwars.sort_function(players[ign]), reverse=True)
class LobbyChat:
def render(img, ign, player, font):
data = player.data
hypixel = data.get("hypixel")
username = player.ign
def render_skin():
if data.get("skin"):
skin = data.get("skin")
img.paste(skin, (3, 0), skin)
def render_nick():
util.text(img, (65,0), f"$c< Nicked >", font, anchor="C")
util.text(img, (200,0), f"{ign}", font, anchor="C")
def render_normal():
bw = hypixel.bw[0]
star = util.get_star_text(bw.level, True)
if bw.winstreak is not None:
ws = bw.winstreak
ws_color = "$" + util.get_string_from_range(config.get("color_bw_ws"), ws)
else:
ws = "-"
ws_color = "$8"
fkdr = bw.fkdr
wlr = bw.wlr
index = bw.index
fkdr_color = "$" + util.get_string_from_range(config.get("color_bw_fkdr"), fkdr)
wlr_color = "$" + util.get_string_from_range(config.get("color_bw_wlr"), wlr)
index_color = "$" + util.get_string_from_range(config.get("color_bw_index"), index)
message = data.get("latest_message",":-").split(":",1)[-1]
message = highlight(message,hypixel.chat.text_color)
util.text(img, (70,0), f"{ws_color}{ws}", font, anchor="R")
util.text(img, (130,0), f"{wlr_color}{grayout_dec(wlr)}", font, anchor="R")
util.text(img, (190,0), f"{fkdr_color}{grayout_dec(fkdr)}", font, anchor="R")
util.text(img, (200,0), f"{index_color}{chr(9609)}{star} {hypixel.chat.name_color}{username}$f: {hypixel.chat.text_color}{message}", font, anchor="L")
def render_error():
util.text(img, (65,0), f"$c(error)", font, anchor="C")
util.text(img, (200,0), f"$7{ign}", font, anchor="C")
util.text(img, (330,0), f"$8{player.error_message}", font, anchor="L")
def render_loading():
message = data.get("latest_message",":-").split(":",1)[-1]
message = highlight(message,"$7")
util.text(img, (95,0), f"$7< fetching stats >", font, anchor="C")
util.text(img, (200,0), f"$8[????] $7{username}$f: $f{message}", font, anchor="L")
if player.nicked:
render_nick()
elif data.get("hypixel"):
render_normal()
elif player.error_message:
render_error()
else:
render_loading()
render_skin()
def header(img, font):
util.text(img, (70,0), f"$bWS", font, anchor="R", bold=True)
util.text(img, (130,0), f"$bWLR", font, anchor="R", bold=True)
util.text(img, (190,0), f"$bFKDR", font, anchor="R", bold=True)
def sort_function(player):
return player.ign
def sort(players):
return list(players)
# import os
# def resource_path(relative_path):
# try:
# base_path = sys._MEIPASS
# except Exception:
# base_path = os.path.abspath(".")
# # print(base_path)
# return os.path.join(base_path, relative_path)
# font = ImageFont.truetype(font=resource_path("Roboto-Bold-uni.ttf"), size=19)
# def generate_card(overlay,player):
# height = overlay.bg.winfo_height()
# img = Image.new("RGB", (1000, height), "#000000")
# player_skin = player.data.get("skin")
# if player_skin:
# img.paste(player_skin.resize((100,100), resample=Image.NEAREST))
# name = player.ign
# util.text(img, (50,100), name, font)
# return img