Пример #1
0
        private Beatmap BeatmapConstructorWrapper(string beatmapFilename)
        {
            Beatmap newBeatmap = new Beatmap(beatmapFilename);

            if (newBeatmap.ApproachRate == -1M)
            {
                newBeatmap.ApproachRate = newBeatmap.OverallDifficulty; // i can't believe this is how old maps used to work...
                if (newBeatmap.ApproachRate == 0)
                {
                    var _ = new ZeroARException();
                }
            }
            return(newBeatmap);
        }
Пример #2
0
        private async void ServiceBeatmapChangeRequest()
        {
            // acquire mutually exclusive entry into this method
            serviceBeatmapRequestLocked = true;

            Beatmap candidateOriginalBeatmap = null, candidateNewBeatmap = null;

            while (completedBeatmapRequest == null || completedBeatmapRequest.RequestNumber != mapChangeRequests.Last().RequestNumber)
            {
                completedBeatmapRequest  = mapChangeRequests.Last();
                candidateOriginalBeatmap = await Task.Run(() => LoadBeatmap(mapChangeRequests.Last().Name));

                if (candidateOriginalBeatmap != null)
                {
                    candidateNewBeatmap = new Beatmap(candidateOriginalBeatmap);
                }

                // if a new request came in, invalidate candidate beatmap and service the new request
            }

            // no new requests, we can commit to using this beatmap
            OriginalBeatmap = candidateOriginalBeatmap;
            NewBeatmap      = candidateNewBeatmap;
            if (OriginalBeatmap == null)
            {
                SetState(EditorState.NOT_READY);
                NotReadyReason = BadBeatmapReason.ERROR_LOADING_BEATMAP;
                BeatmapSwitched?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                if (OriginalBeatmap.HitObjectCount == 0)
                {
                    SetState(EditorState.NOT_READY);
                    NotReadyReason = BadBeatmapReason.EMPTY_MAP;
                    BeatmapSwitched?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    // Apply multiplier
                    NewBeatmap.SetRate(BpmMultiplier);

                    // Apply bpm scaled settings
                    if (ScaleAR)
                    {
                        NewBeatmap.ApproachRate = DifficultyCalculator.CalculateMultipliedAR(candidateOriginalBeatmap, BpmMultiplier);
                    }
                    if (NewBeatmap.ApproachRate == 0)
                    {
                        var _ = new ZeroARException();
                    }
                    if (ScaleOD)
                    {
                        NewBeatmap.OverallDifficulty = DifficultyCalculator.CalculateMultipliedOD(candidateOriginalBeatmap, BpmMultiplier);
                    }

                    // Apply locked settings
                    if (HpIsLocked)
                    {
                        NewBeatmap.HPDrainRate = lockedHP;
                    }
                    if (CsIsLocked)
                    {
                        NewBeatmap.CircleSize = lockedCS;
                    }
                    if (ArIsLocked)
                    {
                        NewBeatmap.ApproachRate = lockedAR;
                        if (NewBeatmap.ApproachRate == 0)
                        {
                            var _ = new ZeroARException();
                        }
                    }
                    if (OdIsLocked)
                    {
                        NewBeatmap.OverallDifficulty = lockedOD;
                    }
                    if (BpmIsLocked)
                    {
                        SetBpm(lockedBpm);
                    }

                    // Apply Hardrock
                    if (EmulateHardrock)
                    {
                        NewBeatmap.CircleSize = OriginalBeatmap.CircleSize * 1.3M;
                    }
                    if (EmulateHardrock)
                    {
                        NewBeatmap.OverallDifficulty = JunUtils.Clamp(GetScaledOD() * 1.4M, 0M, 10M);
                    }

                    SetState(EditorState.READY);
                    RequestDiffCalc();
                    BeatmapSwitched?.Invoke(this, EventArgs.Empty);
                    BeatmapModified?.Invoke(this, EventArgs.Empty);
                }
            }
            ControlsModified?.Invoke(this, EventArgs.Empty);
            serviceBeatmapRequestLocked = false;
        }
Пример #3
0
        public void GenerateBeatmap()
        {
            if (State != EditorState.READY)
            {
                return;
            }

            SetState(EditorState.GENERATING_BEATMAP);

            bool compensateForDT = (NewBeatmap.ApproachRate > 10 || NewBeatmap.OverallDifficulty > 10);

            // Set metadata
            Beatmap exportBeatmap = new Beatmap(NewBeatmap);

            ModifyBeatmapMetadata(exportBeatmap, BpmMultiplier, ChangePitch, compensateForDT);

            // Slow down map by 1.5x
            if (compensateForDT)
            {
                exportBeatmap.ApproachRate = DifficultyCalculator.CalculateMultipliedAR(NewBeatmap, 1 / 1.5M);
                if (exportBeatmap.ApproachRate == 0)
                {
                    var _ = new ZeroARException();
                }
                exportBeatmap.OverallDifficulty = DifficultyCalculator.CalculateMultipliedOD(NewBeatmap, 1 / 1.5M);
                decimal compensatedRate = (NewBeatmap.Bpm / OriginalBeatmap.Bpm) / 1.5M;
                exportBeatmap.SetRate(compensatedRate);
            }

            // remove spinners
            if (NoSpinners)
            {
                exportBeatmap.RemoveSpinners();
            }

            // Generate new mp3
            var audioFilePath = Path.Combine(JunUtils.GetBeatmapDirectoryName(OriginalBeatmap), exportBeatmap.AudioFilename);
            var newMp3        = "";

            if (!File.Exists(audioFilePath))
            {
                string inFile  = Path.Combine(Path.GetDirectoryName(OriginalBeatmap.Filename), OriginalBeatmap.AudioFilename);
                string outFile = Path.Combine(Path.GetTempPath(), exportBeatmap.AudioFilename);

                SongSpeedChanger.GenerateAudioFile(inFile, outFile, BpmMultiplier, mainform.BackgroundWorker, ChangePitch, compensateForDT);
                newMp3 = outFile;

                // take note of this mp3 in a text file, so we can clean it up later
                string        mp3ManifestFile = GetMp3ListFilePath();
                List <string> manifest        = File.ReadAllLines(mp3ManifestFile).ToList();
                string        beatmapFolder   = Path.GetDirectoryName(exportBeatmap.Filename).Replace(Properties.Settings.Default.SongsFolder + "\\", "");
                string        mp3RelativePath = Path.Combine(beatmapFolder, exportBeatmap.AudioFilename);
                manifest.Add(mp3RelativePath + " | " + exportBeatmap.Filename);
                File.WriteAllLines(mp3ManifestFile, manifest);
            }
            // save file to temp location (do not directly put into any song folder)
            exportBeatmap.Filename = Path.Combine(Path.GetTempPath(), Path.GetFileName(exportBeatmap.Filename));
            exportBeatmap.Save();

            // create and execute osz
            AddNewBeatmapToSongFolder(Path.GetDirectoryName(OriginalBeatmap.Filename), exportBeatmap.Filename, newMp3);

            // post
            SetState(EditorState.READY);
        }