[ci] auto-format

This commit is contained in:
Loup-Garou911XD 2022-09-30 12:30:48 +00:00 committed by github-actions[bot]
parent ede95e386e
commit da3bb374b3

View file

@ -1,4 +1,4 @@
#mood light plugin by ʟօʊքɢǟʀօʊ # mood light plugin by ʟօʊքɢǟʀօʊ
# ba_meta require api 7 # ba_meta require api 7
from __future__ import annotations from __future__ import annotations
@ -14,231 +14,240 @@ from bastd.gameutils import SharedObjects
from time import sleep from time import sleep
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Any, Sequence, Callable, List, Dict, Tuple, Optional, Union from typing import Any, Sequence, Callable, List, Dict, Tuple, Optional, Union
def Print(arg1,arg2="",arg3=""):
ba.screenmessage(str(arg1)+str(arg2)+str(arg3)) def Print(arg1, arg2="", arg3=""):
ba.screenmessage(str(arg1)+str(arg2)+str(arg3))
try: try:
with open("moodlightSettings.txt","r") as mltxt: with open("moodlightSettings.txt", "r") as mltxt:
global Ldefault,Udefault global Ldefault, Udefault
data=mltxt.read() data = mltxt.read()
Ldefault,Udefault=data.split("\n") Ldefault, Udefault = data.split("\n")
Ldefault=int(Ldefault) Ldefault = int(Ldefault)
Udefault=int(Udefault) Udefault = int(Udefault)
except: except:
with open("moodlightSettings.txt","w") as mltxt: with open("moodlightSettings.txt", "w") as mltxt:
mltxt.write("15 \n 20") mltxt.write("15 \n 20")
Ldefault,Udefault=15,20 Ldefault, Udefault = 15, 20
class SettingWindow(ba.Window): class SettingWindow(ba.Window):
def __init__(self): def __init__(self):
self.draw_ui() self.draw_ui()
def increase_limit(self): def increase_limit(self):
global Ldefault,Udefault global Ldefault, Udefault
try: try:
if Udefault>=29 and self.selected=="upper": if Udefault >= 29 and self.selected == "upper":
ba.textwidget(edit=self.warn_text,text="Careful!You risk get blind beyond this point") ba.textwidget(edit=self.warn_text,
elif self.selected=="lower" and Ldefault>=-20 or self.selected=="upper" and Udefault<=30: text="Careful!You risk get blind beyond this point")
ba.textwidget(edit=self.warn_text,text="") elif self.selected == "lower" and Ldefault >= -20 or self.selected == "upper" and Udefault <= 30:
if self.selected=="lower": ba.textwidget(edit=self.warn_text, text="")
Ldefault += 1 if self.selected == "lower":
ba.textwidget(edit=self.lower_text,text=str(Ldefault)) Ldefault += 1
elif self.selected=="upper": ba.textwidget(edit=self.lower_text, text=str(Ldefault))
Udefault+=1 elif self.selected == "upper":
ba.textwidget(edit=self.upper_text,text=str(Udefault)) Udefault += 1
except AttributeError: ba.textwidget(edit=self.upper_text, text=str(Udefault))
ba.textwidget(edit=self.warn_text,text="Click on number to select it") except AttributeError:
ba.textwidget(edit=self.warn_text, text="Click on number to select it")
def decrease_limit(self):
global Ldefault,Udefault def decrease_limit(self):
try: global Ldefault, Udefault
if Ldefault<=-19 and self.selected == "lower": try:
ba.textwidget(edit=self.warn_text,text="DON'T BE AFRAID OF DARK,IT'S A PLACE WHERE YOU CAN HIDE") if Ldefault <= -19 and self.selected == "lower":
elif (self.selected == "upper" and Udefault <=30) or (self.selected== "lower" and Ldefault>=-20): ba.textwidget(edit=self.warn_text,
ba.textwidget(edit=self.warn_text,text="") text="DON'T BE AFRAID OF DARK,IT'S A PLACE WHERE YOU CAN HIDE")
if self.selected=="lower": elif (self.selected == "upper" and Udefault <= 30) or (self.selected == "lower" and Ldefault >= -20):
Ldefault -= 1 ba.textwidget(edit=self.warn_text, text="")
ba.textwidget(edit=self.lower_text,text=str(Ldefault)) if self.selected == "lower":
elif self.selected=="upper": Ldefault -= 1
Udefault -=1 ba.textwidget(edit=self.lower_text, text=str(Ldefault))
ba.textwidget(edit=self.upper_text,text=str(Udefault)) elif self.selected == "upper":
except AttributeError: Udefault -= 1
ba.textwidget(edit=self.warn_text,text="Click on number to select it") ba.textwidget(edit=self.upper_text, text=str(Udefault))
except AttributeError:
def on_text_click(self,selected): ba.textwidget(edit=self.warn_text, text="Click on number to select it")
self.selected=selected
if selected=="upper": def on_text_click(self, selected):
ba.textwidget(edit=self.upper_text,color=(0,0,1)) self.selected = selected
ba.textwidget(edit=self.lower_text,color=(1,1,1)) if selected == "upper":
elif selected=="lower": ba.textwidget(edit=self.upper_text, color=(0, 0, 1))
ba.textwidget(edit=self.lower_text,color=(0,0,1)) ba.textwidget(edit=self.lower_text, color=(1, 1, 1))
ba.textwidget(edit=self.upper_text,color=(1,1,1)) elif selected == "lower":
else: ba.textwidget(edit=self.lower_text, color=(0, 0, 1))
Print("this should't happen from on_text_click") ba.textwidget(edit=self.upper_text, color=(1, 1, 1))
else:
def draw_ui(self): Print("this should't happen from on_text_click")
self.uiscale=ba.app.ui.uiscale
def draw_ui(self):
super().__init__( self.uiscale = ba.app.ui.uiscale
root_widget=ba.containerwidget(
size=(670, 670), super().__init__(
on_outside_click_call=self.close, root_widget=ba.containerwidget(
transition="in_right",)) size=(670, 670),
on_outside_click_call=self.close,
moodlight_label=ba.textwidget( transition="in_right",))
parent=self._root_widget,
size=(200,100), moodlight_label = ba.textwidget(
position=(150,550), parent=self._root_widget,
scale=2, size=(200, 100),
h_align="center", position=(150, 550),
v_align="center", scale=2,
text="Mood light settings", h_align="center",
color=(0,1,0)) v_align="center",
text="Mood light settings",
increase_button=ba.buttonwidget( color=(0, 1, 0))
parent=self._root_widget,
position=(600,100), increase_button = ba.buttonwidget(
size=(5,1), parent=self._root_widget,
scale=3.5, position=(600, 100),
extra_touch_border_scale=2.5, size=(5, 1),
icon=ba.gettexture("upButton"), scale=3.5,
on_activate_call=self.increase_limit) extra_touch_border_scale=2.5,
icon=ba.gettexture("upButton"),
decrease_button=ba.buttonwidget( on_activate_call=self.increase_limit)
parent=self._root_widget,
position=(100,100), decrease_button = ba.buttonwidget(
size=(5,1), parent=self._root_widget,
scale=3.5, position=(100, 100),
extra_touch_border_scale=2.5, size=(5, 1),
icon=ba.gettexture("downButton"), scale=3.5,
on_activate_call=self.decrease_limit) extra_touch_border_scale=2.5,
icon=ba.gettexture("downButton"),
self.lower_text=ba.textwidget( on_activate_call=self.decrease_limit)
parent=self._root_widget,
size=(200,100), self.lower_text = ba.textwidget(
scale=2, parent=self._root_widget,
position=(100,200), size=(200, 100),
h_align="center", scale=2,
v_align="center", position=(100, 200),
maxwidth=400.0, h_align="center",
text=str(Ldefault), v_align="center",
click_activate=True, maxwidth=400.0,
selectable=True) text=str(Ldefault),
click_activate=True,
lower_text_label=ba.textwidget( selectable=True)
parent=self._root_widget,
size=(200,100), lower_text_label = ba.textwidget(
position=(100,150), parent=self._root_widget,
h_align="center", size=(200, 100),
v_align="center", position=(100, 150),
text="Limit darkness") h_align="center",
v_align="center",
self.upper_text=ba.textwidget( text="Limit darkness")
parent=self._root_widget,
size=(200,100), self.upper_text = ba.textwidget(
scale=2, parent=self._root_widget,
position=(400,200), size=(200, 100),
h_align="center", scale=2,
v_align="center", position=(400, 200),
maxwidth=400.0, h_align="center",
text=str(Udefault), v_align="center",
click_activate=True, maxwidth=400.0,
selectable=True) text=str(Udefault),
click_activate=True,
upper_text_label=ba.textwidget( selectable=True)
parent=self._root_widget,
size=(200,100), upper_text_label = ba.textwidget(
position=(400,150), parent=self._root_widget,
h_align="center", size=(200, 100),
v_align="center", position=(400, 150),
text="Limit brightness") h_align="center",
v_align="center",
self.warn_text=ba.textwidget( text="Limit brightness")
parent=self._root_widget,
text="", self.warn_text = ba.textwidget(
size=(400,200), parent=self._root_widget,
position=(150,300), text="",
h_align="center", size=(400, 200),
v_align="center", position=(150, 300),
maxwidth=600) h_align="center",
v_align="center",
self.close_button=ba.buttonwidget( maxwidth=600)
parent=self._root_widget,
position=(550,590), self.close_button = ba.buttonwidget(
size=(35,35), parent=self._root_widget,
icon=ba.gettexture("crossOut"), position=(550, 590),
icon_color=(1,0.2,0.2), size=(35, 35),
scale=2, icon=ba.gettexture("crossOut"),
color=(1,0.2,0.2), icon_color=(1, 0.2, 0.2),
extra_touch_border_scale=5, scale=2,
on_activate_call=self.close, color=(1, 0.2, 0.2),
button_type="square") extra_touch_border_scale=5,
on_activate_call=self.close,
save_button=ba.buttonwidget( button_type="square")
parent=self._root_widget,
position=(520,470), save_button = ba.buttonwidget(
size=(90,70), parent=self._root_widget,
scale=1.5, position=(520, 470),
label="SAVE", size=(90, 70),
button_type="square", scale=1.5,
on_activate_call=self.save_settings) label="SAVE",
button_type="square",
ba.textwidget(edit=self.upper_text,on_activate_call=ba.Call(self.on_text_click,"upper")) on_activate_call=self.save_settings)
ba.textwidget(edit=self.lower_text,on_activate_call=ba.Call(self.on_text_click,"lower"))
ba.textwidget(edit=self.upper_text, on_activate_call=ba.Call(self.on_text_click, "upper"))
def save_settings(self): ba.textwidget(edit=self.lower_text, on_activate_call=ba.Call(self.on_text_click, "lower"))
with open("moodlightSettings.txt","w") as mltxt:
data="\n".join([str(Ldefault),str(Udefault)]) def save_settings(self):
mltxt.write(data) with open("moodlightSettings.txt", "w") as mltxt:
Print("settings saved") data = "\n".join([str(Ldefault), str(Udefault)])
self.close() mltxt.write(data)
Print("settings saved")
def close(self): self.close()
ba.containerwidget(edit=self._root_widget, transition="out_right",)
def close(self):
ba.containerwidget(edit=self._root_widget, transition="out_right",)
# ba_meta export plugin # ba_meta export plugin
class moodlight(ba.Plugin): class moodlight(ba.Plugin):
def __init__(self): def __init__(self):
pass pass
Map._old_init = Map.__init__ Map._old_init = Map.__init__
def on_app_running(self): def on_app_running(self):
try: try:
_ba.timer(0.5, self.on_chat_message, True) _ba.timer(0.5, self.on_chat_message, True)
except Exception as err: except Exception as err:
Print(err) Print(err)
def on_chat_message(self): def on_chat_message(self):
messages=_ba.get_chat_messages() messages = _ba.get_chat_messages()
if len(messages)>0: if len(messages) > 0:
lastmessage=messages[-1].split(":")[-1].strip().lower() lastmessage = messages[-1].split(":")[-1].strip().lower()
if lastmessage in ("/mood light","/mood lighting","/mood_light","/mood_lighting","/moodlight","ml"): if lastmessage in ("/mood light", "/mood lighting", "/mood_light", "/mood_lighting", "/moodlight", "ml"):
with open("moodlightSettings.txt","r") as mltxt: with open("moodlightSettings.txt", "r") as mltxt:
global Ldefault,Udefault global Ldefault, Udefault
data=mltxt.read() data = mltxt.read()
Ldefault,Udefault=data.split("\n") Ldefault, Udefault = data.split("\n")
Ldefault=int(Ldefault) Ldefault = int(Ldefault)
Udefault=int(Udefault) Udefault = int(Udefault)
SettingWindow() SettingWindow()
_ba.chatmessage("Mood light settings opened") _ba.chatmessage("Mood light settings opened")
def on_plugin_manager_prompt(self): def on_plugin_manager_prompt(self):
SettingWindow() SettingWindow()
def _new_init(self, vr_overlay_offset: Optional[Sequence[float]] = None) -> None: def _new_init(self, vr_overlay_offset: Optional[Sequence[float]] = None) -> None:
self._old_init(vr_overlay_offset) self._old_init(vr_overlay_offset)
in_game = not isinstance(_ba.get_foreground_host_session(), mainmenu.MainMenuSession) in_game = not isinstance(_ba.get_foreground_host_session(), mainmenu.MainMenuSession)
if not in_game: return if not in_game:
return
gnode = _ba.getactivity().globalsnode gnode = _ba.getactivity().globalsnode
def changetint(): def changetint():
Range=(random.randrange(Ldefault,Udefault)/10, random.randrange(Ldefault,Udefault)/10, random.randrange(Ldefault,Udefault)/10) Range = (random.randrange(Ldefault, Udefault)/10, random.randrange(Ldefault,
ba.animate_array(gnode, 'tint', 3, { Udefault)/10, random.randrange(Ldefault, Udefault)/10)
0.0: gnode.tint, ba.animate_array(gnode, 'tint', 3, {
1.0: Range 0.0: gnode.tint,
}) 1.0: Range
_ba.timer(0.3, changetint, repeat= True) })
Map.__init__ = _new_init _ba.timer(0.3, changetint, repeat=True)
Map.__init__ = _new_init