-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.py
More file actions
92 lines (67 loc) · 2.63 KB
/
manager.py
File metadata and controls
92 lines (67 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from aqt import gui_hooks, mw, qconnect
from aqt.qt import *
from aqt.utils import showText
from PyQt5.QtMultimedia import QSound
from aqt.reviewer import Reviewer
from anki.cards import Card
from .config import load_config_state, save_config_prop
from .loot import CardStudyLoot, StartLoot
from .utils import copy_directory, get_file_from_resource
from .ui import PlayerInformationDialog
from .player import Player
import os
class AnkiManager():
def __init__(self) -> None:
self.player = Player(
level=0,
exp=0
)
self.first_loot = False
self.playerInformationDialog = PlayerInformationDialog(
mw=mw, player=self.player)
self.player.subscribe("change", lambda x, y: self.save_state())
self.player.subscribe("destroy_item", lambda x,
y: self.play_destroy_sound())
def play_destroy_sound(self):
QSound.play(
get_file_from_resource(os.path.join("sounds", "delete_item.wav")))
def calculate_loot(self):
loots = CardStudyLoot().getLoot()
self.player.receive_loot(loots)
self.playerInformationDialog.update_player()
def on_did_answer_card(self, reviewer: Reviewer, card: Card, ease: int):
self.hit_card(ease)
self.calculate_loot()
def load_resources(self):
copy_directory("rpg_resources")
self.load_state()
if self.first_loot is False:
save_config_prop("first_loot", True)
self.player.receive_loot(StartLoot().getLoot())
def hit_card(self, ease: int):
self.player.increase_exp_by_ease(ease)
def open_stats_window(self):
self.playerInformationDialog.update_player()
self.playerInformationDialog.show()
def save_state(self):
save_config_prop("player", self.player.toJSON())
def load_state(self):
state = load_config_state()
self.player.fromJSON(state["player"])
self.first_loot = state["first_loot"]
# Only UI logic
def start_menu(self):
playerAction = QAction("Player", mw)
qconnect(playerAction.triggered, self.open_stats_window)
reloadAction = QAction("Reload config", mw)
qconnect(reloadAction.triggered, self.load_state)
mw.rpg = QMenu('&RPG', mw)
mw.rpg.addAction(playerAction)
mw.rpg.addAction(reloadAction)
mw.form.menubar.addMenu(mw.rpg)
def start_hooks(self):
gui_hooks.reviewer_did_answer_card.append(self.on_did_answer_card)
gui_hooks.profile_did_open.append(self.load_resources)
def start(self):
self.start_hooks()
self.start_menu()