[ci] auto-format

This commit is contained in:
BroBordd 2025-08-10 13:02:22 +00:00 committed by github-actions[bot]
parent bba1a27837
commit 99611b9ae6
8 changed files with 1960 additions and 1387 deletions

View file

@ -46,22 +46,25 @@ from bauiv1lib.ingamemenu import InGameMenuWindow as igm
from babase import Plugin, InputType as IT
from math import sqrt, dist
class Camera:
__doc__ = 'A simple camera.'
__ins__ = None
__lst__ = None
__yes__ = False
def __init__(s) -> None:
c = s.__class__
if c.__yes__:
note('Stopped camera!',True)
note('Stopped camera!', True)
c.__ins__.done(talk=False)
return
c.__ins__ = s
c.__yes__ = True
if c.__lst__: SCM(False)
if c.__lst__:
SCM(False)
s.stage = 0
p = (0,1,0)
p = (0, 1, 0)
s.tex = 'achievementCrossHair'
s.kids = []
s.okay = []
@ -94,7 +97,7 @@ class Camera:
'is_area_of_interest': True
}
)
tick(0.15, animate(n,'mesh_scale',{0:2,0.1:0.5}).delete)
tick(0.15, animate(n, 'mesh_scale', {0: 2, 0.1: 0.5}).delete)
gbs('powerup01').play(position=p)
s.step = 0.01
s.node = n
@ -104,7 +107,7 @@ class Camera:
s.overlay = Overlay()
LN({
'UP_DOWN': lambda a: s.manage(a),
'LEFT_RIGHT': lambda a: s.manage(a,1),
'LEFT_RIGHT': lambda a: s.manage(a, 1),
'PICK_UP_PRESS': lambda: s.start(2),
'JUMP_PRESS': lambda: s.start(0),
'PICK_UP_RELEASE': lambda: s.stop(2),
@ -116,58 +119,61 @@ class Camera:
})
s.move()
"""Write a tip"""
def tip(s,t,p,h='left',b=True):
def tip(s, t, p, h='left', b=True):
n = newnode(
'text',
attrs={
'in_world': True,
'scale': 0.01,
'flatness': 1,
'color': (1,1,1),
'color': (1, 1, 1),
'shadow': 1.0,
'position': p,
'text': t,
'h_align': h
}
)
if b: s.kids.append(n)
if b:
s.kids.append(n)
return n
"""Create a dot"""
def dot(s,p,b=True,tex='black'):
def dot(s, p, b=True, tex='black'):
n = newnode(
'prop',
delegate=s,
attrs={
'mesh': getmesh('tnt'),
'color_texture': gbt(tex),
'body': 'crate',
'mesh_scale': 0.1,
'position': p,
'gravity_scale': 0,
'materials': [s.M],
}
attrs={
'mesh': getmesh('tnt'),
'color_texture': gbt(tex),
'body': 'crate',
'mesh_scale': 0.1,
'position': p,
'gravity_scale': 0,
'materials': [s.M],
}
)
if b: s.kids.append(n)
if b:
s.kids.append(n)
return n
"""Draw a line"""
def line(s,p1,p2,i=2,tex='black'):
x1,y1,z1 = p1
x2,y2,z2 = p2
n = dist(p1,p2)*i
for i in range(1,int(n+1)):
def line(s, p1, p2, i=2, tex='black'):
x1, y1, z1 = p1
x2, y2, z2 = p2
n = dist(p1, p2)*i
for i in range(1, int(n+1)):
t = i/n
x = x1+t*(x2-x1)
y = y1+t*(y2-y1)
z = z1+t*(z2-z1)
s.kids.append(s.dot((x,y,z),tex=tex))
s.kids.append(s.dot((x, y, z), tex=tex))
"""Mark"""
def mark(s):
if not s.stage:
s.stage = 1
p = s.getpos()
s.p1 = (p[0]-0.01,p[1],p[2])
s.okay.append(s.dot(s.p1,b=False))
s.okay.append(s.tip(f'Camera position\n{tuple([round(i,2) for i in s.p1])}',s.p1,b=False))
s.p1 = (p[0]-0.01, p[1], p[2])
s.okay.append(s.dot(s.p1, b=False))
s.okay.append(
s.tip(f'Camera position\n{tuple([round(i, 2) for i in s.p1])}', s.p1, b=False))
else:
[i.delete() for i in s.kids]
s.kids.clear()
@ -201,16 +207,17 @@ class Camera:
s.line(s.p1, bl)
m = 4
j = {'tex':'crossOutMask'}
j = {'tex': 'crossOutMask'}
s.line(tr, tl, m, **j)
s.line(tl, bl, m, **j)
s.line(bl, br, m, **j)
s.line(br, tr, m, **j)
s.tip(f'Your display\n{r[0]}x{r[1]} px\n{tuple([round(i,2) for i in p2])}',tr,'right')
s.tip(
f'Your display\n{r[0]}x{r[1]} px\n{tuple([round(i, 2) for i in p2])}', tr, 'right')
s.stage = 2
s.overlay.press(3)
tick(0.25, animate(s.node,'mesh_scale',{0:0.5,0.1:0.2,0.2:0.5}).delete)
tick(0.25, animate(s.node, 'mesh_scale', {0: 0.5, 0.1: 0.2, 0.2: 0.5}).delete)
gbs('gunCocking').play(position=s.node.position)
"""Handle events"""
def handlemessage(s, m):
@ -237,117 +244,132 @@ class Camera:
def reset(s):
s.__class__.__yes__ = False
me = getme()
if not me: return
if not me:
return
me.resetinput()
with ga().context: me.actor.connect_controls_to_player()
with ga().context:
me.actor.connect_controls_to_player()
[i.delete() for i in (s.kids+s.okay)]
"""Manage movement"""
def manage(s,a,lr=0):
if lr: s.llr = a; return
def manage(s, a, lr=0):
if lr:
s.llr = a
return
s.lud = a
"""Move"""
def move(s):
m = getme(1)
if (not m) or m._dead: s.destroy()
try: p = s.getpos()
if (not m) or m._dead:
s.destroy()
try:
p = s.getpos()
except:
s.overlay.destroy()
return
s.setpos((p[0]+s.llr*s.step,p[1],p[2]-s.lud*s.step))
s.overlay.up(*p,s.llr,s.lud)
s.setpos((p[0]+s.llr*s.step, p[1], p[2]-s.lud*s.step))
s.overlay.up(*p, s.llr, s.lud)
SCT(*p)
teck(s.wait,s.move)
teck(s.wait, s.move)
"""Start elevating"""
def start(s,i):
def start(s, i):
s.overlay.press(i)
s.mode = i
s.loop(i)
"""Keep elevating"""
def loop(s,i):
if s.mode != i: return
try: p = list(s.node.position)
except: return
def loop(s, i):
if s.mode != i:
return
try:
p = list(s.node.position)
except:
return
p[1] += s.step if i else -s.step
s.node.position = tuple(p)
teck(s.wait, lambda: s.loop(i))
"""Stop elevating"""
def stop(s,i):
def stop(s, i):
s.overlay.release(i)
s.mode = 4
"""Get position"""
def getpos(s):
return s.node.position
"""Set position"""
def setpos(s,p):
def setpos(s, p):
s.node.position = p
"""Done"""
def done(s,talk=True):
def done(s, talk=True):
s.overlay.press(1)
s.overlay.destroy()
try: p = s.node.position
except: return
try:
p = s.node.position
except:
return
with ga().context:
gbs('laser').play(position=p)
tick(0.2,animate(s.node,'mesh_scale',{0:0.5,0.08:1,0.2:0}).delete)
tick(0.2,s.node.delete)
tick(0.2, animate(s.node, 'mesh_scale', {0: 0.5, 0.08: 1, 0.2: 0}).delete)
tick(0.2, s.node.delete)
s.reset()
if s.stage > 1 and talk:
SCM(True)
SCP(*s.p1)
SCT(*s.p2)
var('lp1',s.p1)
var('lp2',s.p2)
var('lp1', s.p1)
var('lp2', s.p2)
nice('Applied!')
elif talk:
note('Incomplete camera setup\nNo changes applied.')
if s.__class__.__ins__ == s: s.__class__.__ins__ = None
if s.__class__.__ins__ == s:
s.__class__.__ins__ = None
"""Controls overlay"""
class Overlay:
__lst__ = None
"""Place nodes"""
def __init__(s):
s.__class__.__lst__ = str(ga())
s.colors = [
[(0.2,0.6,0.2),(0.4,1,0.4)],
[(0.6,0,0),(1,0,0)],
[(0.2,0.6,0.6),(0.4,1,1)],
[(0.6,0.6,0.2),(1,1,0.4)],
[(0.3,0.23,0.5),(0.2,0.13,0.3)]
[(0.2, 0.6, 0.2), (0.4, 1, 0.4)],
[(0.6, 0, 0), (1, 0, 0)],
[(0.2, 0.6, 0.6), (0.4, 1, 1)],
[(0.6, 0.6, 0.2), (1, 1, 0.4)],
[(0.3, 0.23, 0.5), (0.2, 0.13, 0.3)]
]
s.pics = []
s.texts = []
s.pos = []
s.nub = []
s.old = [0,0,0]
s.old = [0, 0, 0]
s.dead = False
with ga().context:
for i in range(4):
j = ['Jump','Bomb','PickUp','Punch'][i]
k = [600,650,600,550][i]
l = [170,220,270,220][i]
j = ['Jump', 'Bomb', 'PickUp', 'Punch'][i]
k = [600, 650, 600, 550][i]
l = [170, 220, 270, 220][i]
c = s.colors[i][0]
n = newnode(
'image',
attrs={
'texture': gbt('button'+j),
'absolute_scale': True,
'position': (k,l),
'scale': (60,60),
'position': (k, l),
'scale': (60, 60),
'color': c
}
)
s.pics.append(n)
j = ['Down','Done','Up','Mark'][i]
k = [600,680,600,515][i]
l = [115,220,325,220][i]
h = ['center','left','center','right'][i]
v = ['bottom','center','top','center'][i]
j = ['Down', 'Done', 'Up', 'Mark'][i]
k = [600, 680, 600, 515][i]
l = [115, 220, 325, 220][i]
h = ['center', 'left', 'center', 'right'][i]
v = ['bottom', 'center', 'top', 'center'][i]
n = newnode(
'text',
attrs={
'text': j,
'position': (k,l),
'position': (k, l),
'color': c,
'h_align': h,
'v_align': v
@ -355,92 +377,103 @@ class Overlay:
)
s.texts.append(n)
for i in range(3):
c = s.colors[[1,0,2][i]][0]
c = s.colors[[1, 0, 2][i]][0]
n = newnode(
'text',
attrs={
'text': '0',
'position': (640,155-30*i),
'position': (640, 155-30*i),
'color': c,
'h_align': 'left'
}
)
s.pos.append(n)
s.np = (790,140)
for i in [0,1]:
j = [110,60][i]
s.np = (790, 140)
for i in [0, 1]:
j = [110, 60][i]
n = newnode(
'image',
attrs={
'texture': gbt('nub'),
'absolute_scale': True,
'position': s.np,
'scale': (j,j),
'scale': (j, j),
'color': s.colors[4][i]
}
)
s.nub.append(n)
s.fade()
"""Color overlays"""
def set(s,i,c):
def set(s, i, c):
s.pics[i].color = s.texts[i].color = c
"""Color position"""
def pset(s,i,c):
def pset(s, i, c):
s.pos[i].color = c
"""Simulate pressed"""
def press(s,i):
s.set(i,s.colors[i][1])
def press(s, i):
s.set(i, s.colors[i][1])
s.pics[i].opacity = 1.0
"""Simulate released"""
def release(s,i):
s.set(i,s.colors[i][0])
def release(s, i):
s.set(i, s.colors[i][0])
s.pics[i].opacity = 0.7
"""Get all nodes"""
def nodes(s):
return s.pics+s.texts+s.pos+s.nub
"""Update position"""
def up(s,x,y,z,lr,ud):
new = [x,y,z]
def up(s, x, y, z, lr, ud):
new = [x, y, z]
for i in range(3):
c = s.colors[[1,0,2][i]]
if s.old[i] == new[i]: s.pset(i,c[0]); continue
c = s.colors[[1, 0, 2][i]]
if s.old[i] == new[i]:
s.pset(i, c[0])
continue
t = s.pos[i]
t.text = str(round(new[i],5))
s.pset(i,c[1])
t.text = str(round(new[i], 5))
s.pset(i, c[1])
s.old = new
[setattr(s.nub[i],'opacity',[[0.5,0.2],[0.7,0.3]][bool(lr or ud)][i]) for i in [0,1]]
[setattr(s.nub[i], 'opacity', [[0.5, 0.2], [0.7, 0.3]][bool(lr or ud)][i]) for i in [0, 1]]
p = s.np
m = sqrt(lr**2+ud**2) or 1
d = 25*min(sqrt(lr**2+ud**2),1)
d = 25*min(sqrt(lr**2+ud**2), 1)
lr /= m
ud /= m
s.nub[1].position = (p[0]+lr*d,p[1]+ud*d)
s.nub[1].position = (p[0]+lr*d, p[1]+ud*d)
"""Fade"""
def fade(s,i=0):
if str(ga()) != s.__class__.__lst__: return
def fade(s, i=0):
if str(ga()) != s.__class__.__lst__:
return
mem = s.nodes()
[tick(1, animate(n,'opacity',{0:i,0.5:abs(i-0.7)}).delete) for n in mem]
[tick(1, animate(n, 'opacity', {0: i, 0.5: abs(i-0.7)}).delete) for n in mem]
"""Destroy overlay"""
def destroy(s):
if s.dead: return
if s.dead:
return
s.dead = True
with ga().context:
tick(0.2,lambda:s.fade(0.7))
tick(2,lambda: [n.delete() for n in s.nodes()])
tick(0.2, lambda: s.fade(0.7))
tick(2, lambda: [n.delete() for n in s.nodes()])
# Mini tools
note = lambda t, b=False: (push(t,color=(1,1,0)),gs('block').play() if b else None)
nice = lambda t: (push(t,color=(0,1,0)),gs('dingSmallHigh').play())
SCM = lambda b: (setattr(Camera,'__lst__',b),SSCM(b))
scale = lambda v,s: (v[0]*s,v[1]*s,v[2]*s)
cross = lambda a,b: (a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0])
sub = lambda a,b: (a[0]-b[0],a[1]-b[1],a[2]-b[2])
add = lambda a,b: (a[0]+b[0],a[1]+b[1],a[2]+b[2])
def note(t, b=False): return (push(t, color=(1, 1, 0)), gs('block').play() if b else None)
def nice(t): return (push(t, color=(0, 1, 0)), gs('dingSmallHigh').play())
def SCM(b): return (setattr(Camera, '__lst__', b), SSCM(b))
def scale(v, s): return (v[0]*s, v[1]*s, v[2]*s)
def cross(a, b): return (a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0])
def sub(a, b): return (a[0]-b[0], a[1]-b[1], a[2]-b[2])
def add(a, b): return (a[0]+b[0], a[1]+b[1], a[2]+b[2])
def getme(actor=0):
for p in ga().players:
if p.sessionplayer.inputdevice.client_id == -1:
return p.actor if actor else p
def LN(d): me = getme(); [me.assigninput(getattr(IT,k), d[k]) for k in d]
def LN(d): me = getme(); [me.assigninput(getattr(IT, k), d[k]) for k in d]
def RESUME():
u = APP.ui_v1
c = APP.classic
@ -448,70 +481,80 @@ def RESUME():
u.clear_main_window()
[z() for z in c.main_menu_resume_callbacks]
c.main_menu_resume_callbacks.clear()
def norm(v):
a,b,c = v
a, b, c = v
l = sqrt(a**2+b**2+c**2)
return (0, 0, 0) if l == 0 else (a/l,b/l,c/l)
def var(s,v=None):
return (0, 0, 0) if l == 0 else (a/l, b/l, c/l)
def var(s, v=None):
c = APP.config
s = 'cam_'+s
if v is None: return c.get(s,v)
if v is None:
return c.get(s, v)
c[s] = v
c.commit()
# brobord collide grass
# ba_meta require api 9
# ba_meta export babase.Plugin
class byBordd(Plugin):
has_settings_ui = lambda s: True
show_settings_ui = lambda s, src: s.ui(source=src)
col = (0.18,0.18,0.18)
def has_settings_ui(s): return True
def show_settings_ui(s, src): return s.ui(source=src)
col = (0.18, 0.18, 0.18)
def __init__(s):
o = igm._refresh_in_game
def e(f,*a,**k):
r = o(f,*a,**k)
def e(f, *a, **k):
r = o(f, *a, **k)
b = bw(
label='',
size=(90,40),
size=(90, 40),
button_type='square',
parent=f._root_widget,
color=(0.18,0.18,0.18),
position=(f._width-20,0),
color=(0.18, 0.18, 0.18),
position=(f._width-20, 0),
)
bw(b,on_activate_call=lambda:s.ui(source=b,main=True))
bw(b, on_activate_call=lambda: s.ui(source=b, main=True))
iw(
size=(40,40),
size=(40, 40),
texture=gt('tv'),
parent=f._root_widget,
position=(f._width-20,5)
position=(f._width-20, 5)
)
tw(
maxwidth=50,
text='Camera',
h_align='left',
parent=f._root_widget,
position=(f._width+15,0)
position=(f._width+15, 0)
)
return r
igm._refresh_in_game = e
"""The UI"""
def ui(s,source=None,main=False):
def ui(s, source=None, main=False):
s.main = main
off = source.get_screen_space_center() if source else (0,0)
off = source.get_screen_space_center() if source else (0, 0)
w = cw(
color=s.col,
size=(350,305),
size=(350, 305),
stack_offset=off,
transition='in_scale',
parent=gsw('overlay_stack'),
scale_origin_stack_offset=off
)
s.back = lambda b=True: (cw(w,transition=['out_right','out_scale'][bool(source) and b]),gs('swish').play() if b else None)
cw(w,on_outside_click_call=s.back)
s.back = lambda b=True: (
cw(w, transition=['out_right', 'out_scale'][bool(source) and b]), gs('swish').play() if b else None)
cw(w, on_outside_click_call=s.back)
b = Camera.__yes__
t = [
('Camera is ready!',(0,1,1)),
('Camera is running!',(0,1,0)),
('Camera is ready!', (0, 1, 1)),
('Camera is running!', (0, 1, 0)),
][b]
tw(
parent=w,
@ -519,59 +562,68 @@ class byBordd(Plugin):
scale=1.5,
color=t[1],
h_align='center',
position=(155,250)
position=(155, 250)
)
for i in range(4):
j = [
('3D Camera mapper',s.start),
('Last mapped config',s.load),
('Last dev command',s.copy),
('Reset all settings',s.reset)
('3D Camera mapper', s.start),
('Last mapped config', s.load),
('Last dev command', s.copy),
('Reset all settings', s.reset)
][i]
tw(
parent=w,
text=j[0],
maxwidth=195,
position=(20,30+55*i)
position=(20, 30+55*i)
)
k = [
(['Start','Stop'][b],'cursor'),
('Load','achievementOutline'),
('Copy','file'),
('Reset','replayIcon')
(['Start', 'Stop'][b], 'cursor'),
('Load', 'achievementOutline'),
('Copy', 'file'),
('Reset', 'replayIcon')
][i]
bw(
parent=w,
label=k[0],
color=s.col,
size=(120,50),
size=(120, 50),
icon=gt(k[1]),
enable_sound=not i,
textcolor=(1,1,1),
textcolor=(1, 1, 1),
button_type='square',
on_activate_call=j[1],
position=(220,20+55*i)
position=(220, 20+55*i)
)
"""Gather last"""
def gather(s):
return var('lp1'),var('lp2')
return var('lp1'), var('lp2')
"""Reset"""
def reset(s):
SCM(False)
nice('Resetored original settings!')
"""Copy last"""
def copy(s):
if not CIS(): note('Unsupported!',True); return
if not CIS():
note('Unsupported!', True)
return
g = s.gather()
if not g[1]: note('Apply something first!',True); return
g = [tuple([round(i,2) for i in j]) for j in g]
COPY(f'from _babase import set_camera_manual as SCM, set_camera_target as SCT, set_camera_position as SCP; SCM(True); SCP(*{g[0]}); SCT(*{g[1]})')
if not g[1]:
note('Apply something first!', True)
return
g = [tuple([round(i, 2) for i in j]) for j in g]
COPY(
f'from _babase import set_camera_manual as SCM, set_camera_target as SCT, set_camera_position as SCP; SCM(True); SCP(*{g[0]}); SCT(*{g[1]})')
nice('Copied command!\nPaste it in dev console anytime to load config!')
"""Load last"""
def load(s):
g = s.gather()
if not g[1]: note('Apply something first!',True); return
if Camera.__yes__: note('Stop camera first!',True); return
if not g[1]:
note('Apply something first!', True)
return
if Camera.__yes__:
note('Stop camera first!', True)
return
SCM(True)
SCP(*g[0])
SCT(*g[1])
@ -579,8 +631,13 @@ class byBordd(Plugin):
"""Start camera"""
def start(s):
a = ga()
if not a: note('Only mapping requires you to be the host!\nYou still can load previous config though',True); return
if not getme(): note('Join the game first!',True); return
if not a:
note('Only mapping requires you to be the host!\nYou still can load previous config though', True)
return
if not getme():
note('Join the game first!', True)
return
s.back(False)
RESUME() if s.main else None
with a.context: Camera()
with a.context:
Camera()