Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launcher: deprecate FUNC Component type #1872

Merged
merged 6 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class Launcher(App):
container: ContainerLayout
grid: GridLayout

_tools = {c.display_name: c for c in components if c.type == Type.TOOL and isfile(get_exe(c)[-1])}
_clients = {c.display_name: c for c in components if c.type == Type.CLIENT and isfile(get_exe(c)[-1])}
_adjusters = {c.display_name: c for c in components if c.type == Type.ADJUSTER and isfile(get_exe(c)[-1])}
_funcs = {c.display_name: c for c in components if c.type == Type.FUNC}
_tools = {c.display_name: c for c in components if c.type == Type.TOOL}
_clients = {c.display_name: c for c in components if c.type == Type.CLIENT}
_adjusters = {c.display_name: c for c in components if c.type == Type.ADJUSTER}
_miscs = {c.display_name: c for c in components if c.type == Type.MISC}

def __init__(self, ctx=None):
self.title = self.base_title
Expand Down Expand Up @@ -199,7 +199,7 @@ def build_button(component: Component):
button_layout.add_widget(button)

for (tool, client) in itertools.zip_longest(itertools.chain(
self._tools.items(), self._funcs.items(), self._adjusters.items()), self._clients.items()):
self._tools.items(), self._miscs.items(), self._adjusters.items()), self._clients.items()):
# column 1
if tool:
build_button(tool[1])
Expand All @@ -215,7 +215,7 @@ def build_button(component: Component):

@staticmethod
def component_action(button):
if button.component.type == Type.FUNC:
if button.component.func:
button.component.func()
else:
launch(get_exe(button.component), button.component.cli)
Expand Down
7 changes: 7 additions & 0 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,10 @@ def async_start(co: Coroutine[typing.Any, typing.Any, bool], name: Optional[str]
task = asyncio.create_task(co, name=name)
_faf_tasks.add(task)
task.add_done_callback(_faf_tasks.discard)


def deprecate(message: str):
if __debug__:
raise Exception(message)
import warnings
warnings.warn(message)
27 changes: 16 additions & 11 deletions worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from enum import Enum, auto
from typing import Optional, Callable, List, Iterable

from Utils import local_path, is_windows
from Utils import local_path


class Type(Enum):
TOOL = auto()
FUNC = auto() # not a real component
MISC = auto()
CLIENT = auto()
ADJUSTER = auto()
FUNC = auto() # do not use anymore
HIDDEN = auto()


class Component:
display_name: str
type: Optional[Type]
type: Type
script_name: Optional[str]
frozen_name: Optional[str]
icon: str # just the name, no suffix
Expand All @@ -22,18 +24,21 @@ class Component:
file_identifier: Optional[Callable[[str], bool]]

def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_name: Optional[str] = None,
cli: bool = False, icon: str = 'icon', component_type: Type = None, func: Optional[Callable] = None,
file_identifier: Optional[Callable[[str], bool]] = None):
cli: bool = False, icon: str = 'icon', component_type: Optional[Type] = None,
func: Optional[Callable] = None, file_identifier: Optional[Callable[[str], bool]] = None):
self.display_name = display_name
self.script_name = script_name
self.frozen_name = frozen_name or f'Archipelago{script_name}' if script_name else None
self.icon = icon
self.cli = cli
self.type = component_type or \
None if not display_name else \
Type.FUNC if func else \
Type.CLIENT if 'Client' in display_name else \
Type.ADJUSTER if 'Adjuster' in display_name else Type.TOOL
if component_type == Type.FUNC:
from Utils import deprecate
deprecate(f"Launcher Component {self.display_name} is using Type.FUNC Type, which is pending removal.")
component_type = Type.MISC

self.type = component_type or (
Type.CLIENT if "Client" in display_name else
Type.ADJUSTER if "Adjuster" in display_name else Type.MISC)
self.func = func
self.file_identifier = file_identifier

Expand All @@ -60,7 +65,7 @@ def __call__(self, path: str):

components: List[Component] = [
# Launcher
Component('', 'Launcher'),
Component('Launcher', 'Launcher', component_type=Type.HIDDEN),
# Core
Component('Host', 'MultiServer', 'ArchipelagoServer', cli=True,
file_identifier=SuffixIdentifier('.archipelago', '.zip')),
Expand Down