Beispiel #1
0
    def pickUpItem(self, app, newItem: Stack):
        """Adds an item to the player's inventory."""

        if newItem.isEmpty(): return

        # Prioritize existing stacks of the item first
        for (i, slot) in enumerate(self.inventory):
            stack = slot.stack
            if stack.isInfinite() and stack.item == newItem.item:
                # It just stacks into an infinite slot, so no change
                return
            elif newItem.isInfinite() and stack.item == newItem.item:
                # ditto
                return
            elif stack.amount > 0 and stack.item == newItem.item:
                self.inventory[i].stack.amount += newItem.amount
                return

        # If that fails, then just add the item to the next open space
        for (i, slot) in enumerate(self.inventory):
            if slot.isEmpty():
                self.inventory[i].stack = newItem
                return

        # TODO: Full inventory??
        1 / 0
Beispiel #2
0
def drawStack(client: ClientState, canvas, x, y, stack: Stack):
    #slotWidth = CLIENT_DATA.itemTextures['air'].width + 6

    slotWidth = getSlotCenterAndSize(client, 0)[2]

    if not stack.isEmpty():
        tex = CLIENT_DATA.itemTextures[stack.item]
        image = tex
        canvas.create_image(x, y, image=image)

        # Slots that are infinite or with a single item just don't have a number displayed
        if not stack.isInfinite() and stack.amount != 1:
            cornerX = x + 0.3 * slotWidth
            cornerY = y + 0.2 * slotWidth

            qty = stack.amount

            drawTextOutlined(canvas, cornerX, cornerY, text=str(qty), font='Arial 12 bold')