Skip to content

Commit 1841049

Browse files
Berserker66black-sliver
authored andcommitted
Launcher: deprecate FUNC Component type (ArchipelagoMW#1872)
* Launcher: add hidden component type --------- Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
1 parent 45cf7a2 commit 1841049

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

Launcher.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ class Launcher(App):
155155
container: ContainerLayout
156156
grid: GridLayout
157157

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

163163
def __init__(self, ctx=None):
164164
self.title = self.base_title
@@ -199,7 +199,7 @@ def build_button(component: Component):
199199
button_layout.add_widget(button)
200200

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

216216
@staticmethod
217217
def component_action(button):
218-
if button.component.type == Type.FUNC:
218+
if button.component.func:
219219
button.component.func()
220220
else:
221221
launch(get_exe(button.component), button.component.cli)

Utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -785,3 +785,10 @@ def async_start(co: Coroutine[typing.Any, typing.Any, bool], name: Optional[str]
785785
task = asyncio.create_task(co, name=name)
786786
_faf_tasks.add(task)
787787
task.add_done_callback(_faf_tasks.discard)
788+
789+
790+
def deprecate(message: str):
791+
if __debug__:
792+
raise Exception(message)
793+
import warnings
794+
warnings.warn(message)

worlds/LauncherComponents.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
from enum import Enum, auto
22
from typing import Optional, Callable, List, Iterable
33

4-
from Utils import local_path, is_windows
4+
from Utils import local_path
55

66

77
class Type(Enum):
88
TOOL = auto()
9-
FUNC = auto() # not a real component
9+
MISC = auto()
1010
CLIENT = auto()
1111
ADJUSTER = auto()
12+
FUNC = auto() # do not use anymore
13+
HIDDEN = auto()
1214

1315

1416
class Component:
1517
display_name: str
16-
type: Optional[Type]
18+
type: Type
1719
script_name: Optional[str]
1820
frozen_name: Optional[str]
1921
icon: str # just the name, no suffix
@@ -22,18 +24,21 @@ class Component:
2224
file_identifier: Optional[Callable[[str], bool]]
2325

2426
def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_name: Optional[str] = None,
25-
cli: bool = False, icon: str = 'icon', component_type: Type = None, func: Optional[Callable] = None,
26-
file_identifier: Optional[Callable[[str], bool]] = None):
27+
cli: bool = False, icon: str = 'icon', component_type: Optional[Type] = None,
28+
func: Optional[Callable] = None, file_identifier: Optional[Callable[[str], bool]] = None):
2729
self.display_name = display_name
2830
self.script_name = script_name
2931
self.frozen_name = frozen_name or f'Archipelago{script_name}' if script_name else None
3032
self.icon = icon
3133
self.cli = cli
32-
self.type = component_type or \
33-
None if not display_name else \
34-
Type.FUNC if func else \
35-
Type.CLIENT if 'Client' in display_name else \
36-
Type.ADJUSTER if 'Adjuster' in display_name else Type.TOOL
34+
if component_type == Type.FUNC:
35+
from Utils import deprecate
36+
deprecate(f"Launcher Component {self.display_name} is using Type.FUNC Type, which is pending removal.")
37+
component_type = Type.MISC
38+
39+
self.type = component_type or (
40+
Type.CLIENT if "Client" in display_name else
41+
Type.ADJUSTER if "Adjuster" in display_name else Type.MISC)
3742
self.func = func
3843
self.file_identifier = file_identifier
3944

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

6166
components: List[Component] = [
6267
# Launcher
63-
Component('', 'Launcher'),
68+
Component('Launcher', 'Launcher', component_type=Type.HIDDEN),
6469
# Core
6570
Component('Host', 'MultiServer', 'ArchipelagoServer', cli=True,
6671
file_identifier=SuffixIdentifier('.archipelago', '.zip')),

0 commit comments

Comments
 (0)