mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-11-07 17:36:00 +00:00
Correct minigames enable/disable behaviour
This commit is contained in:
parent
d11d4eadcf
commit
4ec3a5a984
1 changed files with 55 additions and 36 deletions
|
|
@ -22,8 +22,8 @@ HEADERS = {
|
||||||
PLUGIN_DIRECTORY = _env["python_directory_user"]
|
PLUGIN_DIRECTORY = _env["python_directory_user"]
|
||||||
REGEXP = {
|
REGEXP = {
|
||||||
"plugin_api_version": re.compile(b"(?<=ba_meta require api )(.*)"),
|
"plugin_api_version": re.compile(b"(?<=ba_meta require api )(.*)"),
|
||||||
# "plugin_entry_points": re.compile(b"(ba_meta export plugin\n+class )(.*)\("),
|
"plugin_entry_points": re.compile(b"(ba_meta export plugin\n+class )(.*)\("),
|
||||||
"plugin_entry_points": re.compile(b"(ba_meta export .+\n+class )(.*)\("),
|
"minigames": re.compile(b"(ba_meta export game\n+class )(.*)\("),
|
||||||
}
|
}
|
||||||
|
|
||||||
VERSION = "0.1.1"
|
VERSION = "0.1.1"
|
||||||
|
|
@ -136,9 +136,13 @@ class PluginLocal:
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.install_path = os.path.join(PLUGIN_DIRECTORY, f"{name}.py")
|
self.install_path = os.path.join(PLUGIN_DIRECTORY, f"{name}.py")
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
self._content = None
|
self._content = None
|
||||||
self._api_version = None
|
self._api_version = None
|
||||||
self._entry_points = []
|
self._entry_points = []
|
||||||
|
self._contains_minigames = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_installed(self):
|
def is_installed(self):
|
||||||
|
|
@ -206,10 +210,15 @@ class PluginLocal:
|
||||||
self._entry_points = entry_points
|
self._entry_points = entry_points
|
||||||
return self._entry_points
|
return self._entry_points
|
||||||
|
|
||||||
@property
|
async def has_minigames(self):
|
||||||
def is_enabled(self):
|
if self._contains_minigames is None:
|
||||||
|
content = await self.get_content()
|
||||||
|
self._contains_minigames = REGEXP["minigames"].search(content) is not None
|
||||||
|
return self._contains_minigames
|
||||||
|
|
||||||
|
async def is_enabled(self):
|
||||||
"""
|
"""
|
||||||
Return True even if a single entry point is enabled.
|
Return True even if a single entry point is enabled or contains minigames.
|
||||||
"""
|
"""
|
||||||
entry_point_initials = f"{self.name}."
|
entry_point_initials = f"{self.name}."
|
||||||
for entry_point, plugin_info in ba.app.config["Plugins"].items():
|
for entry_point, plugin_info in ba.app.config["Plugins"].items():
|
||||||
|
|
@ -220,7 +229,7 @@ class PluginLocal:
|
||||||
# for entry_point in await self.get_entry_points():
|
# for entry_point in await self.get_entry_points():
|
||||||
# if ba.app.config["Plugins"][entry_point]["enabled"]:
|
# if ba.app.config["Plugins"][entry_point]["enabled"]:
|
||||||
# return True
|
# return True
|
||||||
return False
|
return await self.has_minigames()
|
||||||
|
|
||||||
# XXX: Commenting this out for now, since `enable` and `disable` currently have their
|
# XXX: Commenting this out for now, since `enable` and `disable` currently have their
|
||||||
# own separate logic.
|
# own separate logic.
|
||||||
|
|
@ -336,9 +345,14 @@ class Plugin:
|
||||||
|
|
||||||
class PluginWindow(popup.PopupWindow):
|
class PluginWindow(popup.PopupWindow):
|
||||||
def __init__(self, plugin, origin_widget, button_callback=lambda: None):
|
def __init__(self, plugin, origin_widget, button_callback=lambda: None):
|
||||||
play_sound()
|
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.button_callback = button_callback
|
self.button_callback = button_callback
|
||||||
|
self.scale_origin = origin_widget.get_screen_space_center()
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.create_task(self.draw_ui())
|
||||||
|
|
||||||
|
async def draw_ui(self):
|
||||||
|
play_sound()
|
||||||
b_text_color = (0.75, 0.7, 0.8)
|
b_text_color = (0.75, 0.7, 0.8)
|
||||||
s = 1.1 if _uiscale is ba.UIScale.SMALL else 1.27 if ba.UIScale.MEDIUM else 1.57
|
s = 1.1 if _uiscale is ba.UIScale.SMALL else 1.27 if ba.UIScale.MEDIUM else 1.57
|
||||||
width = 360 * s
|
width = 360 * s
|
||||||
|
|
@ -347,7 +361,6 @@ class PluginWindow(popup.PopupWindow):
|
||||||
text_scale = 0.7 * s
|
text_scale = 0.7 * s
|
||||||
self._transition_out = 'out_scale'
|
self._transition_out = 'out_scale'
|
||||||
transition = 'in_scale'
|
transition = 'in_scale'
|
||||||
scale_origin = origin_widget.get_screen_space_center()
|
|
||||||
self._root_widget = ba.containerwidget(size=(width, height),
|
self._root_widget = ba.containerwidget(size=(width, height),
|
||||||
parent=_ba.get_special_widget(
|
parent=_ba.get_special_widget(
|
||||||
'overlay_stack'),
|
'overlay_stack'),
|
||||||
|
|
@ -355,9 +368,9 @@ class PluginWindow(popup.PopupWindow):
|
||||||
transition=transition,
|
transition=transition,
|
||||||
scale=(2.1 if _uiscale is ba.UIScale.SMALL else 1.5
|
scale=(2.1 if _uiscale is ba.UIScale.SMALL else 1.5
|
||||||
if _uiscale is ba.UIScale.MEDIUM else 1.0),
|
if _uiscale is ba.UIScale.MEDIUM else 1.0),
|
||||||
scale_origin_stack_offset=scale_origin)
|
scale_origin_stack_offset=self.scale_origin)
|
||||||
pos = height * 0.8
|
pos = height * 0.8
|
||||||
plugin_title = f"{plugin.name} (v{plugin.latest_version})"
|
plugin_title = f"{self.plugin.name} (v{self.plugin.latest_version})"
|
||||||
ba.textwidget(parent=self._root_widget,
|
ba.textwidget(parent=self._root_widget,
|
||||||
position=(width * 0.49, pos), size=(0, 0),
|
position=(width * 0.49, pos), size=(0, 0),
|
||||||
h_align='center', v_align='center', text=plugin_title,
|
h_align='center', v_align='center', text=plugin_title,
|
||||||
|
|
@ -370,7 +383,7 @@ class PluginWindow(popup.PopupWindow):
|
||||||
size=(0, 0),
|
size=(0, 0),
|
||||||
h_align='center',
|
h_align='center',
|
||||||
v_align='center',
|
v_align='center',
|
||||||
text='by ' + plugin.info["authors"][0]["name"],
|
text='by ' + self.plugin.info["authors"][0]["name"],
|
||||||
scale=text_scale * 0.8,
|
scale=text_scale * 0.8,
|
||||||
color=color, maxwidth=width * 0.9)
|
color=color, maxwidth=width * 0.9)
|
||||||
pos -= 35
|
pos -= 35
|
||||||
|
|
@ -384,7 +397,7 @@ class PluginWindow(popup.PopupWindow):
|
||||||
ba.textwidget(parent=self._root_widget,
|
ba.textwidget(parent=self._root_widget,
|
||||||
position=(width * 0.49, pos), size=(0, 0),
|
position=(width * 0.49, pos), size=(0, 0),
|
||||||
h_align='center', v_align='center',
|
h_align='center', v_align='center',
|
||||||
text=plugin.info["description"],
|
text=self.plugin.info["description"],
|
||||||
scale=text_scale * 0.6, color=color,
|
scale=text_scale * 0.6, color=color,
|
||||||
maxwidth=width * 0.95)
|
maxwidth=width * 0.95)
|
||||||
b1_color = (0.6, 0.53, 0.63)
|
b1_color = (0.6, 0.53, 0.63)
|
||||||
|
|
@ -393,17 +406,21 @@ class PluginWindow(popup.PopupWindow):
|
||||||
pos = height * 0.1
|
pos = height * 0.1
|
||||||
button_size = (80 * s, 40 * s)
|
button_size = (80 * s, 40 * s)
|
||||||
|
|
||||||
if plugin.is_installed:
|
to_draw_button1 = True
|
||||||
self.local_plugin = plugin.get_local()
|
if self.plugin.is_installed:
|
||||||
if self.local_plugin.is_enabled:
|
self.local_plugin = self.plugin.get_local()
|
||||||
button1_label = "Disable"
|
if await self.local_plugin.has_minigames():
|
||||||
button1_action = self.disable
|
to_draw_button1 = False
|
||||||
else:
|
else:
|
||||||
button1_label = "Enable"
|
if await self.local_plugin.is_enabled():
|
||||||
button1_action = self.enable
|
button1_label = "Disable"
|
||||||
|
button1_action = self.disable
|
||||||
|
else:
|
||||||
|
button1_label = "Enable"
|
||||||
|
button1_action = self.enable
|
||||||
button2_label = "Uninstall"
|
button2_label = "Uninstall"
|
||||||
button2_action = self.uninstall
|
button2_action = self.uninstall
|
||||||
has_update = self.local_plugin.version != plugin.latest_version
|
has_update = self.local_plugin.version != self.plugin.latest_version
|
||||||
if has_update:
|
if has_update:
|
||||||
button3_label = "Update"
|
button3_label = "Update"
|
||||||
button3_action = self.update
|
button3_action = self.update
|
||||||
|
|
@ -411,17 +428,18 @@ class PluginWindow(popup.PopupWindow):
|
||||||
button1_label = "Install"
|
button1_label = "Install"
|
||||||
button1_action = self.install
|
button1_action = self.install
|
||||||
|
|
||||||
ba.buttonwidget(parent=self._root_widget,
|
if to_draw_button1:
|
||||||
position=(width * 0.1, pos),
|
ba.buttonwidget(parent=self._root_widget,
|
||||||
size=button_size,
|
position=(width * 0.1, pos),
|
||||||
on_activate_call=button1_action,
|
size=button_size,
|
||||||
color=b1_color,
|
on_activate_call=button1_action,
|
||||||
textcolor=b_text_color,
|
color=b1_color,
|
||||||
button_type='square',
|
textcolor=b_text_color,
|
||||||
text_scale=1,
|
button_type='square',
|
||||||
label=button1_label)
|
text_scale=1,
|
||||||
|
label=button1_label)
|
||||||
|
|
||||||
if plugin.is_installed:
|
if self.plugin.is_installed:
|
||||||
ba.buttonwidget(parent=self._root_widget,
|
ba.buttonwidget(parent=self._root_widget,
|
||||||
position=(width * 0.4, pos),
|
position=(width * 0.4, pos),
|
||||||
size=button_size,
|
size=button_size,
|
||||||
|
|
@ -456,7 +474,7 @@ class PluginWindow(popup.PopupWindow):
|
||||||
def button(fn):
|
def button(fn):
|
||||||
async def asyncio_handler(fn, self, *args, **kwargs):
|
async def asyncio_handler(fn, self, *args, **kwargs):
|
||||||
await fn(self, *args, **kwargs)
|
await fn(self, *args, **kwargs)
|
||||||
self.button_callback()
|
await self.button_callback()
|
||||||
|
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
self._ok()
|
self._ok()
|
||||||
|
|
@ -465,7 +483,8 @@ class PluginWindow(popup.PopupWindow):
|
||||||
loop.create_task(asyncio_handler(fn, self, *args, **kwargs))
|
loop.create_task(asyncio_handler(fn, self, *args, **kwargs))
|
||||||
else:
|
else:
|
||||||
fn(self, *args, **kwargs)
|
fn(self, *args, **kwargs)
|
||||||
self.button_callback()
|
asyncio.create_task(self.button_callback())
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@button
|
@button
|
||||||
|
|
@ -852,13 +871,13 @@ class PluginManagerWindow(ba.Window, PluginManager):
|
||||||
plugin.delete()
|
plugin.delete()
|
||||||
|
|
||||||
plugins = await self.categories[self.selected_category].get_plugins()
|
plugins = await self.categories[self.selected_category].get_plugins()
|
||||||
for plugin in plugins:
|
plugin_names_to_draw = tuple(self.draw_plugin_name(plugin) for plugin in plugins)
|
||||||
self.draw_plugin_name(plugin)
|
await asyncio.gather(*plugin_names_to_draw)
|
||||||
|
|
||||||
def draw_plugin_name(self, plugin):
|
async def draw_plugin_name(self, plugin):
|
||||||
if plugin.is_installed:
|
if plugin.is_installed:
|
||||||
local_plugin = plugin.get_local()
|
local_plugin = plugin.get_local()
|
||||||
if local_plugin.is_enabled:
|
if await local_plugin.is_enabled():
|
||||||
if not local_plugin.is_installed_via_plugin_manager:
|
if not local_plugin.is_installed_via_plugin_manager:
|
||||||
color = (0.8, 0.2, 0.2)
|
color = (0.8, 0.2, 0.2)
|
||||||
elif local_plugin.version == plugin.latest_version:
|
elif local_plugin.version == plugin.latest_version:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue