Пример #1
0
def itemPlusFive():
    model = ui_inventory.inventoryView.model()
    selected = []
    data = tojson.loadfromsave()
    indexes = ui_inventory.inventoryView.selectionModel().selectedRows()
    for i in sorted(indexes):
        row = i.row()
        print(row)
        index = model.index(row, 0)
        # We suppose data are strings
        selected.append(model.data(index))
        strselected = "".join(selected)
        print(selected)
        for element in data["Inventory"]:
            if element == strselected:
                menge = data["Inventory"][strselected]["menge"]
                newMenge = int(menge) + 5
                data["Inventory"][strselected].update({"menge": newMenge})
                gewicht = data["Inventory"][strselected]["gewicht"]
                newGewicht = math.ceil(gewicht / menge * newMenge)
                if newMenge <= 0:
                    del data["Inventory"][strselected]
                else:
                    data["Inventory"][strselected].update({"menge": newMenge})
                    data["Inventory"][strselected].update(
                        {"gewicht": newGewicht})
                tojson.savetojson(data)
                updateListView()
                inv = Inventory()
                inv.update(ui)
                data = inv.save(data, ui)
                updateinv(inv, data)
                break
Пример #2
0
def reloadUI():
    stats = Stats()
    data = tojson.loadfromsave()
    stats.load(data)
    inv = Inventory()
    print(data)
    inv.load(data)
    inituivalues(stats)
    initinvvalues(inv, data)
Пример #3
0
def saveItem():
    x = Item()
    data = tojson.loadfromsave()
    global ui_editor
    x.create(ui_editor)
    data = x.save(data)
    tojson.savetojson(data)
    closeEditor()
    updateListView()
Пример #4
0
def save():
    data = tojson.loadfromsave()
    stats = Stats()
    inv = Inventory()
    stats.update(ui)
    data = stats.save(data, ui)
    updateui(stats)
    inv.update(ui)
    data = inv.save(data, ui)
    updateinv(inv, data)
    tojson.savetojson(data)
Пример #5
0
def updateListView():
    global ui_inventory
    data = tojson.loadfromsave()
    model = QStandardItemModel()
    if model.rowCount() is not 0:
        model.removeRows(0, model.rowCount())
        ui_inventory.inventoryView.setModel(model)
    counter = 0
    for inv in data["Inventory"]:

        if inv == "muenzen":
            pass
        elif inv == "edelsteine":
            pass
        elif inv == "feldrationen":
            pass
        elif inv == "abenteuerausruestung":
            pass
        elif inv == "heiltraenke":
            pass
        elif inv == "pfeile":
            pass
        else:
            item = None
            gegenstand = None
            l = []
            l.append("Menge: ")
            l.append(str(data["Inventory"][inv]["menge"]))
            l.append(" Gewicht: ")
            l.append(str(data["Inventory"][inv]["gewicht"]))
            l.append(" ")

            if data["Inventory"][inv]["staerke"] is not 0:
                l.append(ui.staerke.text())
                l.append(": ")
                if data["Inventory"][inv]["staerke"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["staerke"]))
                l.append(" ")
            if data["Inventory"][inv]["geschick"] is not 0:
                l.append(ui.geschick.text())
                l.append(": ")
                if data["Inventory"][inv]["geschick"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["geschick"]))
                l.append(" ")
            if data["Inventory"][inv]["konstitution"] is not 0:
                l.append(ui.konstitution.text())
                l.append(": ")
                if data["Inventory"][inv]["konstitution"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["konstitution"]))
                l.append(" ")
            if data["Inventory"][inv]["intelligenz"] is not 0:
                l.append(ui.intelligenz.text())
                l.append(": ")
                if data["Inventory"][inv]["intelligenz"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["intelligenz"]))
                l.append(" ")
            if data["Inventory"][inv]["weisheit"] is not 0:
                l.append(ui.weisheit.text())
                l.append(": ")
                if data["Inventory"][inv]["weisheit"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["weisheit"]))
                l.append(" ")
            if data["Inventory"][inv]["charisma"] is not 0:
                l.append(ui.charisma.text())
                l.append(": ")
                if data["Inventory"][inv]["charisma"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["charisma"]))
                l.append(" ")
            if data["Inventory"][inv]["ruestung"] is not 0:
                l.append(ui.ruestung.text())
                l.append(": ")
                if data["Inventory"][inv]["ruestung"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["ruestung"]))
                l.append(" ")
            if data["Inventory"][inv]["schaden"] is not 0:
                l.append(ui.schaden.text())
                l.append(": ")
                if data["Inventory"][inv]["schaden"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["schaden"]))
                l.append(" ")
            if data["Inventory"][inv]["leben"] is not 0:
                l.append(ui.lebenText.text())
                l.append(": ")
                if data["Inventory"][inv]["leben"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["leben"]))
                l.append(" ")
            if data["Inventory"][inv]["belastung"] is not 0:
                l.append(ui.belastungText.text())
                l.append(": ")
                if data["Inventory"][inv]["belastung"] > 0:
                    l.append("+")
                l.append(str(data["Inventory"][inv]["belastung"]))
                l.append(" ")
            gegenstand = "".join(l)
            name = QStandardItem(inv)
            item = QStandardItem(gegenstand)
            beschreibung = QStandardItem(
                str(data["Inventory"][inv]["beschreibung"]))
            itemList = (name, beschreibung, item)
            model.insertRow(counter, itemList)
            counter = counter + 1
            model.setHorizontalHeaderLabels(["Name", "Beschreibung", "Stats"])
    ui_inventory.inventoryView.setModel(model)
    ui_inventory.inventoryView.resizeColumnToContents(0)
    ui_inventory.inventoryView.resizeColumnToContents(1)
    ui_inventory.inventoryView.resizeColumnToContents(2)