Skip to content

Commit

Permalink
Merge pull request #175 from Yutsuten/disable-deck
Browse files Browse the repository at this point in the history
Add option to disable addon per deck
  • Loading branch information
Yutsuten authored Apr 16, 2024
2 parents 13fda2a + b0fa61f commit be889b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def update(self, new_conf: dict[str, Any]) -> None:

class DeckConf:
"""Manages Life Drain's deck configuration."""
FIELDS: ClassVar[set[str]] = {'maxLife', 'recover', 'damage', 'damageNew', 'damageLearning'}
FIELDS: ClassVar[set[str]] = {
'enable', 'maxLife', 'recover', 'damage', 'damageNew', 'damageLearning',
}

def __init__(self, mw: AnkiQt):
self._mw = mw
Expand Down
4 changes: 3 additions & 1 deletion src/deck_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def update(self, state: MainWindowState) -> None:
self._update_progress_bar_style()
self._progress_bar.set_max_value(bar_info['maxValue'])
self._progress_bar.set_current_value(bar_info['currentValue'])
self._progress_bar.set_visible(visible=True)
self._progress_bar.set_visible(visible=bar_info['enable'])

def hide_life_bar(self) -> None:
"""Set life bar visibility to False."""
Expand All @@ -79,6 +79,7 @@ def set_deck_conf(self, conf: dict[str, Any], *, update_life: bool) -> None:
self._add_deck(conf['id'])

bar_info = self._bar_info[conf['id']]
bar_info['enable'] = conf['enable']
bar_info['maxValue'] = conf['maxLife']
bar_info['recoverValue'] = conf['recover']
bar_info['damageValue'] = conf['damage']
Expand Down Expand Up @@ -227,6 +228,7 @@ def _add_deck(self, deck_id:str) -> None:
conf = self._deck_conf.get()

self._bar_info[deck_id] = {
'enable': conf['enable'],
'maxValue': conf['maxLife'],
'recoverValue': conf['recover'],
'damageValue': conf['damage'],
Expand Down
5 changes: 4 additions & 1 deletion src/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ def must_have_active_deck(func: Callable) -> Callable:
def _wrapper(self: Any, *args, **kwargs) -> Any:
if self._cur_deck_id is None:
raise NoDeckSelectedError
return func(self, self._bar_info[self._cur_deck_id], *args, **kwargs)
bar_info = self._bar_info[self._cur_deck_id]
if not bar_info['enable']:
return lambda: None
return func(self, bar_info, *args, **kwargs)
return _wrapper
4 changes: 4 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def save() -> None:

conf = config.get()
conf.update({
'enable': basic_tab.enable.isChecked(),
'maxLife': basic_tab.maxLifeInput.value(),
'recover': basic_tab.recoverInput.value(),
'damage': damage,
Expand Down Expand Up @@ -508,6 +509,8 @@ def _deck_basic_tab(aqt: Any, conf: dict[str, Any], life: float) -> Any:

def generate_form() -> Any:
tab = Form(aqt)
tab.check_box('enable', 'Enable for this deck',
'Enable/disable Life Drain for this deck.')
tab.spin_box('maxLifeInput', 'Maximum life', [1, 10000], '''Time in \
seconds for the life bar go from full to empty.''')
tab.spin_box('recoverInput', 'Recover', [0, 1000], '''Time in seconds \
Expand All @@ -518,6 +521,7 @@ def generate_form() -> Any:
return tab.widget

def load_data(widget: Any, conf: dict[str, Any]) -> None:
widget.enable.set_value(conf['enable'])
widget.maxLifeInput.set_value(conf['maxLife'])
widget.recoverInput.set_value(conf['recover'])
widget.currentValueInput.set_value(int(life))
Expand Down

0 comments on commit be889b4

Please sign in to comment.