Skip to content

Commit 5c0cbb3

Browse files
committed
Add dedicated de/activate_plugin_all methods
Add dedicated methods to bethesda.py for: - activate_plugin_all - deactivate_plugin_all This allows us to handle the Union[int, str] for the index argument in a way that allows static type checkers like `ty` to prove that we aren't passing a string arg to functions that expect an int. This is the same treatment as the last patch, but for bethesda.py. Still need to do bethesda.py mod functions.
1 parent 5c1b51a commit 5c0cbb3

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

ammo/controller/bethesda.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -644,24 +644,24 @@ def set_plugin_state(self, index: int, desired_state: bool):
644644
if not self.changes:
645645
self.changes = starting_state != target_plugin.enabled
646646

647+
def activate_plugin_all(self) -> None:
648+
for i, plugin in enumerate(self.plugins):
649+
if plugin.visible:
650+
self.set_plugin_state(i, True)
651+
self.stage()
652+
647653
def activate_plugin(self, index: Union[int, str]) -> None:
648654
"""
649655
Enabled plugins will be loaded by the game.
650656
"""
651-
try:
652-
int(index)
653-
except ValueError as e:
654-
if index != "all":
655-
raise Warning(e)
656-
657657
if index == "all":
658-
for i in range(len(self.plugins)):
659-
if self.plugins[i].visible:
660-
self.set_plugin_state(i, True)
661-
else:
662-
self.set_plugin_state(int(index), True)
658+
return self.activate_plugin_all()
663659

664-
self.stage()
660+
try:
661+
self.set_plugin_state(int(index), True)
662+
self.stage()
663+
except ValueError as e:
664+
raise Warning(e)
665665

666666
def do_activate(self, component: ComponentMove, index: Union[int, str]) -> None:
667667
"""
@@ -677,24 +677,24 @@ def do_activate(self, component: ComponentMove, index: Union[int, str]) -> None:
677677
f"Expected one of {list(ComponentMove)} but got '{component}'"
678678
)
679679

680+
def deactivate_plugin_all(self) -> None:
681+
for i, plugin in enumerate(self.plugins):
682+
if plugin.visible:
683+
self.set_plugin_state(i, False)
684+
self.stage()
685+
680686
def deactivate_plugin(self, index: Union[int, str]) -> None:
681687
"""
682688
Disabled plugins will not be loaded by the game.
683689
"""
684-
try:
685-
int(index)
686-
except ValueError as e:
687-
if index != "all":
688-
raise Warning(e)
689-
690690
if index == "all":
691-
for i in range(len(self.plugins)):
692-
if self.plugins[i].visible:
693-
self.set_plugin_state(i, False)
694-
else:
695-
self.set_plugin_state(int(index), False)
691+
return self.deactivate_plugin_all()
696692

697-
self.stage()
693+
try:
694+
self.set_plugin_state(int(index), False)
695+
self.stage()
696+
except ValueError as e:
697+
raise Warning(e)
698698

699699
def do_deactivate(self, component: ComponentMove, index: Union[int, str]) -> None:
700700
"""

0 commit comments

Comments
 (0)