Esempio n. 1
0
    public void SetGameState(NPC npc)
    {
        GameState state = npc.gameState;

        foreach (CardGrid card in state.cards)
        {
            CardGrid newInstance = Instantiate(cardGridPrefab);
            newInstance.Init(this, card.card, null, CardGrid.CardSource.SAVED);
            newInstance.x        = card.x;
            newInstance.y        = card.y;
            newInstance.rotation = card.rotation;
            newInstance.transform.localPosition = new Vector3(card.x, card.y, 0);
            newInstance.transform.Rotate(0, 0, -90 * card.rotation);
            newInstance.confirmedOnBoard = true;
            cards.Add(newInstance);
        }

        blockedSquares = new HashSet <Vector2>(npc.blockedSpots);

        if (cards.Count > 0)
        {
            UpdateAvailableSpots();
        }

        gridScale            = Camera.main.orthographicSize * 2 / GridSquaresVertical;
        transform.localScale = Vector3.one * gridScale;
        transform.position   = new Vector3(
            (1 - BoardWidth) * gridScale / 2 + 2,
            (1 - BoardHeight) * gridScale / 2 + 1,
            0);
        confirmButton.interactable = false;
        for (int x = 0; x < BoardWidth; x++)
        {
            for (int y = 0; y < BoardHeight; y++)
            {
                if (blockedSquares.Contains(new Vector2(x, y)))
                {
                    continue;
                }
                Transform gridSquare = Instantiate(gridSquarePrefab);
                gridSquare.SetParent(transform);
                gridSquare.localScale    = Vector3.one;
                gridSquare.localPosition = new Vector3(x, y, 0);
                if (cards.Count == 0)
                {
                    availableSpots.Add(new Vector2(x, y));
                }
            }
        }
    }
Esempio n. 2
0
    public void SpawnCard(Card c, CardInventory parent)
    {
        CardGrid cardGrid = Instantiate(cardGridPrefab);

        if (parent)
        {
            parent.draggedCard = cardGrid;
        }
        cardGrid.Init(this, c, parent, parent == null ? CardGrid.CardSource.OTHER : CardGrid.CardSource.PLAYER);
        if (activeCard != null)
        {
            activeCard.CancelMoveFromInventory();
        }
        activeCard = cardGrid;
        confirmButton.interactable = true;
    }