Skip to content
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
7 changes: 4 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ game specific things:
### v1.9
- Added a new `CoopSupport.HostOnly` value.

- Added a helper `RestartToDisable` mod class, for mods which need a restart to fully disable.

- Specifying a custom class when calling `build_mod` now type hints returning an instance of it,
instead of just `Mod`.

- `SliderOption`s now throw if initialized with a step larger than their allowed range.

- Added `_(to|from)_json()` methods to all options.

- Changed settings saving and loading to use above methods.
- Added `_(to|from)_json()` methods to all options, and changed settings saving and loading to use
them.

### v1.8
- Fixed that nested and grouped options' children would not get their `.mod` attribute set.
Expand Down
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .hook import HookType, bind_all_hooks, hook
from .html_to_plain_text import html_to_plain_text
from .keybinds import EInputEvent, KeybindType, keybind
from .mod import CoopSupport, Game, Library, Mod, ModType
from .mod import CoopSupport, Game, Library, Mod, ModType, RestartToDisable
from .mod_factory import build_mod
from .mod_list import (
deregister_mod,
Expand Down Expand Up @@ -77,6 +77,7 @@
"Mod",
"ModType",
"NestedOption",
"RestartToDisable",
"SliderOption",
"SpinnerOption",
"ValueOption",
Expand Down
27 changes: 27 additions & 0 deletions mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,30 @@ def get_status(self) -> str:
if Game.get_current() not in self.supported_games:
return "<font color='#ffff00'>Incompatible</font>"
return "<font color='#00ff00'>Loaded</font>"


@dataclass
class RestartToDisable(Mod):
"""
Helper subclass for mods which cannot be fully disabled without restarting the game.

Mods will still run the normal enable/disable logic. However, after being disabled, the status
will show that the mod requires a restart.
"""

_ever_enabled: bool = field(default=False, init=False, repr=False)

def enable(self) -> None:
"""Called to enable the mod."""
super().enable()

# In case we weren't allowed to enable
if self.is_enabled:
self._ever_enabled = True

def get_status(self) -> str:
"""Gets the current status of this mod."""
if self._ever_enabled and not self.is_enabled:
return "<font color='#ff6060'>Disabling on Restart</font>"

return super().get_status()