Beispiel #1
0
        static string GetColoursToSave(BeatMap toWrite)
        {
            string ColoursToSave = null;
            int    number        = 1;

            foreach (colour rgb in toWrite.Colours)
            {
                ColoursToSave += "Combo" + number + " : " + rgb.Red + ',' + rgb.Green + ',' + rgb.Blue + "\r\n";
                number++;
            }
            return(ColoursToSave);
        }
Beispiel #2
0
        /// <summary>
        /// Saves the BeatMap object as .osu file in the specified path
        /// </summary>
        /// <param name="path">File save path</param>
        /// <param name="toWrite">Object to write</param>
        public static void SaveDotOsu(string path, BeatMap toWrite)
        {
            IniFile beatmap = new IniFile(path);

            beatmap.WriteAllSection("General",
                                    "AudioFilename: " + toWrite.FileName +
                                    "\r\nAudioLeadin: " + toWrite.AudioLeadIn +
                                    "\r\nPreviewTime: " + toWrite.PreviewTime +
                                    "\r\nCountDown: " + toWrite.Countdown +
                                    "\r\nSampleSet: " + toWrite.SampleSet +
                                    "\r\nStackLeniency: " + toWrite.StackLeniency +
                                    "\r\nMode: " + toWrite.Mode +
                                    "\r\nLetterBoxInBreaks: " + toWrite.LetterBoxInBreaks +
                                    "\r\nWideScreenStoryboard" + toWrite.WideScreenStoryboard);
            beatmap.WriteAllSection("Metadata",
                                    "Title: " + toWrite.Title +
                                    "\r\nTitleUnicode: " + toWrite.TitleUnicode +
                                    "\r\nArtist: " + toWrite.Artist +
                                    "\r\nArtistUnicode: " + toWrite.ArtistUnicode +
                                    "\r\nCreator: " + toWrite.Creator +
                                    "\r\nVersion: " + toWrite.Version +
                                    "\r\nSource: " + toWrite.Source +
                                    "\r\nTags: " + toWrite.Tags +
                                    "\r\nBeatmapID: " + toWrite.BeatmapID +
                                    "\r\nBeatmapSetID: " + toWrite.BeatmapSetID);
            beatmap.WriteAllSection("Difficulty",
                                    "HPDrainRate: " + toWrite.HPDrainRate +
                                    "\r\nCircleSize: " + toWrite.CircleSize +
                                    "\r\nOverallDifficulty: " + toWrite.OverallDifficulty +
                                    "\r\nApproachRate: " + toWrite.ApproachRate +
                                    "\r\nSliderMultiplier: " + toWrite.SliderMultiplier +
                                    "\r\nSliderTickRate: " + toWrite.SliderTickRate);
            beatmap.WriteAllSection("Colours", GetColoursToSave(toWrite));
            beatmap.WriteAllSection("TimingPoints", GetTimingPointString(toWrite.TimingPoints));
            beatmap.WriteAllSection("HitObjects", GetHitObjectsString(toWrite.SingleNotes, toWrite.LongNotes));
        }
