Exemplo n.º 1
0
        /// <summary>
        ///     Asks the user if they'd like to create a new difficulty for the mapset,
        ///     and does so.
        /// </summary>
        public void CreateNewDifficulty() => ThreadScheduler.Run(() =>
        {
            if (MapManager.Selected.Value.Game != MapGame.Quaver)
            {
                NotificationManager.Show(NotificationLevel.Error, "You cannot create new difficulties for maps from other games. Create a new set!");
                return;
            }

            // Save the already existing map.
            if (Ruleset.ActionManager.HasUnsavedChanges)
            {
                DialogManager.Show(new EditorUnsavedChangesDialog(this));
                return;
            }

            Button.IsGloballyClickable = false;

            var qua            = ObjectHelper.DeepClone(WorkingMap);
            qua.DifficultyName = "";
            qua.MapId          = -1;
            qua.Description    = $"Created at {TimeHelper.GetUnixTimestampMilliseconds()}";

            var dir  = $"{ConfigManager.SongDirectory.Value}/{MapManager.Selected.Value.Directory}";
            var path = $"{dir}/{StringHelper.FileNameSafeString($"{qua.Artist} - {qua.Title} [{qua.DifficultyName}] - {TimeHelper.GetUnixTimestampMilliseconds()}")}.qua";
            qua.Save(path);

            // Add the new map to the db.
            var map       = Map.FromQua(qua, path);
            map.DateAdded = DateTime.Now;
            map.Id        = MapDatabaseCache.InsertMap(map, path);

            // Reload the mapsets
            MapDatabaseCache.OrderAndSetMapsets();

            // Set the selected one to the new one.
            MapManager.Selected.Value     = map;
            MapManager.Selected.Value.Qua = qua;

            // Find the mapset and get the *new* object w/ the selected map.
            var selectedMapset                              = MapManager.Mapsets.Find(x => x.Maps.Any(y => y.Id == MapManager.Selected.Value.Id));
            MapManager.Selected.Value                       = selectedMapset.Maps.Find(x => x.Id == MapManager.Selected.Value.Id);
            MapManager.Selected.Value.Qua                   = qua;
            MapManager.Selected.Value.NewlyCreated          = true;
            MapManager.Selected.Value.AskToRemoveHitObjects = true;

            // Reload editor w/ new one.
            Exit(() => new EditorScreen(qua));
        });
Exemplo n.º 2
0
        /// <summary>
        ///     Creates a new mapset with an audio file.
        /// </summary>
        /// <param name="audioFile"></param>
        public static void HandleNewMapsetCreation(string audioFile)
        {
            try
            {
                var game = GameBase.Game as QuaverGame;

                // Add a fade effect and make butotns not clickable
                // so the user can't perform any actions during this time.
                Transitioner.FadeIn();
                Button.IsGloballyClickable = false;

                var tagFile = TagLib.File.Create(audioFile);

                // Create a fresh .qua with the available metadata from the file
                var qua = new Qua()
                {
                    AudioFile      = Path.GetFileName(audioFile),
                    Artist         = tagFile.Tag.FirstPerformer ?? "",
                    Title          = tagFile.Tag.Title ?? "",
                    Source         = tagFile.Tag.Album ?? "",
                    Tags           = string.Join(" ", tagFile.Tag.Genres) ?? "",
                    Creator        = ConfigManager.Username.Value,
                    DifficultyName = "",
                    // Makes the file different to prevent exception thrown in the DB for same md5 checksum
                    Description    = $"Created at {TimeHelper.GetUnixTimestampMilliseconds()}",
                    BackgroundFile = "",
                    Mode           = GameMode.Keys4
                };

                // Create a new directory to house the map.
                var dir = $"{ConfigManager.SongDirectory.Value}/{TimeHelper.GetUnixTimestampMilliseconds()}";
                Directory.CreateDirectory(dir);

                // Copy over the audio file into the directory
                File.Copy(audioFile, $"{dir}/{Path.GetFileName(audioFile)}");

                // Save the new .qua file into the directory
                var path = $"{dir}/{StringHelper.FileNameSafeString($"{qua.Artist} - {qua.Title} [{qua.DifficultyName}] - {TimeHelper.GetUnixTimestampMilliseconds()}")}.qua";
                qua.Save(path);

                // Place the new map inside of the database and make sure all the loaded maps are correct
                var map = Map.FromQua(qua, path);
                map.Id = MapDatabaseCache.InsertMap(map, path);
                MapDatabaseCache.OrderAndSetMapsets();

                MapManager.Selected.Value     = map;
                MapManager.Selected.Value.Qua = qua;

                var selectedMapset = MapManager.Mapsets.Find(x => x.Maps.Any(y => y.Id == MapManager.Selected.Value.Id));

                // Find the new object from the loaded maps that contains the same id.
                MapManager.Selected.Value              = selectedMapset.Maps.Find(x => x.Id == MapManager.Selected.Value.Id);
                MapManager.Selected.Value.Qua          = qua;
                MapManager.Selected.Value.NewlyCreated = true;

                game?.CurrentScreen.Exit(() => new EditorScreen(qua));
            }
            catch (Exception e)
            {
                Logger.Error(e, LogType.Runtime);

                var game = GameBase.Game as QuaverGame;

                game?.CurrentScreen.Exit(() =>
                {
                    NotificationManager.Show(NotificationLevel.Error, "Could not create new mapset with that audio file.");
                    return(new SelectScreen());
                });
            }
        }