Пример #1
0
        public void LoadNewSongPack(SongPack songPack)
        {
            if (form.listSongPacks.SelectedIndex < 0)
            {
                return;
            }

            form.grpMaps.Visible = true;

            songPack.ReloadMapsListInCurrentSongPack(form.listMap);
        }
Пример #2
0
        public void SwapItems(SongPack songPack, CustomMap map1, CustomMap map2)
        {
            int map1Index = songPack.CustomMaps.IndexOf(map1);
            int map2Index = songPack.CustomMaps.IndexOf(map2);

            songPack.CustomMaps.Remove(map1);
            songPack.CustomMaps.Remove(map2);

            songPack.CustomMaps.Insert(map1Index, map2);
            songPack.CustomMaps.Insert(map2Index, map1);

            songPack.ReloadSongPackOrderFile();
        }
Пример #3
0
        public void ReLoadSongPacks()
        {
            form.listMap.Items.Clear();
            form.listSongPacks.Items.Clear();
            songPacks.Clear();

            if (!Directory.Exists(SONG_PACK_FOLDER))
            {
                Directory.CreateDirectory(SONG_PACK_FOLDER);
            }

            foreach (var directory in Directory.GetDirectories(SONG_PACK_FOLDER))
            {
                SongPack songPack = new SongPack(directory, false);
                songPacks.Add(songPack);

                form.listSongPacks.Items.Add(directory.Split('\\').Last());
            }
        }
Пример #4
0
        public void DeleteSongPack(SongPack songPack)
        {
            if (form.listSongPacks.SelectedIndex < 0)
            {
                return;
            }

            if (Directory.Exists(songPack.path))
            {
                Directory.Delete(songPack.path, true);
            }
            else
            {
                MessageBox.Show("This song pack doesn't exist!");
            }

            ReLoadSongPacks();
            form.grpMaps.Visible = false;
        }
