mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2026-08-15 13:03:08 +00:00
[ci] auto-format
This commit is contained in:
parent
d25a14bd2e
commit
fd4bcc1f72
1 changed files with 158 additions and 107 deletions
|
|
@ -33,6 +33,7 @@ from random import uniform
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
|
|
||||||
class Replay:
|
class Replay:
|
||||||
VER = '3.0'
|
VER = '3.0'
|
||||||
COL1 = (0.18, 0.18, 0.18)
|
COL1 = (0.18, 0.18, 0.18)
|
||||||
|
|
@ -56,7 +57,8 @@ class Replay:
|
||||||
p=get_overlay_stack(),
|
p=get_overlay_stack(),
|
||||||
size=(400, 500),
|
size=(400, 500),
|
||||||
oac=lambda: (
|
oac=lambda: (
|
||||||
bui.containerwidget(self.parent, transition='out_scale' if source and source.exists() else 'out_left'),
|
bui.containerwidget(
|
||||||
|
self.parent, transition='out_scale' if source and source.exists() else 'out_left'),
|
||||||
self.play_sound('laser'),
|
self.play_sound('laser'),
|
||||||
self.transition_sound.stop()
|
self.transition_sound.stop()
|
||||||
)
|
)
|
||||||
|
|
@ -228,10 +230,12 @@ class Replay:
|
||||||
|
|
||||||
def finish_calculation(self, duration):
|
def finish_calculation(self, duration):
|
||||||
bui.textwidget(self.status_text, text='Starting...' if duration else 'Wait what?')
|
bui.textwidget(self.status_text, text='Starting...' if duration else 'Wait what?')
|
||||||
bui.textwidget(self.progress_text2, text=f'result was {duration} milleseconds') if duration else duration
|
bui.textwidget(self.progress_text2,
|
||||||
|
text=f'result was {duration} milleseconds') if duration else duration
|
||||||
if not duration:
|
if not duration:
|
||||||
self.error = True
|
self.error = True
|
||||||
bui.textwidget(self.progress_text, text='pybrp returned zero duration, error?\nclosing this window in 5 seconds')
|
bui.textwidget(
|
||||||
|
self.progress_text, text='pybrp returned zero duration, error?\nclosing this window in 5 seconds')
|
||||||
bui.textwidget(self.progress_text2, text='')
|
bui.textwidget(self.progress_text2, text='')
|
||||||
bui.apptimer(1 if duration else 5, CallPartial(self.start_player, duration))
|
bui.apptimer(1 if duration else 5, CallPartial(self.start_player, duration))
|
||||||
|
|
||||||
|
|
@ -290,6 +294,7 @@ class Replay:
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
TICK = 0.01
|
TICK = 0.01
|
||||||
COL0 = (0.5, 0, 0)
|
COL0 = (0.5, 0, 0)
|
||||||
|
|
@ -325,7 +330,8 @@ class Player:
|
||||||
self.camera_look = None
|
self.camera_look = None
|
||||||
self.replay_time = self.start_time = self.progress_val = 0
|
self.replay_time = self.start_time = self.progress_val = 0
|
||||||
self.camera_zoom = 1
|
self.camera_zoom = 1
|
||||||
[setattr(self, attr, []) for attr in ['ui_widgets', 'camera_widgets', 'hide_widgets', 'cinema_widgets', 'cinema_ui_widgets']]
|
[setattr(self, attr, []) for attr in ['ui_widgets', 'camera_widgets',
|
||||||
|
'hide_widgets', 'cinema_widgets', 'cinema_ui_widgets']]
|
||||||
|
|
||||||
# Start replay immediately
|
# Start replay immediately
|
||||||
bs.new_replay_session(path)
|
bs.new_replay_session(path)
|
||||||
|
|
@ -881,7 +887,8 @@ class Player:
|
||||||
self.camera_look = None
|
self.camera_look = None
|
||||||
bui.textwidget(self.look_text, text='players')
|
bui.textwidget(self.look_text, text='players')
|
||||||
self.camera_zoom = new_zoom
|
self.camera_zoom = new_zoom
|
||||||
bui.textwidget(self.zoom_text, text=f'x{round(0.5 ** (new_zoom - 1), 2)}' if new_zoom != 1 else 'x1.0' if self.manual_zoom else 'auto')
|
bui.textwidget(
|
||||||
|
self.zoom_text, text=f'x{round(0.5 ** (new_zoom - 1), 2)}' if new_zoom != 1 else 'x1.0' if self.manual_zoom else 'auto')
|
||||||
self.apply_zoom()
|
self.apply_zoom()
|
||||||
|
|
||||||
def look(self):
|
def look(self):
|
||||||
|
|
@ -1034,7 +1041,8 @@ class Player:
|
||||||
crosshair = 20
|
crosshair = 20
|
||||||
[widgets(bui.imagewidget(
|
[widgets(bui.imagewidget(
|
||||||
parent=self.parent,
|
parent=self.parent,
|
||||||
position=(width / 2, height / 2 - crosshair / 2 + crosshair * 0.1) if i else (width / 2 - crosshair / 2, height / 2 + crosshair * 0.1),
|
position=(width / 2, height / 2 - crosshair / 2 + crosshair *
|
||||||
|
0.1) if i else (width / 2 - crosshair / 2, height / 2 + crosshair * 0.1),
|
||||||
size=(3, crosshair * 1.15) if i else (crosshair * 1.15, 3),
|
size=(3, crosshair * 1.15) if i else (crosshair * 1.15, 3),
|
||||||
color=self.COL1,
|
color=self.COL1,
|
||||||
texture=bui.gettexture('white')
|
texture=bui.gettexture('white')
|
||||||
|
|
@ -1055,7 +1063,8 @@ class Player:
|
||||||
parent=self.parent,
|
parent=self.parent,
|
||||||
texture=bui.gettexture('white'),
|
texture=bui.gettexture('white'),
|
||||||
color=self.COL1,
|
color=self.COL1,
|
||||||
position=(width / 2 + offset, height / 2 + [offset - crosshair, -offset + crosshair * 0.3][j]),
|
position=(width / 2 + offset, height / 2 +
|
||||||
|
[offset - crosshair, -offset + crosshair * 0.3][j]),
|
||||||
size=(3, crosshair * +1.1)
|
size=(3, crosshair * +1.1)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
@ -1064,7 +1073,8 @@ class Player:
|
||||||
parent=self.parent,
|
parent=self.parent,
|
||||||
texture=bui.gettexture('white'),
|
texture=bui.gettexture('white'),
|
||||||
color=self.COL1,
|
color=self.COL1,
|
||||||
position=(width / 2 + [-offset, offset - crosshair][j], height / 2 - crosshair / 2 - offset + crosshair * 0.8),
|
position=(width / 2 + [-offset, offset - crosshair][j],
|
||||||
|
height / 2 - crosshair / 2 - offset + crosshair * 0.8),
|
||||||
size=(crosshair * 1.1, 3)
|
size=(crosshair * 1.1, 3)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
@ -1073,7 +1083,8 @@ class Player:
|
||||||
parent=self.parent,
|
parent=self.parent,
|
||||||
texture=bui.gettexture('white'),
|
texture=bui.gettexture('white'),
|
||||||
color=self.COL1,
|
color=self.COL1,
|
||||||
position=(width / 2 - offset, height / 2 + [offset - crosshair, -offset + crosshair * 0.3][j]),
|
position=(width / 2 - offset, height / 2 +
|
||||||
|
[offset - crosshair, -offset + crosshair * 0.3][j]),
|
||||||
size=(3, crosshair * 1.1)
|
size=(3, crosshair * 1.1)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
@ -1211,7 +1222,8 @@ class Player:
|
||||||
self.ui_hidden = hidden = not self.ui_hidden
|
self.ui_hidden = hidden = not self.ui_hidden
|
||||||
bui.textwidget(self.hide_text, text=self.hide_icons[hidden])
|
bui.textwidget(self.hide_text, text=self.hide_icons[hidden])
|
||||||
if hidden:
|
if hidden:
|
||||||
bui.apptimer(0.2, lambda: bui.buttonwidget(self.hide_button, texture=bui.gettexture('empty')))
|
bui.apptimer(0.2, lambda: bui.buttonwidget(
|
||||||
|
self.hide_button, texture=bui.gettexture('empty')))
|
||||||
self.fade_hide_button(0.4, -0.05)
|
self.fade_hide_button(0.4, -0.05)
|
||||||
self.destroy_ui()
|
self.destroy_ui()
|
||||||
else:
|
else:
|
||||||
|
|
@ -1258,7 +1270,8 @@ class Player:
|
||||||
bui.textwidget(self.pause_text, text=icon)
|
bui.textwidget(self.pause_text, text=icon)
|
||||||
if not dry:
|
if not dry:
|
||||||
if not silent:
|
if not silent:
|
||||||
self.show_message(['Resume', 'Pause'][self.paused], os.path.basename(self.path) + f' of {os.path.getsize(self.path)} bytes', self.COL6, self.COL7)
|
self.show_message(['Resume', 'Pause'][self.paused], os.path.basename(
|
||||||
|
self.path) + f' of {os.path.getsize(self.path)} bytes', self.COL6, self.COL7)
|
||||||
if self.paused:
|
if self.paused:
|
||||||
self.stop()
|
self.stop()
|
||||||
bs.pause_replay()
|
bs.pause_replay()
|
||||||
|
|
@ -1335,7 +1348,8 @@ class Player:
|
||||||
self.real_time = time()
|
self.real_time = time()
|
||||||
self.fix_pause()
|
self.fix_pause()
|
||||||
amount = abs(round(amount, 2))
|
amount = abs(round(amount, 2))
|
||||||
self.show_message('Seek', label + f" {amount} second{['s', ''][amount == 1]}", self.COL4, self.COL5)
|
self.show_message(
|
||||||
|
'Seek', label + f" {amount} second{['s', ''][amount == 1]}", self.COL4, self.COL5)
|
||||||
|
|
||||||
def jump(self, percent):
|
def jump(self, percent):
|
||||||
"""Jump with WYSIWYG behavior - percent is based on ESTIMATED duration, checked against CONFIRMED"""
|
"""Jump with WYSIWYG behavior - percent is based on ESTIMATED duration, checked against CONFIRMED"""
|
||||||
|
|
@ -1404,7 +1418,8 @@ class Player:
|
||||||
progress = self.progress_width
|
progress = self.progress_width
|
||||||
elif not self.duration_sec:
|
elif not self.duration_sec:
|
||||||
# Fallback if scan failed
|
# Fallback if scan failed
|
||||||
progress = min(elapsed / max(elapsed, 1) * self.progress_width * 0.1, self.progress_width * 0.1)
|
progress = min(elapsed / max(elapsed, 1) * self.progress_width *
|
||||||
|
0.1, self.progress_width * 0.1)
|
||||||
else:
|
else:
|
||||||
# Normal progress calculation, cap at 100%
|
# Normal progress calculation, cap at 100%
|
||||||
progress = min((elapsed / self.duration_sec) * self.progress_width, self.progress_width)
|
progress = min((elapsed / self.duration_sec) * self.progress_width, self.progress_width)
|
||||||
|
|
@ -1434,73 +1449,104 @@ class Player:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
|
|
||||||
|
|
||||||
def get_ui_scale(small, medium, large=None):
|
def get_ui_scale(small, medium, large=None):
|
||||||
scale = bui.app.ui_v1.uiscale
|
scale = bui.app.ui_v1.uiscale
|
||||||
return small if scale is bui.UIScale.SMALL else medium if scale is bui.UIScale.MEDIUM else (large or medium)
|
return small if scale is bui.UIScale.SMALL else medium if scale is bui.UIScale.MEDIUM else (large or medium)
|
||||||
return_to_menu = lambda: bui.app.classic.return_to_main_menu_session_gracefully(reset_ui=False)
|
|
||||||
show_warning = lambda text: (bui.getsound('block').play() or 1) and bui.screenmessage(text, color=(1, 1, 0))
|
|
||||||
format_time = lambda seconds: strftime('%H:%M:%S', gmtime(seconds))
|
def return_to_menu(): return bui.app.classic.return_to_main_menu_session_gracefully(reset_ui=False)
|
||||||
get_overlay_stack = lambda: bui.get_special_widget('overlay_stack')
|
def show_warning(text): return (bui.getsound('block').play()
|
||||||
round_tuple = lambda tup: type(tup)([round(val, 1) for val in tup])
|
or 1) and bui.screenmessage(text, color=(1, 1, 0))
|
||||||
|
|
||||||
|
|
||||||
|
def format_time(seconds): return strftime('%H:%M:%S', gmtime(seconds))
|
||||||
|
def get_overlay_stack(): return bui.get_special_widget('overlay_stack')
|
||||||
|
def round_tuple(tup): return type(tup)([round(val, 1) for val in tup])
|
||||||
|
|
||||||
|
|
||||||
# pybrp
|
# pybrp
|
||||||
Z = lambda _:[0]*_
|
def Z(_): return [0]*_
|
||||||
G_FREQS = lambda: [
|
|
||||||
101342,9667,3497,1072,0,3793,*Z(2),2815,5235,*Z(3),3570,*Z(3),
|
|
||||||
1383,*Z(3),2970,*Z(2),2857,*Z(8),1199,*Z(30),
|
def G_FREQS(): return [
|
||||||
1494,1974,*Z(12),1351,*Z(122),1475,*Z(65)
|
101342, 9667, 3497, 1072, 0, 3793, *Z(2), 2815, 5235, *Z(3), 3570, *Z(3),
|
||||||
|
1383, *Z(3), 2970, *Z(2), 2857, *Z(8), 1199, *Z(30),
|
||||||
|
1494, 1974, *Z(12), 1351, *Z(122), 1475, *Z(65)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class _Huffman:
|
class _Huffman:
|
||||||
class _N:
|
class _N:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.l,self.r,self.p,self.f=-1,-1,0,0
|
self.l, self.r, self.p, self.f = -1, -1, 0, 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.nodes=[self._N()for _ in range(511)]
|
self.nodes = [self._N()for _ in range(511)]
|
||||||
gf = G_FREQS()
|
gf = G_FREQS()
|
||||||
for i in range(256):self.nodes[i].f=gf[i]
|
for i in range(256):
|
||||||
nc=256
|
self.nodes[i].f = gf[i]
|
||||||
while nc<511:
|
nc = 256
|
||||||
s1,s2=-1,-1
|
while nc < 511:
|
||||||
i=0
|
s1, s2 = -1, -1
|
||||||
while self.nodes[i].p!=0:i+=1
|
i = 0
|
||||||
s1=i;i+=1
|
while self.nodes[i].p != 0:
|
||||||
while self.nodes[i].p!=0:i+=1
|
i += 1
|
||||||
s2=i;i+=1
|
s1 = i
|
||||||
while i<nc:
|
i += 1
|
||||||
if self.nodes[i].p==0:
|
while self.nodes[i].p != 0:
|
||||||
if self.nodes[s1].f>self.nodes[s2].f:
|
i += 1
|
||||||
if self.nodes[i].f<self.nodes[s1].f:s1=i
|
s2 = i
|
||||||
elif self.nodes[i].f<self.nodes[s2].f:s2=i
|
i += 1
|
||||||
i+=1
|
while i < nc:
|
||||||
self.nodes[nc].f=self.nodes[s1].f+self.nodes[s2].f
|
if self.nodes[i].p == 0:
|
||||||
self.nodes[s1].p=self.nodes[s2].p=nc-255
|
if self.nodes[s1].f > self.nodes[s2].f:
|
||||||
self.nodes[nc].r,self.nodes[nc].l=s1,s2
|
if self.nodes[i].f < self.nodes[s1].f:
|
||||||
nc+=1
|
s1 = i
|
||||||
def decompress(self,src):
|
elif self.nodes[i].f < self.nodes[s2].f:
|
||||||
if not src:return b''
|
s2 = i
|
||||||
rem,comp=src[0]&15,src[0]>>7
|
i += 1
|
||||||
if not comp:return src
|
self.nodes[nc].f = self.nodes[s1].f+self.nodes[s2].f
|
||||||
out,ptr,l=bytearray(),src[1:],len(src)
|
self.nodes[s1].p = self.nodes[s2].p = nc-255
|
||||||
bl=((l-1)*8)-rem;bit=0
|
self.nodes[nc].r, self.nodes[nc].l = s1, s2
|
||||||
while bit<bl:
|
nc += 1
|
||||||
m_bit=(ptr[bit>>3]>>(bit&7))&1;bit+=1
|
|
||||||
|
def decompress(self, src):
|
||||||
|
if not src:
|
||||||
|
return b''
|
||||||
|
rem, comp = src[0] & 15, src[0] >> 7
|
||||||
|
if not comp:
|
||||||
|
return src
|
||||||
|
out, ptr, l = bytearray(), src[1:], len(src)
|
||||||
|
bl = ((l-1)*8)-rem
|
||||||
|
bit = 0
|
||||||
|
while bit < bl:
|
||||||
|
m_bit = (ptr[bit >> 3] >> (bit & 7)) & 1
|
||||||
|
bit += 1
|
||||||
if m_bit:
|
if m_bit:
|
||||||
n=510
|
n = 510
|
||||||
while n>=256:
|
while n >= 256:
|
||||||
if bit>=bl:raise ValueError("Incomplete Huffman code")
|
if bit >= bl:
|
||||||
p_bit=(ptr[bit>>3]>>(bit&7))&1;bit+=1
|
raise ValueError("Incomplete Huffman code")
|
||||||
n=self.nodes[n].l if p_bit==0 else self.nodes[n].r
|
p_bit = (ptr[bit >> 3] >> (bit & 7)) & 1
|
||||||
|
bit += 1
|
||||||
|
n = self.nodes[n].l if p_bit == 0 else self.nodes[n].r
|
||||||
out.append(n)
|
out.append(n)
|
||||||
else:
|
else:
|
||||||
if bit+8>bl:break
|
if bit+8 > bl:
|
||||||
bi,b_in_b=bit>>3,bit&7
|
break
|
||||||
val=ptr[bi]if b_in_b==0 else(ptr[bi]>>b_in_b)|(ptr[bi+1]<<(8-b_in_b))
|
bi, b_in_b = bit >> 3, bit & 7
|
||||||
out.append(val&255);bit+=8
|
val = ptr[bi]if b_in_b == 0 else (ptr[bi] >> b_in_b) | (ptr[bi+1] << (8-b_in_b))
|
||||||
|
out.append(val & 255)
|
||||||
|
bit += 8
|
||||||
return bytes(out)
|
return bytes(out)
|
||||||
|
|
||||||
|
|
||||||
def get_replay_duration(_h, brp_path, progress):
|
def get_replay_duration(_h, brp_path, progress):
|
||||||
total_ms = 0
|
total_ms = 0
|
||||||
with open(brp_path, 'rb') as f:
|
with open(brp_path, 'rb') as f:
|
||||||
f.seek(0,2)
|
f.seek(0, 2)
|
||||||
progress[1] = f.tell()
|
progress[1] = f.tell()
|
||||||
f.seek(6)
|
f.seek(6)
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -1539,16 +1585,21 @@ def get_replay_duration(_h, brp_path, progress):
|
||||||
# brobord collide grass
|
# brobord collide grass
|
||||||
# ba_meta require api 9
|
# ba_meta require api 9
|
||||||
# ba_meta export babase.Plugin
|
# ba_meta export babase.Plugin
|
||||||
|
|
||||||
|
|
||||||
class byBordd(Plugin):
|
class byBordd(Plugin):
|
||||||
has_settings_ui = lambda c=0: True
|
def has_settings_ui(c=0): return True
|
||||||
show_settings_ui = lambda c=0, w=None: Replay(source=w)
|
def show_settings_ui(c=0, w=None): return Replay(source=w)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
from bauiv1lib.ingamemenu import InGameMenuWindow as ingame
|
from bauiv1lib.ingamemenu import InGameMenuWindow as ingame
|
||||||
orig_refresh = getattr(ingame, '_refresh_in_game')
|
orig_refresh = getattr(ingame, '_refresh_in_game')
|
||||||
setattr(ingame, '_refresh_in_game', lambda window, *args, **kwargs: (self.add_button(window), orig_refresh(window, *args, **kwargs))[1])
|
setattr(ingame, '_refresh_in_game', lambda window, *args, **
|
||||||
|
kwargs: (self.add_button(window), orig_refresh(window, *args, **kwargs))[1])
|
||||||
from bauiv1lib.watch import WatchWindow as watch
|
from bauiv1lib.watch import WatchWindow as watch
|
||||||
orig_init = getattr(watch, '__init__')
|
orig_init = getattr(watch, '__init__')
|
||||||
setattr(watch, '__init__', lambda window, *args, **kwargs: (orig_init(window, *args, **kwargs), self.add_button(window, 1))[0])
|
setattr(watch, '__init__', lambda window, *args, **
|
||||||
|
kwargs: (orig_init(window, *args, **kwargs), self.add_button(window, 1))[0])
|
||||||
|
|
||||||
def add_button(self, window, watch_mode=0):
|
def add_button(self, window, watch_mode=0):
|
||||||
if watch_mode:
|
if watch_mode:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue