Ejemplo n.º 1
0
    public static LevelEditor.SerializableBoard LoardBoardFromFile(string _filePath)
    {
        string jsonDataOnFile = File.ReadAllText($"{Application.dataPath}{LevelEditor.LevelEditor.PrependPath}/{_filePath}");

        LevelEditor.SerializableBoard serializableBoard = JsonUtility.FromJson <LevelEditor.SerializableBoard>(jsonDataOnFile);
        return(serializableBoard);
    }
Ejemplo n.º 2
0
        public void LoadFile(InputField _inputField)
        {
            string fileName = _inputField.textComponent.text;

            if (!fileName.Contains(".json"))
            {
                fileName += ".json";
            }

            string            filePath = $"{fileName}";
            SerializableBoard board    = SerializeUtility.LoardBoardFromFile(filePath);

            DeserializeBoard(board);
            HideLoadFilePanel();
        }
Ejemplo n.º 3
0
        private void SavePuzzle(string _filename)
        {
            SerializableBoard       savedBoard = new SerializableBoard();
            List <SerializableCell> cellList   = new List <SerializableCell>();

            savedBoard.boardSize = Mathf.RoundToInt(Mathf.Sqrt(m_cellList.Count));

            foreach (CellScript cell in m_cellList)
            {
                cellList.Add(GetSerializableCellFromCellScript(cell));
            }

            savedBoard.serializableGrid = cellList.ToArray();
            SaveFile(_filename, JsonUtility.ToJson(savedBoard));
        }
Ejemplo n.º 4
0
        private void GenerateBoard(SerializableBoard _board)
        {
            InitializeDependencies();
            GridLayoutGroup gridLayoutGroup = gridObject.GetComponent <GridLayoutGroup>();

            gridLayoutGroup.constraintCount = _board.boardSize;

            for (int i = 0; i < (_board.boardSize * _board.boardSize); i++)
            {
                // Instantiating Cells
                CellScript instantiatedCell = Instantiate(singleCellPrefab, gridObject.transform).GetComponent <CellScript>();
                instantiatedCell.FetchDependencies();
                instantiatedCell.CopyFrom(_board.serializableGrid[i]);
                instantiatedCell.UpdateUI();
                m_cellList.Add(instantiatedCell);
            }
        }
Ejemplo n.º 5
0
    private void InitializeLevel()
    {
        LevelEditor.SerializableBoard boardToLoad = SerializeUtility.LoardBoardFromFile(m_levelToLoad);
        m_boardGridLayoutPanel.constraintCount = boardToLoad.boardSize;

        // Instantiating all cells
        foreach (LevelEditor.SerializableCell cell in boardToLoad.serializableGrid)
        {
            GameplayCell gameplayCell = Instantiate(gameplayCellPrefab, gridPanel.transform).GetComponent <GameplayCell>();
            gameplayCell.FetchDependencies();
            gameplayCell.Assign(cell, colorConfiguration);

            // see if it would be a hint or answer, and then do stuff...
            if (cell.cellType == (int)LevelEditor.CellScript.ECellType.Unused)
            {
                m_unusedCells.Add(gameplayCell);
            }
            else if (cell.cellStatus == (int)LevelEditor.CellScript.ECellStatus.Hidden)
            {
                gameplayCell.MarkAsQuestion(colorConfiguration.hiddenBlockColor);
                m_questionCells.Add(gameplayCell);

                // Instantiating the cell that will be shown on the answer bank and can be dragged
                GameplayCell answerCell = Instantiate(gameplayCellPrefab, solutionBank.transform).GetComponent <GameplayCell>();
                answerCell.FetchDependencies();
                answerCell.Assign(cell, colorConfiguration);

                // Adding the Drag Component and stablishing all the actions necessary
                CellDrag answerCellDragComponent = answerCell.gameObject.AddComponent <CellDrag>();
                answerCellDragComponent.OnInteractedWithCell += GiveFeedbackOnCell;
                answerCellDragComponent.OnCellWasMatched     += RemoveCellFromAnswers;

                answerCell.MarkAsAnswer();
                m_answerCells.Add(answerCell);
            }
            else if (cell.cellStatus == (int)LevelEditor.CellScript.ECellStatus.Visible)
            {
                gameplayCell.cellType = GameplayCell.ECellType.Hint;
                m_gameplayCells.Add(gameplayCell);
            }
        }

        m_feedbackUIReference.UpdateRemainingUIText(m_answerCells.Count);
    }
Ejemplo n.º 6
0
 private void DeserializeBoard(SerializableBoard _board)
 {
     DestroyAllChildren(gridObject.transform);
     GenerateBoard(_board);
 }