Beispiel #3
0
        /// <summary>
        /// Load and deserialize a specified .osu file
        /// </summary>
        /// <returns>The .osu file as BeatMap object</returns>
        /// <param name="path">File location of the .osu (including the filename itself)</param>
        public static BeatMap LoadDotOsu(string path)
        {
            #region Read of the file as ini
            IniFile beatmap = new IniFile(path);
            Dictionary <string, string> generalKeyPairs    = beatmap.GetKeyValuesPair("General");
            Dictionary <string, string> metadataKeyPairs   = beatmap.GetKeyValuesPair("Metadata");
            Dictionary <string, string> difficultyKeyPairs = beatmap.GetKeyValuesPair("Difficulty");
            Dictionary <string, string> coloursKeyPairs    = beatmap.GetKeyValuesPair("Colours");
            #endregion
            #region read of the file as raw text
            string rawBeatmap = File.ReadAllText(path);
            //Istantiate the return object
            BeatMap parsedMap = new BeatMap();
            #endregion
            //--------------------------------------------------------------
            //Conversion of the values from ini to a dynamic object.
            #region General
            string value;
            if (generalKeyPairs.TryGetValue("AudioFilename", out value))
            {
                parsedMap.FileName = value;
            }
            if (generalKeyPairs.TryGetValue("AudioLeadIn", out value))
            {
                parsedMap.AudioLeadIn = int.Parse(value);
            }
            if (generalKeyPairs.TryGetValue("PreviewTime", out value))
            {
                parsedMap.PreviewTime = int.Parse(value);
            }
            if (generalKeyPairs.TryGetValue("CountDown", out value))
            {
                parsedMap.Countdown = bool.Parse(value);
            }
            if (generalKeyPairs.TryGetValue("SampleSet", out value))
            {
                parsedMap.SampleSet = value;
            }
            if (generalKeyPairs.TryGetValue("StackLeniency", out value))
            {
                parsedMap.StackLeniency = float.Parse(value);
            }
            if (generalKeyPairs.TryGetValue("Mode", out value))
            {
                parsedMap.Mode = int.Parse(value);
            }
            if (generalKeyPairs.TryGetValue("LetterBoxInBreaks", out value))
            {
                parsedMap.LetterBoxInBreaks = bool.Parse(value);
            }
            if (generalKeyPairs.TryGetValue("WideScreenStoryboard", out value))
            {
                parsedMap.WideScreenStoryboard = bool.Parse(value);
            }
            #endregion
            #region Metadata
            if (metadataKeyPairs.TryGetValue("Title", out value))
            {
                parsedMap.Title = value;
            }
            if (metadataKeyPairs.TryGetValue("TitleUnicode", out value))
            {
                parsedMap.TitleUnicode = value;
            }
            if (metadataKeyPairs.TryGetValue("Artist", out value))
            {
                parsedMap.Artist = value;
            }
            if (metadataKeyPairs.TryGetValue("ArtistUnicode", out value))
            {
                parsedMap.ArtistUnicode = value;
            }
            if (metadataKeyPairs.TryGetValue("Creator", out value))
            {
                parsedMap.Creator = value;
            }
            if (metadataKeyPairs.TryGetValue("Version", out value))
            {
                parsedMap.Version = value;
            }
            if (metadataKeyPairs.TryGetValue("Source", out value))
            {
                parsedMap.Source = value;
            }
            if (metadataKeyPairs.TryGetValue("Tags", out value))
            {
                parsedMap.Tags = value;
            }
            if (metadataKeyPairs.TryGetValue("BeatmapID", out value))
            {
                parsedMap.BeatmapID = int.Parse(value);
            }
            if (metadataKeyPairs.TryGetValue("BeatmapSetID", out value))
            {
                parsedMap.BeatmapSetID = int.Parse(value);
            }

            #endregion
            #region Difficulty
            if (difficultyKeyPairs.TryGetValue("HPDrainRate", out value))
            {
                parsedMap.HPDrainRate = float.Parse(value);
            }
            if (difficultyKeyPairs.TryGetValue("CircleSize", out value))
            {
                parsedMap.CircleSize = float.Parse(value);
            }
            if (difficultyKeyPairs.TryGetValue("OverallDifficulty", out value))
            {
                parsedMap.OverallDifficulty = float.Parse(value);
            }
            if (difficultyKeyPairs.TryGetValue("ApproachRate", out value))
            {
                parsedMap.ApproachRate = float.Parse(value);
            }
            if (difficultyKeyPairs.TryGetValue("SliderMultiplier", out value))
            {
                parsedMap.SliderMultiplier = float.Parse(value);
            }
            if (difficultyKeyPairs.TryGetValue("SliderTickRate", out value))
            {
                parsedMap.SliderTickRate = float.Parse(value);
            }
            #endregion
            #region Colours
            parsedMap.Colours = new List <colour>();
            for (int i = 0; i < coloursKeyPairs.Count; i++)
            {
                string[] SplittedRGB = new string[3];
                string   ComboN      = Convert.ToString(i + 1);

                if (coloursKeyPairs.TryGetValue("Combo" + ComboN + " ", out value))
                {
                    SplittedRGB    = value.Split(',');
                    SplittedRGB[0] = SplittedRGB[0].Trim();
                    parsedMap.Colours.Add(new colour(int.Parse(SplittedRGB[0]), int.Parse(SplittedRGB[1]), int.Parse(SplittedRGB[2])));
                }
            }
            #endregion
            //--------------------------------------------------------------
            //Conversion of the values from the raw text file
            #region from raw text
            //Subdivision of the string over sections
            string[] partialBM = rawBeatmap.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            //Recognize where timing points and hit objects are
            int timingIndex = Array.IndexOf(partialBM, "[TimingPoints]");
            int hitIndex    = Array.IndexOf(partialBM, "[HitObjects]");
            //initzialize parsedMap timing point list and notes point list
            parsedMap.TimingPoints = new List <TimingPoint>();
            parsedMap.SingleNotes  = new List <Note>();
            parsedMap.LongNotes    = new List <LongNote>();
            //read the timing points
            for (int i = timingIndex; i < hitIndex; i++)
            {
                TimingPoint parsed = ParseTimingPoint(partialBM[i]);
                if (parsed.Offset != 0)
                {
                    parsedMap.TimingPoints.Add(parsed);
                }
            }
            //read the single notes
            for (int i = hitIndex; i < partialBM.Length; i++)
            {
                Note parsed = ParseSingleNote(partialBM[i]);
                if (parsed.Time != 0)
                {
                    parsedMap.SingleNotes.Add(parsed);
                }
            }
            //read the long notes
            for (int i = hitIndex; i < partialBM.Length; i++)
            {
                LongNote parsed = ParseLongNote(partialBM[i]);
                if (parsed.StartTime != 0)
                {
                    parsedMap.LongNotes.Add(parsed);
                }
            }
            #endregion
            return(parsedMap);
        }