File size: 1,095 Bytes
2452398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from qt.components.recipes import RecipesWidget

from qt.constant import MAX_RECIPE_SKILLS, MAX_RECIPES


class Recipes:
    def __init__(self):
        self.recipes = [[] for _ in range(MAX_RECIPE_SKILLS)]

    def __getitem__(self, item):
        return self.recipes[item]

    def __setitem__(self, key, value):
        self.recipes[key] = value

    @property
    def gains(self):
        return [recipe for recipes in self.recipes for recipe in recipes]


def recipes_script(recipes_widget: RecipesWidget):
    recipes = Recipes()

    def recipe_update(i):
        widget = recipes_widget[i]

        def inner():
            skill = widget.label.text()
            if selected_items := widget.list.selectedItems():
                while len(selected_items) > MAX_RECIPES:
                    selected_items.pop().setSelected(False)
            recipes[i] = [(skill, item.text()) for item in selected_items]

        return inner

    for n, recipe_widget in enumerate(recipes_widget.values()):
        recipe_widget.list.itemSelectionChanged.connect(recipe_update(n))

    return recipes