Пример #5
0
        public void DeleteMap(SongPack songPack)
        {
            try
            {
                string directory = songPack.CustomMaps[form.listMap.SelectedIndex].directoryPath;
                if (Directory.Exists(directory))
                {
                    Directory.Delete(directory, true);
                }
                else
                {
                    MessageBox.Show("This map doesn't exist!");
                }

                songPack.ReloadMapsListInCurrentSongPack(form.listMap);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #6
0
        public async void AddMap(SongPack songPack)
        {
            using (var openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Title = "Select a difficulty .dat file";

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    if (openFileDialog.FileName.Contains("info.dat"))
                    {
                        MessageBox.Show("You must select a difficulty .dat file!");
                    }
                    else if (openFileDialog.FileName.EndsWith(".dat"))
                    {
                        await songPack.AddMap(openFileDialog.FileName, songPack.DisplayName, true, form.listMap);
                    }
                    else
                    {
                        MessageBox.Show("You must select a .dat file!");
                    }
                }
            }
        }
Пример #7
0
        public static void MergeMaps(Form1 form, SongPack currentSongPack)
        {
            double newBPM;

            try
            {
                newBPM = Convert.ToDouble(form.txtNewBpm.Text);
            }
            catch
            {
                MessageBox.Show("I can only understand digits...");
                return;
            }

            var mergedEvents    = new List <_Events>();
            var mergedNotes     = new List <_Notes>();
            var mergedObstacles = new List <_Obstacles>();

            bool ignoringEvents    = form.checkIgnoreEvents.Checked;
            bool ignoringObstacles = form.checkIgnoreObstacles.Checked;

            // Move the notes to a way that changes the bpm of the map
            foreach (var customMap in currentSongPack.CustomMaps)
            {
                ItemBase.ItemBase.ConvertItemBeatsToSeconds(customMap.map._notes, mergedNotes, customMap.info._beatsPerMinute);
                if (!ignoringEvents)
                {
                    ItemBase.ItemBase.ConvertItemBeatsToSeconds(customMap.map._events, mergedEvents, customMap.info._beatsPerMinute);
                }
                if (!ignoringObstacles)
                {
                    ItemBase.ItemBase.ConvertItemBeatsToSeconds(customMap.map._obstacles, mergedObstacles, customMap.info._beatsPerMinute);
                }
            }

            ItemBase.ItemBase.ConvertItemSecondsToBeats(mergedNotes, newBPM);
            if (!ignoringEvents)
            {
                ItemBase.ItemBase.ConvertItemSecondsToBeats(mergedEvents, newBPM);
            }
            if (!ignoringObstacles)
            {
                ItemBase.ItemBase.ConvertItemSecondsToBeats(mergedObstacles, newBPM);
            }
            //////////////////////////////////////////////////////////////////////////

            // Move the notes behind the current map
            double?currentMapLengthInBeats = null;

            foreach (var customMap in currentSongPack.CustomMaps)
            {
                if (currentMapLengthInBeats.HasValue)
                {
                    double distanceToMove = currentMapLengthInBeats.Value;
                    ItemBase.ItemBase.MoveItems(customMap.map._notes, distanceToMove);
                    if (!ignoringEvents)
                    {
                        ItemBase.ItemBase.MoveItems(customMap.map._events, distanceToMove);
                    }
                    if (!ignoringObstacles)
                    {
                        ItemBase.ItemBase.MoveItems(customMap.map._obstacles, distanceToMove);
                    }
                }

                if (!currentMapLengthInBeats.HasValue)
                {
                    currentMapLengthInBeats = 0;
                }
                currentMapLengthInBeats += customMap.SongLengthInMilliSeconds / Rootobject.GetBeatLengthInMS(newBPM);
            }
            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // TODO customData need to be implemented                                                            //
            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            var mergedMap = new Rootobject
            {
                _events     = mergedEvents.ToArray(),
                _notes      = mergedNotes.ToArray(),
                _obstacles  = mergedObstacles.ToArray(),
                _version    = currentSongPack.CustomMaps[0].map._version,
                _customData = null
            };

            var customInfo = new Info.Rootobject()
            {
                _version            = currentSongPack.CustomMaps.First().info._version,
                _songName           = "Merged",
                _songSubName        = "",
                _songAuthorName     = "Various Artists",
                _levelAuthorName    = "BeatMerge",
                _beatsPerMinute     = newBPM,
                _shuffle            = currentSongPack.CustomMaps.First().info._shuffle,
                _shufflePeriod      = currentSongPack.CustomMaps.First().info._shufflePeriod,
                _previewStartTime   = 10,
                _previewDuration    = 12,
                _songFilename       = "song.ogg",
                _coverImageFilename = "cover.jpg",
                _environmentName    = currentSongPack.CustomMaps.First().info._environmentName,
                _songTimeOffset     = 0,
                _customData         = currentSongPack.CustomMaps.First().info._customData,
            };

            var customData = new Info._Customdata1()
            {
                _difficultyLabel = "Pack",
                _editorOffset    = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._customData._editorOffset,
                _editorOldOffset = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._customData._editorOldOffset,
                _information     = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._customData._information,
                _requirements    = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._customData._requirements,
                _suggestions     = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._customData._suggestions,
                _warnings        = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._customData._warnings
            };

            Info._Difficultybeatmaps[] customDifficultybeatmaps = new Info._Difficultybeatmaps[1];
            Info._Difficultybeatmaps   temp = new Info._Difficultybeatmaps
            {
                _difficulty              = "ExpertPlus",
                _difficultyRank          = 9,
                _beatmapFilename         = "ExpertPlusStandard.dat",
                _noteJumpMovementSpeed   = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._noteJumpMovementSpeed,
                _noteJumpStartBeatOffset = currentSongPack.CustomMaps.First().info._difficultyBeatmapSets.First()._difficultyBeatmaps.First()._noteJumpStartBeatOffset,
                _customData              = customData
            };
            customDifficultybeatmaps[0] = temp;

            Info._Difficultybeatmapsets[] customdifficultyBeatmapSets = new Info._Difficultybeatmapsets[1];
            Info._Difficultybeatmapsets   tempo = new Info._Difficultybeatmapsets();
            tempo._beatmapCharacteristicName = "Standard";
            tempo._difficultyBeatmaps        = customDifficultybeatmaps;

            customdifficultyBeatmapSets[0] = tempo;

            customInfo._difficultyBeatmapSets = customdifficultyBeatmapSets;

            Info.Rootobject firstSongInfo = customInfo;

            try
            {
                string mergedDirectory = "Merged Map";
                if (Directory.Exists(mergedDirectory))
                {
                    Directory.Delete(mergedDirectory, true);
                }

                Directory.CreateDirectory(mergedDirectory);

                for (int i = 0; i < currentSongPack.CustomMaps.Count; i++)
                {
                    CustomMap custmMap = currentSongPack.CustomMaps[i];
                    File.Copy(custmMap.audioPath, mergedDirectory + "/" + i + Path.GetExtension(custmMap.audioPath));
                }

                string difficulty = mergedDirectory + "/" + "ExpertPlusStandard.dat";
                using (StreamWriter wr = new StreamWriter(difficulty))
                    wr.WriteLine(JsonConvert.SerializeObject(mergedMap));

                string info = mergedDirectory + "/info.dat";
                using (StreamWriter wr = new StreamWriter(info))
                    wr.WriteLine(JsonConvert.SerializeObject(firstSongInfo));

                System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
                {
                    WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
                    FileName    = "cmd.exe",
                    Arguments   = "/C cd " + AppDomain.CurrentDomain.BaseDirectory + mergedDirectory + "\\"
                };
                startInfo.Arguments += " & copy /b";
                for (int i = 0; i < currentSongPack.CustomMaps.Count; i++)
                {
                    CustomMap custmMap = currentSongPack.CustomMaps[i];
                    if (i == 0)
                    {
                        startInfo.Arguments += " " + i + Path.GetExtension(custmMap.audioPath);
                    }
                    else
                    {
                        startInfo.Arguments += " +" + i + Path.GetExtension(custmMap.audioPath);
                    }
                }
                startInfo.Arguments += " song.ogg";
                process.StartInfo    = startInfo;
                process.Start();
                process.WaitForExit();

                for (int i = 0; i < currentSongPack.CustomMaps.Count; i++)
                {
                    CustomMap custmMap = currentSongPack.CustomMaps[i];
                    File.Delete(mergedDirectory + "/" + i + Path.GetExtension(custmMap.audioPath));
                }

                MessageBox.Show("A new folder called " + mergedDirectory + " has been created");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #8
0
        private void btnMerge_Click(object sender, EventArgs e)
        {
            SongPack currentSongPack = songPackManager.GetCurrentSongPack();

            Task.Run(() => MapsMergerHelper.MergeMaps(this, currentSongPack));
        }