Ejemplo n.º 1
0
        public void ExternalIdConflictImport_CreateNew()
        {
            CreateFakeLevel("testlevel", null);
            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));
            Level oldLevel = LevelQuery.List().First();

            CreateFakeLevel("testlevel", null, "", "newSong");
            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));
            FileManagement.FinalizeImport();

            IEnumerable <Level> levels = LevelQuery.List();
            int count = levels.Count();

            if (count != 2)
            {
                Assert.Fail($"Expected 2 levels but {count} exists");
            }

            foreach (Level level in levels)
            {
                if (level.Charts[0].Name == "newSong")
                {
                    Assert.Pass("Level imported as new");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <List <Level> > GetLevels(LevelQuery query)
        {
            var content = await RepositoryParser.ParseRepository <List <Level> >(filePaths.Levels);

            var queryedItems = FilterLevels(content, query);

            return(queryedItems);
        }
Ejemplo n.º 3
0
        public void LevelAndPackImport_Success()
        {
            CreateFakeLevel("testlevel", "testpack", "level");
            CreateFakePack("testpack", "pack");

            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));

            int levelCount = LevelQuery.List().Count();
            int packCount  = PackQuery.List().Count();

            Assert.That(packCount == 1 && levelCount == 1);
        }
Ejemplo n.º 4
0
    public static void QueryAllLevels()
    {
        levelsToDownload = 0;
        levelsDownloaded = 0;
        tempLevels       = new List <LevelQuery>();
        levelsHolder     = null;

        const long maxAllowedSize = 4 * 1024 * 1024;

        FirebaseDatabase.DefaultInstance.RootReference.Child("User_Levels").GetValueAsync().ContinueWith(x => {
            foreach (DataSnapshot item in x.Result.Children)
            {
                if (user == null || FormattedUserName != item.Key)
                {
                    string author = item.Key;
                    foreach (DataSnapshot level in item.Children)
                    {
                        lock (myLock)
                        {
                            levelsToDownload++;
                        }
                        string lName = level.Key;
                        string fPath = level.Child("File_Path").Value.ToString();
                        string pPath = level.Child("Picture_Path").Value.ToString();
                        root.Child(pPath).GetBytesAsync(maxAllowedSize).ContinueWith(done => {
                            Texture2D screenShot = new Texture2D(512, 512);
                            screenShot.LoadImage(done.Result);
                            screenShot.Apply();
                            LevelQuery newLevel = new LevelQuery
                            {
                                levelAuthor = author,
                                filePath    = fPath,
                                picPath     = pPath,
                                screenshot  = screenShot,
                                lName       = lName
                            };
                            lock (myLock)
                            {
                                levelsToDownload--;
                                tempLevels.Add(newLevel);
                                if (levelsToDownload <= 0)
                                {
                                    levelsHolder = tempLevels.ToArray();
                                    onUserFilesCached();
                                }
                            }
                        });
                    }
                }
            }
        });
    }
Ejemplo n.º 5
0
    void ShowCloudLevelOptions(LevelQuery level, bool isMyLevel)
    {
        cloudLevelOptions.transform.GetChild(0).GetComponent <Text>().text = level.lName;
        cloudLevelOptions.transform.GetChild(1).GetComponent <Text>().text = level.levelAuthor;
        Button downloadButton = cloudLevelOptions.transform.GetChild(2).transform.GetChild(0)
                                .GetComponent <Button>();

        cloudLevelOptions.transform.GetChild(2).transform.GetChild(1)
        .GetComponent <Button>().interactable = false;
        downloadButton.onClick.RemoveAllListeners();
        downloadButton.onClick.AddListener(delegate { FirebaseManager.DownloadLevel(level);
                                                      cloudLevelOptions.SetActive(false);
                                                      ShowMainMenu(); });
    }
 public async Task <IActionResult> GetLevels([FromQuery] LevelQuery query)
 {
     try
     {
         return(Ok(await levelsService.GetLevels(query)));
     }
     catch (FileNotFoundException ex)
     {
         return(BadRequest(ex));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Ejemplo n.º 7
0
        public void ExternalIdConflictImport_ReplaceOld()
        {
            CreateFakeLevel("testlevel", null);
            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));
            Level oldLevel = LevelQuery.List().First();

            CreateFakeLevel("testlevel", null, "", "replacedSong");
            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));

            foreach (List <IArccoreInfo> conflict in FileManagement.GetConflicts())
            {
                FileManagement.Replace(conflict[0]);
            }
            FileManagement.FinalizeImport();

            Assert.AreEqual(LevelQuery.Get(oldLevel.Id).Charts[0].Name, "replacedSong");
        }
