Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public LevelSummary GetExportData()
        {
            var ballData = gameObject.GetChildren()
                           .Where(c => c.GetComponent <EditableBall>() != null)
                           .Select(c => c.GetComponent <EditableBall>().Export())
                           .ToList();

            var levelSummary = new LevelSummary(LevelNumber, LevelName)
            {
                BallData = ballData
            };

            return(levelSummary);
        }
Exemplo n.º 2
0
        public void SetLevelData(LevelSummary levelSummary)
        {
            Debug.Log("Clearing children...");
            ClearAllChildren();

            var simpleObjectPool = GetComponent <SimpleObjectPool>();

            LevelNumber = levelSummary.OrdinalNumber;
            LevelName   = levelSummary.LevelNumber;
            Debug.Log("Loading level : " + LevelName + " (" + levelSummary.BallData.Count + " balls)");
            foreach (var ballLevelData in levelSummary.BallData)
            {
                var newBall      = simpleObjectPool.GetObjectFromPool();
                var editableBall = newBall.GetComponent <EditableBall>();
                editableBall.SetData(ballLevelData);
                newBall.transform.SetParent(transform);
            }
        }
Exemplo n.º 3
0
        public void TestReadWriteData()
        {
            var gridEditorSettingsForExport = Substitute.For <IGridEditorSettings>();
            var gridEditorSettingsForImport = Substitute.For <IGridEditorSettings>();

            LevelSummary expectedLevelSummary = new LevelSummary(59, "the level name");

            for (int i = 0; i < 10; i++)
            {
                expectedLevelSummary.BallData.Add(CreateRandomBallData());
            }

            gridEditorSettingsForExport.GetExportData().Returns(expectedLevelSummary);
            LevelSummary actualLevelSummary = null;

            gridEditorSettingsForImport
            .When(e => e.SetLevelData(Arg.Any <LevelSummary>()))
            .Do(x => actualLevelSummary = x.Arg <LevelSummary>());

            var levelExporter = new LevelExporter(gridEditorSettingsForExport);
            var levelImporter = new LevelImporter(gridEditorSettingsForImport);

            levelExporter.Export();
            var expectedFile = GameConstants.Levels.RelativeResourcePath + "level-" + expectedLevelSummary.OrdinalNumber +
                               ".bin";

            FileAssert.Exists(expectedFile);

            var successfullyImported = levelImporter.Import(expectedFile);

            Assert.True(successfullyImported);

            Assert.NotNull(actualLevelSummary);
            Assert.AreEqual(expectedLevelSummary.LevelNumber, actualLevelSummary.LevelNumber);
            Assert.AreEqual(expectedLevelSummary.OrdinalNumber, actualLevelSummary.OrdinalNumber);
            CollectionAssert.AreEquivalent(expectedLevelSummary.BallData, actualLevelSummary.BallData);
        }
Exemplo n.º 4
0
    public void LoadSavedLevels()
    {
        string path = Path.Combine(Application.persistentDataPath, "Levels");

        if (!Directory.Exists(path))
        {
            return;
        }

        var levels = Directory.GetFiles(path);

        for (int i = 0; i < levels.Length; ++i)
        {
            if (Path.GetExtension(levels[i]) == ".data")
            {
                continue;
            }

            LevelInfo    levelInfo = new LevelInfo(LevelInfo.LevelType.Local);
            LevelSummary ls        = Instantiate(levelSummary, communityLocal.transform).GetComponent <LevelSummary>();
            levelInfo.levelSummary = ls;

            Level level = BinarySaveSystem.LoadFile <Level>(levels[i]);

            levelInfo.id          = Path.GetFileName(levels[i]);
            levelInfo.levelname   = level.name;
            levelInfo.size        = level.size;
            levelInfo.username    = level.creatorName;
            levelInfo.description = level.description;

            ls.ApplyInfo(levelInfo);
        }

        communityLocal.padding.right = levels.Length > 12 ? 60 : 15;
        scrollbarLocal.enabled       = levels.Length > 12;
        Invoke(nameof(SetLocalLevelsSize), 0.1f);
    }
