From b635d5140fc99e941d2d8fdb9a696a5a52eb7253 Mon Sep 17 00:00:00 2001 From: kaneryu Date: Wed, 7 Aug 2024 14:45:11 -0500 Subject: [PATCH] Add backend for items, make disabling on buttons actually work, and other changes --- src/createthesun/gameLogic/itemGameLogic.py | 313 +++++++++++--------- src/createthesun/gamedefine.py | 157 ++++++++-- src/createthesun/itemInteractions.py | 15 +- src/createthesun/main~2x3x.qml | 2 +- src/createthesun/qml/CustomButton.qml | 11 +- src/createthesun/qml/CustomToolTip.qml | 80 +++++ src/createthesun/qml/tabs/mainTab.qml | 27 +- src/createthesun/qmlver.py | 13 +- 8 files changed, 438 insertions(+), 180 deletions(-) create mode 100644 src/createthesun/qml/CustomToolTip.qml diff --git a/src/createthesun/gameLogic/itemGameLogic.py b/src/createthesun/gameLogic/itemGameLogic.py index a4087cb..7cee55e 100644 --- a/src/createthesun/gameLogic/itemGameLogic.py +++ b/src/createthesun/gameLogic/itemGameLogic.py @@ -7,158 +7,193 @@ from .. import gamedefine -def canAfford(item: str, doBuyMultiply=True) -> bool: - """ - Checks if you can afford an item. +from PySide6.QtCore import QObject +from PySide6.QtCore import Signal , Slot + +# first argment is the item, second is misc +_instance = None +class ItemGameLogic(QObject): + + + + @staticmethod + def getInstance(): + global _instance + if _instance is None: + _instance = ItemGameLogic() + return _instance + + def __new__(cls, *args, **kwargs): + global _instance + if not _instance: + _instance = super(ItemGameLogic, cls).__new__(cls, *args, **kwargs) + return _instance + + def __init__(self): + super().__init__() + + @Slot(str, result=bool) + def canAfford(self, item: str, doBuyMultiply=True) -> bool: + """ + Checks if you can afford an item. + + Args: + item (str): The item to check. + + Returns: + bool: Whether you can afford the item or not. + """ + + buyMultiplier = gamedefine.game.mainTabBuyMultiple if doBuyMultiply else 1 + + if gamedefine.items[item].costEquation == "": + return True + + costs = gamedefine.items[item].cost + ongoing = True + + for i in costs: + if i["what"].amount < i["amount"] * buyMultiplier: + ongoing = False + + + return ongoing + + @Slot(str, result=None) + def _purchase(self, item: str, doBuyMultiply=False) -> None: + """ + Purchases an item. + + Args: + item (str): The item to purchase. + """ + + buyMultiplier = gamedefine.game.mainTabBuyMultiple if doBuyMultiply else 1 + + if gamedefine.items[item].costEquation == "": + + gamedefine.items[item].amount += 1 + print(f"purchased {item}, now have {gamedefine.items[item].amount}") + return + + + costs = gamedefine.items[item].cost + gives = gamedefine.items[item].gives + + + for i in costs: + i["what"].amount -= i["amount"] * buyMultiplier + for i in gives: + i["what"].amount += i["amount"] * buyMultiplier + print(f"purchased {item}, now have {gamedefine.items[item].amount}, with buy multiplier {buyMultiplier}") - Args: - item (str): The item to check. - - Returns: - bool: Whether you can afford the item or not. - """ - - buyMultiplier = gamedefine.gamedefine.mainTabBuyMultiple if doBuyMultiply else 1 - - if gamedefine.gamedefine.itemInternalDefine[item]["costEquation"] == "": - return True - - whatItCosts = gamedefine.gamedefine.itemInternalDefine[item]["whatItCosts"] - - ongoing = True - - for i in whatItCosts: - if gamedefine.gamedefine.amounts[i["what"]] < i["amount"] * buyMultiplier: - ongoing = False - - return ongoing - - -def purchase(item: str, doBuyMultiply=False) -> None: - """ - Purchases an item. - - Args: - item (str): The item to purchase. - """ - - buyMultiplier = gamedefine.gamedefine.mainTabBuyMultiple if doBuyMultiply else 1 - - if gamedefine.gamedefine.itemInternalDefine[item]["costEquation"] == "": - gamedefine.gamedefine.amounts[item] += 1 - print(f"purchased {item}, now have {gamedefine.gamedefine.amounts[item]}") return - whatItCosts = gamedefine.gamedefine.itemInternalDefine[item]["whatItCosts"] - whatItGives = gamedefine.gamedefine.itemInternalDefine[item]["whatItGives"] - - for i in whatItCosts: - gamedefine.gamedefine.amounts[i["what"]] -= i["amount"] * buyMultiplier - for i in whatItGives: - gamedefine.gamedefine.amounts[i["what"]] += i["amount"] * buyMultiplier - print(f"purchased {item}, now have {gamedefine.gamedefine.amounts[item]}, with buy multiplier {buyMultiplier}") - - return - - -def getCurrentCost(item: str, _round: bool | None = False, eNotation: bool | None = True) -> dict: - """ - Returns the current cost of an item. + @Slot(str, result=None) + def purchase(self, item: str) -> None: + if self.canAfford(item): + self._purchase(item) - Args: - item (str): The item to get the cost of. - _round (bool | None): Whether to round the cost or not. Defaults to False. + @Slot(str, result=None) + def getCurrentCost(self, item: str, _round: bool | None = False, eNotation: bool | None = True) -> float: + """ + Returns the current cost of an item. - Returns: - dict: The current cost of the item. - """ + Args: + item (str): The item to get the cost of. + _round (bool | None): Whether to round the cost or not. Defaults to False. - buyMultiplier = gamedefine.gamedefine.mainTabBuyMultiple + Returns: + dict: The current cost of the item. + """ - equation = gamedefine.gamedefine.itemInternalDefine[item]["costEquation"] - if equation == "": - return {"failed": True} + buyMultiplier = gamedefine.game.mainTabBuyMultiple - whatItCosts = gamedefine.gamedefine.itemInternalDefine[item]["whatItCosts"][0] + equation = gamedefine.gamedefine.itemInternalDefine[item]["costEquation"] + if equation == "": + return {"failed": True} - currentCost = int(numberLogic.evaluateCostEquation(equation, 1)) + whatItCosts = gamedefine.gamedefine.itemInternalDefine[item]["whatItCosts"][0] - if _round: - return {whatItCosts: round(currentCost) * buyMultiplier} - else: - return {whatItCosts: currentCost * buyMultiplier} + currentCost = int(numberLogic.evaluateCostEquation(equation, 1)) + # if _round: + # return {whatItCosts: round(currentCost) * buyMultiplier} + # else: + # return {whatItCosts: currentCost * buyMultiplier} -def parseCost(name): - buyMultiplier = gamedefine.gamedefine.mainTabBuyMultiple - - if not name == "quarks": - what = gamedefine.gamedefine.itemInternalDefine[name]["whatItCosts"] - get = gamedefine.gamedefine.itemInternalDefine[name]["whatItGives"] - string = ["Purchase "] - else: - return "Free" - exempt = ["hydrogen"] - for i in get: - string.append(str(i["amount"] * buyMultiplier) + " ") - - if i["amount"] * buyMultiplier == 1 and not i["what"] in exempt: - string.append(i["what"][:-1]) - else: - string.append(i["what"]) - - if get.index(i) < len(get) - 2: - string.append(", ") - elif get.index(i) == len(get) - 2: - string.append(" and ") + if _round: + return round(currentCost * buyMultiplier) else: - string.append(" for ") + return currentCost * buyMultiplier - for i in what: - string.append(str(i["amount"] * buyMultiplier) + " ") + @Slot(str, result=str) + def parseCost(self, item: str) -> str: + buyMultiplier = gamedefine.game.mainTabBuyMultiple - if i["amount"] * buyMultiplier == 1 and not i["what"] in exempt: - string.append(i["what"][:-1]) + if not gamedefine.items[item].defaultCost == -1: + cost = gamedefine.items[item].cost + gives = gamedefine.items[item].gives + string = ["Purchase "] else: - string.append(i["what"]) - - if what.index(i) < len(what) - 2: - string.append(", ") - elif what.index(i) == len(what) - 2: - string.append(" and ") - else: - string.append(".") - - return "".join(string) - - -def maxAll(): - def maxAllPurchase(item): - whatItCosts = gamedefine.gamedefine.itemInternalDefine[item]["whatItCosts"] - whatItGives = gamedefine.gamedefine.itemInternalDefine[item]["whatItGives"] - - maxAmountPossible = 1 - - for i in whatItCosts: - maxAmountPossible = gamedefine.gamedefine.amounts[i["what"]] // i["amount"] - - for i in whatItCosts: - gamedefine.gamedefine.amounts[i["what"]] -= int(i["amount"] * maxAmountPossible) - for i in whatItGives: - gamedefine.gamedefine.amounts[i["what"]] += int(i["amount"] * maxAmountPossible) - - print(f"max all purchased {maxAmountPossible} of {item}, now have {gamedefine.gamedefine.amounts[item]}") - - return - - affordList = [] - for i in gamedefine.gamedefine.itemInternalDefine: - if not gamedefine.gamedefine.itemInternalDefine[i]["whatItCosts"][0]["what"] == "nothing": - if i in gamedefine.gamedefine.purchaseToCreate: - if canAfford(i, doBuyMultiply=False): - affordList.append(i) - - for i in affordList: - maxAllPurchase( - i - ) # this fixes the 'cascade effect' of the max all button by not actually purchasing it until the end + return "Free" + exempt = ["Hydrogen"] + for i in gives: + string.append(str(numberLogic.humanReadableNumber(i["amount"] * buyMultiplier)) + " ") + + string.append(i["what"].getName_(i["amount"] * buyMultiplier).lower()) + numberLogic.humanReadableNumber + if gives.index(i) < len(gives) - 2: + string.append(", ") + elif gives.index(i) == len(gives) - 2: + string.append(" and ") + else: + string.append(" for ") + + for i in cost: + string.append(str(numberLogic.humanReadableNumber(i["amount"] * buyMultiplier)) + " ") + + string.append(i["what"].getName_(i["amount"] * buyMultiplier).lower()) + + if cost.index(i) < len(cost) - 2: + string.append(", ") + elif cost.index(i) == len(cost) - 2: + string.append(" and ") + else: + string.append(".") + + return "".join(string) + + @Slot(result=None) + def maxAll(self): + def maxAllPurchase(item): + costs = gamedefine.items[item].cost + gives = gamedefine.items[item].gives + + maxAmountPossible = 1 + + for i in costs: + maxAmountPossible = gamedefine.items[i].amount // i["amount"] + + for i in costs: + gamedefine.items[i].amount -= int(i["amount"] * maxAmountPossible) + for i in gives: + gamedefine.items[i].amount += int(i["amount"] * maxAmountPossible) + + print(f"max all purchased {maxAmountPossible} of {item}, now have {gamedefine.items[item].amount}") + + return + + affordList = [] + for i in gamedefine.items: + if not gamedefine.items[i].cost[0]["what"] == "nothing": + if i in gamedefine.game.purchaseToCreate: + if self.canAfford(i, doBuyMultiply=False): + affordList.append(i) + + for i in affordList: + maxAllPurchase( + i + ) # this fixes the 'cascade effect' of the max all button by not actually purchasing it until the end + +gamedefine.itemGameLogic = ItemGameLogic \ No newline at end of file diff --git a/src/createthesun/gamedefine.py b/src/createthesun/gamedefine.py index 7f04b36..0d9c8c7 100644 --- a/src/createthesun/gamedefine.py +++ b/src/createthesun/gamedefine.py @@ -13,11 +13,13 @@ import versions from dacite import from_dict from PySide6.QtWidgets import QTabWidget -from PySide6.QtCore import QObject, Signal, Slot, Property as QProperty +from PySide6.QtCore import QObject, Signal, Slot, Property as QProperty, QTimer + from . import quickload -items: dict[str, object] = {} +ItemGameLogic = None +items: dict[str, _Item] = {} # Base Classes class _Item(QObject): @@ -29,6 +31,8 @@ class _Item(QObject): nameChanged = Signal(str) descriptionChanged = Signal(str) amountChanged = Signal(int) + affordablilityChanged = Signal(bool) + costChanged = Signal(list) def __init__(self): super().__init__() @@ -39,13 +43,31 @@ def __init__(self): self._description: str = "" self._amount: int = 0 - + + self._affordable: bool = True + self.internalName: str = "" self.singlarName: str = "" - self.cost: list[dict[str, int]] = [] + self._cost: list[dict[_Item, int]] = [] + self.defaultCost: int = 0 self.costEquation: str = "" - self.gives: list[dict[object, int]] = [] + self.gives: list[dict[_Item, int]] = [] self.switches: list[object] = [] + + self.nameChanged.connect(self.affordablilityCheck) + self.amountChanged.connect(self.affordablilityCheck) + + self.costChanged.connect(self.recheckcosts) + + + def recheckcosts(self): + for i in self.cost: + i["what"].amountChanged.connect(self.affordablilityCheck) + + + + def periodicalChecks(self): + self.affordablilityCheck() def getSwitch(self, switch: int) -> object: """This function will return the correct switch item based on the switch number. @@ -57,6 +79,14 @@ def getSwitch(self, switch: int) -> object: Item_Switch: The correct switch item. """ return self.switches[switch] + @QProperty(str, notify=costChanged) + def cost(self) -> list[dict[_Item, int]]: + return self._cost + + @cost.setter + def cost(self, value: list[dict[_Item, int]]): + self._cost = value + self.costChanged.emit(value) @QProperty(str, notify=nameChanged) def name(self) -> str: @@ -66,7 +96,7 @@ def name(self) -> str: def name(self, value: str): self._name = value self.nameChanged.emit(value) - + @QProperty(str, notify=descriptionChanged) def description(self) -> str: @@ -76,6 +106,7 @@ def description(self) -> str: def description(self, value: str): self._description = value self.descriptionChanged.emit(value) + @QProperty(int, notify=amountChanged) def amount(self) -> int: @@ -86,15 +117,34 @@ def amount(self, value: int): self._amount = value self.amountChanged.emit(value) + @QProperty(bool, notify=affordablilityChanged) + def affordable(self) -> bool: + return self._affordable + + @affordable.setter + def affordable(self, value: bool): + self._affordable = value + self.affordablilityChanged.emit(value) + @Slot(result=str) def getName(self) -> str: if not self.amount == 1: return self.name else: return self.singlarName + + def getName_(self, number) -> str: + if not number == 1: + return self.name + else: + return self.singlarName - - + @Slot() + def affordablilityCheck(self): + if ItemGameLogic is not None: + self.affordable = ItemGameLogic.getInstance().canAfford(self.name) + else: + print("affordablilityCheck: ItemGameLogic is not defined") class _LevelAutomation: """This is the base class for all automations, will not be accessed directly, even when instantiated. @@ -178,7 +228,9 @@ def __init__(self): self.cost = [{"what": None, "amount": -1}] self.defaultCost = -1 self.costEquation = "" - self.gives = [{"what": "quarks", "amount": 1}] + self.gives = [{"what": items["Quarks"], "amount": 1}] + + Quarks() class Electrons(_Item): @@ -192,7 +244,7 @@ def __init__(self): self.cost = [{"what": None, "amount": -1}] self.defaultCost = -1 self.costEquation = "" - self.gives = [{"what": "Electrons", "amount": 1}] + self.gives = [{"what": items["Electrons"], "amount": 1}] Electrons() class Protons(_Item): @@ -203,9 +255,9 @@ def __init__(self): self.description = "Protons are the building blocks of atoms. They are made of quarks." self.internalName = "protons" self.amount = 3 - self.cost = [{"what": Quarks, "amount": 3}] + self.cost = [{"what": items["Quarks"], "amount": 3}] self.costEquation = "%1 * 3" - self.gives = [{"what": "Protons", "amount": 1}] + self.gives = [{"what": items["Protons"], "amount": 1}] Protons() class Hydrogen(_Item): @@ -216,9 +268,9 @@ def __init__(self): self.description = "Hydrogen is the simplest element. It is made of one proton and one electron." self.internalName = "hydrogen" - self.cost = [{"what": Quarks, "amount": 3}] + self.cost = [{"what": items["Quarks"], "amount": 1}, {"what": items["Protons"], "amount": 1}, {"what": items["Electrons"], "amount": 1}] self.costEquation = "%1 * 3" - self.gives = [{"what": "Hydrogen", "amount": 1}] + self.gives = [{"what": items["Hydrogen"], "amount": 1}] Hydrogen() class Stars(_Item): @@ -229,9 +281,9 @@ def __init__(self): self.description = "Stars are the building blocks of galaxies. They are made of hydrogen." self.internalName = "stars" - self.cost = [{"what": Hydrogen, "amount": 1e57}] + self.cost = [{"what": items["Hydrogen"], "amount": 1e57}] self.costEquation = "%1 * 1e57" - self.gives = [{"what": "Stars", "amount": 2}] + self.gives = [{"what": items["Stars"], "amount": 2}] Stars() class Galaxies(_Item): @@ -242,9 +294,9 @@ def __init__(self): self.description = "Galaxies are the building blocks of superclusters. They are made of stars." self.internalName = "galaxies" - self.cost = [{"what": Stars, "amount": 1e11}] + self.cost = [{"what": items["Stars"], "amount": 1e11}] self.costEquation = "%1 * 1e11" - self.gives = [{"what": "galaxies", "amount": 1}] + self.gives = [{"what": items["Galaxies"], "amount": 1}] Galaxies() class Superclusters(_Item): @@ -255,11 +307,75 @@ def __init__(self): self.description = "Superclusters are the building blocks of the universe. They are made of galaxies." self.internalName = "superclusters" - self.cost = [{"what": Galaxies, "amount": 100000}] + self.cost = [{"what": items["Galaxies"], "amount": 100000}] self.costEquation = "%1 * 100000" - self.gives = [{"what": "superclusters", "amount": 1}] + self.gives = [{"what": items["Superclusters"], "amount": 1}] Superclusters() +class Game(QObject): + + purchaseToCreateChanged = Signal(list[str]) + automationsToCreateChanged = Signal(list[str]) + mainTabBuyMultipleChanged = Signal(int) + playTimeChanged = Signal(int) + tutorialPopupDoneChanged = Signal(bool) + + def __init__(self) -> None: + super().__init__() + + self._purchaseToCreate = ["quarks", "protons"] + self._automationsToCreate = ["particleAccelerator", "protonicForge"] + + self._mainTabBuyMultiple = 1 + + self._playTime = 0 + self._tutorialPopupDone = False + + @QProperty(list, notify=purchaseToCreateChanged) + def purchaseToCreate(self) -> list[str]: + return self._purchaseToCreate + + @purchaseToCreate.setter + def purchaseToCreate(self, value: list[str]): + self._purchaseToCreate = value + self.purchasesToCreateChanged.emit(value) + + @QProperty(list, notify=automationsToCreateChanged) + def automationsToCreate(self) -> list[str]: + return self._automationsToCreate + + @automationsToCreate.setter + def automationsToCreate(self, value: list[str]): + self._automationsToCreate = value + self.automationsToCreateChanged.emit(value) + + @QProperty(int, notify=mainTabBuyMultipleChanged) + def mainTabBuyMultiple(self) -> int: + return self._mainTabBuyMultiple + + @mainTabBuyMultiple.setter + def mainTabBuyMultiple(self, value: int): + self._mainTabBuyMultiple = value + self.mainTabBuyMultipleChanged.emit(value) + + @QProperty(int, notify=playTimeChanged) + def playTime(self) -> int: + return self._playTime + + @playTime.setter + def playTime(self, value: int): + self._playTime = value + self.playTimeChanged.emit(value) + + @QProperty(bool, notify=tutorialPopupDoneChanged) + def tutorialPopupDone(self) -> bool: + return self._tutorialPopupDone + + @tutorialPopupDone.setter + def tutorialPopupDone(self, value: bool): + self._tutorialPopupDone = value + self.tutorialPopupDoneChanged.emit(value) +game = Game() defualtGameDefine = { "itemVisualDefine": { "quarks": { @@ -912,3 +1028,4 @@ def getSaveMetadata(savedata: GameDefine | None = None) -> dict: # print(loadSave(json.loads(b64Decode(f.read())))) # f.close() + diff --git a/src/createthesun/itemInteractions.py b/src/createthesun/itemInteractions.py index 4cdf5b9..32181a9 100644 --- a/src/createthesun/itemInteractions.py +++ b/src/createthesun/itemInteractions.py @@ -5,7 +5,7 @@ import random import sys import threading -import time +import typing import requests from PySide6.QtCore import Property as Property @@ -17,9 +17,16 @@ # local imports -from .gameLogic import numberLogic - +from .gameLogic import itemGameLogic +from . import gamedefine class ItemInteractions(QObject): - pass \ No newline at end of file + def __init__(self): + super().__init__() + self.possibleItems = gamedefine.items.keys() + + for i in itemGameLogic.functions: + self.__setattr__(i.__name__, i) + + \ No newline at end of file diff --git a/src/createthesun/main~2x3x.qml b/src/createthesun/main~2x3x.qml index 38f9460..0e52b29 100644 --- a/src/createthesun/main~2x3x.qml +++ b/src/createthesun/main~2x3x.qml @@ -10,7 +10,7 @@ import "./qml/" as Kyu ApplicationWindow { id: root visible: true - minimumWidth: 640 + minimumWidth: 840 minimumHeight: 480 title: "Create The Sun" diff --git a/src/createthesun/qml/CustomButton.qml b/src/createthesun/qml/CustomButton.qml index 0e60a94..500a0d3 100644 --- a/src/createthesun/qml/CustomButton.qml +++ b/src/createthesun/qml/CustomButton.qml @@ -53,6 +53,13 @@ Item { txt.color = (disabledTextColor !== undefined && disabledTextColor !== null) ? disabledTextColor : textColor fill.radius = (disabledRadius !== undefined && disabledRadius !== null) ? disabledRadius : radius txt.text = (disabledText !== undefined && disabledText !== null) ? disabledText : text + } else { + fill.color = fillColor + fill.border.color = borderColor + fill.border.width = borderWidth + txt.color = textColor + fill.radius = radius + txt.text = text } } @@ -96,7 +103,9 @@ Item { id: txt text: root.text color: textColor - anchors.centerIn: parent + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter font.pixelSize: 24 } } diff --git a/src/createthesun/qml/CustomToolTip.qml b/src/createthesun/qml/CustomToolTip.qml new file mode 100644 index 0000000..9a7b89d --- /dev/null +++ b/src/createthesun/qml/CustomToolTip.qml @@ -0,0 +1,80 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import Qt.labs.platform + + +Item { + id: root + + property bool visible_: false + property string text: "" + + property alias color: background.color + property alias radius: background.radius + property alias border: background.border + + property alias textColor: tooltipText.color + property alias textSize: tooltipText.font.pixelSize + + opacity: 0.0 + + property real fadeInDuration: 500 + property real fadeOutDuration: 500 + + states: [ + State { + name: "visible" + when: root.visible_ + PropertyChanges { + target: root + opacity: 1.0 + } + }, + State { + name: "hidden" + when: !root.visible_ + PropertyChanges { + target: root + opacity: 0.0 + } + } + ] + + transitions: [ + Transition { + from: "hidden" + to: "visible" + NumberAnimation { + target: root + property: "opacity" + duration: fadeInDuration + } + }, + Transition { + from: "visible" + to: "hidden" + NumberAnimation { + target: root + property: "opacity" + duration: fadeOutDuration + } + } + ] + + Rectangle { + id: background + color: "black" + radius: 5 + border.color: "white" + border.width: 1 + anchors.fill: parent + } + + Text { + id: tooltipText + text: root.text + color: "white" + anchors.centerIn: parent + } +} \ No newline at end of file diff --git a/src/createthesun/qml/tabs/mainTab.qml b/src/createthesun/qml/tabs/mainTab.qml index aa924b0..ef580d2 100644 --- a/src/createthesun/qml/tabs/mainTab.qml +++ b/src/createthesun/qml/tabs/mainTab.qml @@ -30,12 +30,19 @@ Item { color: Theme.surface + ToolTip { + id: tooltip + text: model.item.description + delay: 200 + timeout: 2000 + } + Text { id: amtText text: "You have " + model.item.amount + " " + model.item.getName() width: root.largestTextWidth + 10 color: Theme.onSurface - font.pixelSize: 36 / 2 + font.pixelSize: 18 verticalAlignment: Text.AlignVCenter anchors.left: parent.left @@ -65,15 +72,11 @@ Item { height: parent.height - text: "Purchase 0 " + model.item.getName() + " for " + model.item.cost + " ..." // in the future you will call a function to get the cost text - disabledText: "(Can't Afford)" - textPixelSize: 36 / 2 - - Component.onCompleted: { - if (model.item.name != "Quarks") { - buyButton.enabled = false - } - } + text: ItemGameLogic.parseCost(model.item.name) + disabledText: ItemGameLogic.parseCost(model.item.name) + textPixelSize: 18 + + enabled: model.item.affordable TextMetrics { id: bbmetrics @@ -81,7 +84,7 @@ Item { font: buyButton.txt.font } - width: bbmetrics.width + 50 + width: (bbmetrics.advanceWidth * 1.2) + 15 anchors.leftMargin: 15 anchors.left: amtText.right @@ -91,7 +94,7 @@ Item { clickedRadius: 0 onClicked: { - Backend.buyItem(model.item.name) + ItemGameLogic.purchase(model.item.name) } fillColor: Theme.primaryContainer diff --git a/src/createthesun/qmlver.py b/src/createthesun/qmlver.py index 9a613c0..791419e 100644 --- a/src/createthesun/qmlver.py +++ b/src/createthesun/qmlver.py @@ -25,7 +25,9 @@ from PySide6.QtWidgets import QApplication # local imports -from . import materialInterface, urbanistFont, gamedefine, iLoveModelsTotally, itemInteractions +from .gameLogic import itemGameLogic +from . import materialInterface, urbanistFont, gamedefine, iLoveModelsTotally + @@ -110,6 +112,7 @@ def createItemModel(): def main(): + gamedefine.ItemGameLogic = itemGameLogic.ItemGameLogic app = QApplication() fonts = urbanistFont.createFonts() @@ -124,8 +127,9 @@ def main(): theme = materialInterface.Theme() theme.get_dynamicColors(0x18130B, True, 0.0) + items = Items() - + ItemGameLogic = itemGameLogic.ItemGameLogic.getInstance() if not qml: print('Could not find QML file') @@ -136,6 +140,7 @@ def main(): engine.rootContext().setContextProperty("Theme", theme) engine.rootContext().setContextProperty("Backend", backend) engine.rootContext().setContextProperty("Items", items) + engine.rootContext().setContextProperty("ItemGameLogic", ItemGameLogic) tabsModel = createTabModel() @@ -144,14 +149,16 @@ def main(): ItemsModel = createItemModel() engine.rootContext().setContextProperty("ItemsModel", ItemsModel) + # tim = QTimer() # tim.setInterval(1000) # tim.timeout.connect(lambda: theme.get_dynamicColors(generateRandomHexColor(), True, 0.0)) # tim.start() + for i in gamedefine.items: + gamedefine.items[i].affordablilityCheck() print(QDir.currentPath()) - time.sleep(0.3) # Main Theme Source Color: #DCAB5C backend.loadComplete.emit() engine.rootObjects()[0].show()