Ejemplo n.º 8
0
        public void LevelImport_Success()
        {
            CreateFakeLevel("testlevel");

            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));

            IEnumerable <Level> levels = LevelQuery.List();
            int count;

            if ((count = levels.Count()) != 1)
            {
                Assert.Fail($"There should only be one level but {count} levels found");
            }

            Level level = levels.First();

            Assert.That(level.ExternalId == "testlevel");
        }
Ejemplo n.º 9
0
    public static void DownloadLevel(LevelQuery level)
    {
        string authorDir = Application.persistentDataPath + "/UserLevels/" + level.levelAuthor + "/";
        string levelDir  = Path.Combine(authorDir, level.lName);
        string fileDir   = Path.Combine(levelDir, level.lName + ".xml");
        string picDir    = Path.Combine(levelDir, level.lName + ".png");

        if (!Directory.Exists(authorDir))
        {
            Directory.CreateDirectory(authorDir);
        }
        if (!Directory.Exists(levelDir))
        {
            Directory.CreateDirectory(levelDir);
        }
        root.Child(level.filePath).GetFileAsync(fileDir);
        root.Child(level.picPath).GetFileAsync(picDir);
        LevelManager.RebuildLists();
    }
Ejemplo n.º 10
0
    public static void QueryMyLevels()
    {
        levelsHolder     = null;
        tempLevels       = new List <LevelQuery>();
        levelsToDownload = 0;
        const long maxAllowedSize = 4 * 1024 * 1024;

        FirebaseDatabase.DefaultInstance.RootReference.Child("User_Levels").Child(FirebaseManager.FormattedUserName).GetValueAsync().ContinueWith(x => {
            foreach (DataSnapshot child in x.Result.Children)
            {
                lock (myLock)
                {
                    levelsToDownload++;
                }
                string levelName = child.Key;
                string filePath  = child.Child("File_Path").Value.ToString();
                string picPath   = child.Child("Picture_Path").Value.ToString();
                root.Child(picPath).GetBytesAsync(maxAllowedSize).ContinueWith(done => {
                    Texture2D screenTex = new Texture2D(512, 512);
                    screenTex.LoadImage(done.Result);
                    screenTex.Apply();
                    LevelQuery newLevel = new LevelQuery {
                        lName       = levelName,
                        filePath    = filePath,
                        picPath     = picPath,
                        screenshot  = screenTex,
                        levelAuthor = FormattedUserName
                    };
                    lock (myLock)
                    {
                        tempLevels.Add(newLevel);
                        levelsToDownload--;
                        if (levelsToDownload <= 0)
                        {
                            levelsHolder = tempLevels.ToArray();
                            onMyFilesCached();
                        }
                    }
                });
            }
        });
    }