Exemplo n.º 5
0
    public void ApplyAllLevelsData(string levelsData)
    {
        int       levels    = int.Parse(levelsData[0].ToString());
        int       lastChar  = 2;
        LevelInfo levelInfo = new LevelInfo(LevelInfo.LevelType.Online);

        char levelSeparator = '|';

        for (int i = 0; i < levels; ++i)
        {
            while (levelsData[lastChar] != '/')
            {
                string data = "";
                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.id = data;
                data         = "";
                ++lastChar;

                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.levelname = data;
                data = "";
                ++lastChar;

                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.description = data;
                data = "";
                ++lastChar;

                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.likesNumber = int.Parse(data);
                data = "";
                ++lastChar;

                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.username = data;
                data = "";
                ++lastChar;

                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.size = int.Parse(data);
                data           = "";
                ++lastChar;

                while (levelsData[lastChar] != levelSeparator)
                {
                    data += levelsData[lastChar];
                    ++lastChar;
                }

                levelInfo.usersLiked = data;
                data = "";
                ++lastChar;

                levelInfo.comments = new List <KeyValuePair <string, string> >();
                string comment = "";

                while (levelsData[lastChar] != '/')
                {
                    ++lastChar;

                    while (levelsData[lastChar] != 'ª')
                    {
                        comment += levelsData[lastChar];
                        ++lastChar;
                    }

                    ++lastChar;

                    while (levelsData[lastChar] != '|' && levelsData[lastChar] != '/')
                    {
                        data += levelsData[lastChar];
                        ++lastChar;
                    }

                    levelInfo.comments.Add(new KeyValuePair <string, string>(data, comment));
                    data    = "";
                    comment = "";
                }
            }

            ++lastChar;
            LevelSummary ls = Instantiate(levelSummary, communityContent.transform).GetComponent <LevelSummary>();
            levelInfo.levelSummary = ls;
            ls.ApplyInfo(levelInfo);
            levelInfo = new LevelInfo(LevelInfo.LevelType.Online);
        }


        communityContent.padding.right = levels > 12 ? 60 : 15;
        scrollbarCommunity.enabled     = levels > 12;
        Invoke(nameof(SetCommunityLevelsSize), 0.1f);
    }
Exemplo n.º 6
0
    public void ApplyLevelInfo(LevelInfo level, LevelSummary ls, bool setActiveFalse = false)
    {
        if ((lastLevelShown != null && level == null) || setActiveFalse)
        {
            lastLevelShown = null;

            puzzleInfo.SetActive(false);
            return;
        }
        else if (lastLevelShown == null && level != null)
        {
            puzzleInfo.SetActive(true);
        }

        levelname.text   = level.levelname;
        size.text        = "Size: " + level.size + "x" + level.size;
        username.text    = "MADE BY " + level.username;
        description.text = level.description;

        likeGO.SetActive(level.type == LevelInfo.LevelType.Online);
        commentsGO.SetActive(level.type == LevelInfo.LevelType.Online);
        commentGOButton.SetActive(level.type == LevelInfo.LevelType.Online);

        if (level.type == LevelInfo.LevelType.Online)
        {
            string likesS = level.likesNumber < 10 ? "0" + level.likesNumber.ToString() : level.likesNumber.ToString();
            likes.text = likesS;
            ls.ApplyInfo(level);

            string user       = "";
            string usersLiked = level.usersLiked;
            heartLike.color = Color.white;

            for (int i = 0; i < usersLiked.Length; ++i)
            {
                if (usersLiked[i] == ',')
                {
                    if (user == currentUsername)
                    {
                        heartLike.color = Color.green;
                    }

                    user = "";
                    continue;
                }

                user += usersLiked[i];
            }

            for (int i = 0; i < commentsContent.childCount; ++i)
            {
                Destroy(commentsContent.GetChild(i).gameObject);
            }

            for (int i = 0; i < level.comments.Count; ++i)
            {
                CommentStructure cs = Instantiate(commentPrefab, commentsContent).GetComponent <CommentStructure>();
                cs.SetCommentInfo(level.comments[i].Key, level.comments[i].Value);
            }

            scrollbar.enabled = level.comments.Count > 2;
            commentsContent.GetComponent <VerticalLayoutGroup>().padding.right = level.comments.Count > 2 ? 50 : 20;

            Invoke(nameof(SetCommentsSize), 0.1f);
        }

        editButton.SetActive(level.type == LevelInfo.LevelType.Local);
        deleteButton.SetActive(level.username == currentUsername || level.type == LevelInfo.LevelType.Local);
        lastLevelShown = level;
    }