Ejemplo n.º 11
0
 public void LoadUserLevels()
 {
     currentUserCloudLevels = new List <GameObject>();
     foreach (LevelQuery level in FirebaseManager.levelsHolder)
     {
         GameObject newCloudObject = Instantiate(cloudButton);
         newCloudObject.GetComponentInChildren <Button>().onClick.AddListener(delegate {
             cloudDataObject.SetActive(false);
             cloudLevelOptions.SetActive(true);
             cloudLevelSelected = level;
             ShowCloudLevelOptions(cloudLevelSelected, false);
         });
         RectTransform cloudTrans = newCloudObject.GetComponent <RectTransform>();
         newCloudObject.transform.SetParent(cloudDataHolder);
         newCloudObject.transform.Find("LevelName").GetComponent <Text>().text  = level.lName;
         newCloudObject.transform.Find("AuthorName").GetComponent <Text>().text = level.levelAuthor;
         newCloudObject.transform.Find("Image").GetComponent <Image>().sprite   = Sprite.Create(level.screenshot, new Rect(0, 0, 512, 512), new Vector2());
         cloudTrans.localScale = new Vector3(1, 1, 1);
         currentUserCloudLevels.Add(newCloudObject);
     }
 }
Ejemplo n.º 12
0
        public void ExternalIdConflictImport_Abort()
        {
            CreateFakeLevel("testlevel", null);
            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));
            Level oldLevel = LevelQuery.List().First();

            CreateFakeLevel("testlevel", null, "", "newSong");
            FileManagement.ImportDirectory(new DirectoryInfo(tempPath));
            FileManagement.Cleanup();

            IEnumerable <Level> levels = LevelQuery.List();
            int count = levels.Count();

            if (count != 1)
            {
                Assert.Fail($"Expected 1 levels but {count} exists");
            }

            Level level = levels.First();

            Assert.AreEqual(level.Charts[0].Name, "testsong");
        }
Ejemplo n.º 13
0
        private List <Level> FilterLevels(List <Level> levels, LevelQuery query)
        {
            if (query == null)
            {
                return(levels);
            }

            if (query.Id != null)
            {
                levels = levels.Where(x => query.Id.IndexOf(x.Id) >= 0).ToList();
            }

            if (query.Name != null)
            {
                levels = levels.Where(x =>
                                      query.Name.Any(y =>
                                                     x.Name.ToLower()
                                                     .Contains(y.ToLower()
                                                               )
                                                     )
                                      ).ToList();
            }

            if (query.GameId != null)
            {
                levels = levels.Where(x =>
                                      query.GameId.Any(id =>
                                                       x.AppearsInGame.Any(
                                                           y => y.Contains(id.ToString())
                                                           )
                                                       )
                                      ).ToList();
            }

            if (query.LevelId != null)
            {
                levels = levels.Where(x =>
                                      query.LevelId.Any(id =>
                                                        x.Id == id
                                                        )
                                      ).ToList();
            }

            if (query.LevelNumber != null)
            {
                levels = levels.Where(x =>
                                      query.LevelNumber.Any(id =>
                                                            x.LevelNumber == id
                                                            )
                                      ).ToList();
            }

            if (query.CharacterId != null)
            {
                levels = levels.Where(x =>
                                      query.CharacterId.Any(id =>
                                                            x.Characters.Any(
                                                                y => y.Contains(id.ToString())
                                                                )
                                                            )
                                      ).ToList();
            }

            if (query.CollectableId != null)
            {
                levels = levels.Where(x =>
                                      query.CollectableId.Any(id =>
                                                              x.Collectables.Any(
                                                                  y => y.Contains(id.ToString())
                                                                  )
                                                              )
                                      ).ToList();
            }

            if (query.LevelType != null)
            {
                levels = levels.Where(x =>
                                      query.LevelType.Any(type => type == x.Type)
                                      ).ToList();
            }

            if (query.AbilityId != null)
            {
                levels = levels.Where(x =>
                                      query.AbilityId.Any(id =>
                                                          x.AbilitiesLearned.Any(
                                                              y => y.Contains(id.ToString())
                                                              )
                                                          )
                                      ).ToList();
            }

            if (query.TransformationId != null)
            {
                levels = levels.Where(x =>
                                      query.TransformationId.Any(id =>
                                                                 x.Transformations.Any(
                                                                     y => y.Contains(id.ToString())
                                                                     )
                                                                 )
                                      ).ToList();
            }

            return(levels);
        }