示例#1
0
        /// <summary>
        ///     使用一定的格式构造一个字符串
        /// </summary>
        /// <param name="format"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            var b = new StringBuilder(format);

            b.Replace("Artist", Artist);
            b.Replace("artist", Artist);
            b.Replace("bpm", Bpm.ToString(CultureInfo.CurrentCulture));
            b.Replace("stars", Stars.ToString(CultureInfo.CurrentCulture));
            b.Replace("mode", Mode.ToString());
            b.Replace("cs", CircleSize.ToString(CultureInfo.CurrentCulture));
            b.Replace("ar", ApproachRate.ToString(CultureInfo.CurrentCulture));
            b.Replace("hp", HpDrain.ToString(CultureInfo.CurrentCulture));
            b.Replace("od", OverallDifficulty.ToString(CultureInfo.CurrentCulture));
            b.Replace("circles", HitCircle.ToString());
            b.Replace("sliders", Slider.ToString());
            b.Replace("spiners", Spinner.ToString());
            b.Replace("creator", Creator);
            b.Replace("Title", Title);
            b.Replace("title", Title);
            b.Replace("Tags", Tags);
            b.Replace("tags", Tags);
            b.Replace("setid", BeatmapSetId.ToString());
            b.Replace("maxcombo", MaxCombo.ToString());
            b.Replace("approved", Approved.ToString());
            var total = TimeSpan.FromSeconds(TotalTime);
            var hit   = TimeSpan.FromSeconds(DrainTime);

            b.Replace("length", $"{total.TotalMinutes}:{total.Seconds}");
            b.Replace("hitlength", $"{hit.TotalMinutes}:{hit.Seconds}");
            b.Replace("version", Version);
            b.Replace("md5", Md5);
            b.Replace("id", BeatmapId.ToString());
            return(b.ToString());
        }
示例#2
0
 private void CalcBPM()
 {
     updateTimer  = updateRate;
     Bpm          = (int)(uniqBeats.Count / waitingNewTimer * 60 + Bpm) / 2;
     BPMText.text = Bpm.ToString();
     OnBPMUpdate?.Invoke(Bpm, OldBpm);
     OldBpm = Bpm;
 }
示例#3
0
        private void UpdateHR(JObject json)
        {
            if (json["payload"] != null && json["payload"]["hr"] != null)
            {
                Bpm.Bpm        = json["payload"]["hr"].ToObject <int>();
                Bpm.ReceivedAt = DateTime.Now.ToString("HH:mm:ss");
            }

            if (_logHr)
            {
                logger.Info(Bpm.ToString());
            }
        }
示例#4
0
        private IEnumerator UpdateHR()
        {
            using (var webRequest = UnityWebRequest.Get(_url))
            {
                // Request and wait for the desired page.
                yield return(webRequest.SendWebRequest());

                if (webRequest.isNetworkError)
                {
                    logger.Error($"Error Requesting HR data: {webRequest.error}");
                    throw new WebException();
                }

                if (_regex.IsMatch(webRequest.downloadHandler.text))
                {
                    Bpm.Bpm        = int.Parse(webRequest.downloadHandler.text);
                    Bpm.ReceivedAt = System.DateTime.Now.ToString("HH:mm:ss");
                }
                else
                {
                    // pulsoid: {"bpm":0,"measured_at":"2021-06-21T01:34:39.320Z"}
                    try
                    {
                        var json = JObject.Parse(webRequest.downloadHandler.text);
                        if (json["bpm"] != null)
                        {
                            Bpm.Bpm = json["bpm"].ToObject <int>();
                        }
                        else
                        {
                            logger.Warn("Json received does not contain necessary field");
                            logger.Warn(webRequest.downloadHandler.text);
                        }

                        Bpm.ReceivedAt = json["measured_at"] != null ? json["measured_at"].ToObject <string>() : Bpm.ReceivedAt = System.DateTime.Now.ToString("HH:mm:ss");
                    }
                    catch (JsonReaderException)
                    {
                        logger.Critical("Invalid json received.");
                        logger.Critical(webRequest.downloadHandler.text);
                    }
                }

                if (_logHr)
                {
                    logger.Info(Bpm.ToString());
                }
            }
        }
示例#5
0
        private void HandleData(string data)
        {
#if DEBUG
            logger.Debug(data);
#endif

            try
            {
                var json = JObject.Parse(data);
                if (json["actionType"]?.ToString() != "OverlayUpdate")
                {
                    return;
                }

                if (json["jsonData"] == null)
                {
                    return;
                }

                var osu = JObject.Parse(json["jsonData"]?.ToString());

#if DEBUG
                logger.Debug(osu.ToString());
#endif

                var hrToken = osu["status"]?["heartRate"]?.Type != JTokenType.Null
                    ? osu["status"]?["heartRate"]
                    : osu["status"]?["calculationMetrics"]?["estHeartRate"];

                var hr = hrToken?.ToObject <int>() ?? 0;

                // Console.WriteLine($"HR {hr}");
                Bpm.Bpm        = hr;
                Bpm.ReceivedAt = DateTimeOffset.Now.ToUnixTimeSeconds().ToString();
                if (_logHr)
                {
                    logger.Info(Bpm.ToString());
                }
            }
            catch (Exception e)
            {
                logger.Warn("Exception occured while parsing hr data");
                logger.Warn(e.Message);
                logger.Debug(e);
            }
        }
        /// <summary>
        ///     输出为BangCraft谱面工程格式
        /// </summary>
        /// <returns></returns>
        private string ToBangCraftScore()
        {
            var xml  = new XmlDocument();
            var Save = xml.CreateElement("Save");

            Save.SetAttribute("name", "BGCdate");
            xml.AppendChild(Save);

            var info = xml.CreateElement("info");

            Save.AppendChild(info);

            var music = xml.CreateElement("music");

            music.InnerText = "test";
            info.AppendChild(music);

            var bpm = xml.CreateElement("bpm");

            bpm.InnerText = Bpm.ToString();
            info.AppendChild(bpm);

            var delay = xml.CreateElement("delay");

            delay.InnerText = Delay_ms.ToString();
            info.AppendChild(delay);

            var bpmP1 = xml.CreateElement("bpmP1");

            bpmP1.InnerText = "";
            info.AppendChild(bpmP1);

            var bpmD1 = xml.CreateElement("bpmD1");

            bpmD1.InnerText = "0";
            info.AppendChild(bpmD1);

            var bpmP2 = xml.CreateElement("bpmP2");

            bpmP2.InnerText = "";
            info.AppendChild(bpmP2);

            var bpmD2 = xml.CreateElement("bpmD2");

            bpmD2.InnerText = "0";
            info.AppendChild(bpmD2);

            var bpmP3 = xml.CreateElement("bpmP3");

            bpmP3.InnerText = "";
            info.AppendChild(bpmP3);

            var bpmD3 = xml.CreateElement("bpmD3");

            bpmD3.InnerText = "0";
            info.AppendChild(bpmD3);

            foreach (var note in Notes)
            {
                //N
                if (note.NoteType == NoteType.白键 || note.NoteType == NoteType.技能)
                {
                    var noteN = xml.CreateElement("noteN");
                    Save.AppendChild(noteN);

                    var lineN = xml.CreateElement("lineN");
                    lineN.InnerText = (note.Track - 4).ToString();
                    noteN.AppendChild(lineN);

                    var posN = xml.CreateElement("posN");
                    posN.InnerText = (note.Time * 2).ToString();
                    noteN.AppendChild(posN);

                    var typeN = xml.CreateElement("typeN");
                    typeN.InnerText = "N";
                    noteN.AppendChild(typeN);
                }
            }

            foreach (var note in Notes)
            {
                //F
                if (note.NoteType == NoteType.粉键)
                {
                    var noteF = xml.CreateElement("noteF");
                    Save.AppendChild(noteF);

                    var lineF = xml.CreateElement("lineF");
                    lineF.InnerText = (note.Track - 4).ToString();
                    noteF.AppendChild(lineF);

                    var posF = xml.CreateElement("posF");
                    posF.InnerText = (note.Time * 2).ToString();
                    noteF.AppendChild(posF);

                    var typeF = xml.CreateElement("typeF");
                    typeF.InnerText = "F";
                    noteF.AppendChild(typeF);
                }
            }

            var index = 0;

            foreach (var note in Notes)
            {
                //LS
                if (note.NoteType == NoteType.滑条a_开始)
                {
                    var noteL = xml.CreateElement("noteL");
                    Save.AppendChild(noteL);

                    var lineL = xml.CreateElement("lineL");
                    lineL.InnerText = (note.Track - 4).ToString();
                    noteL.AppendChild(lineL);

                    var posL = xml.CreateElement("posL");
                    posL.InnerText = (note.Time * 2).ToString();
                    noteL.AppendChild(posL);

                    var typeL = xml.CreateElement("typeL");
                    typeL.InnerText = "LS";
                    noteL.AppendChild(typeL);

                    var startlineL = xml.CreateElement("startlineL");
                    startlineL.InnerText = (note.Track - 4).ToString();
                    noteL.AppendChild(startlineL);

                    var startposL = xml.CreateElement("startposL");
                    startposL.InnerText = (note.Time * 2).ToString();
                    noteL.AppendChild(startposL);

                    for (var i = index + 1; i < Notes.Count; i++)
                    {
                        if (Notes[i].NoteType == NoteType.滑条a_中间 && Notes[i].Time != note.Time)
                        {
                            var noteM = xml.CreateElement("noteL");
                            Save.AppendChild(noteM);

                            var lineM = xml.CreateElement("lineL");
                            lineM.InnerText = (Notes[i].Track - 4).ToString();
                            noteM.AppendChild(lineM);

                            var posM = xml.CreateElement("posL");
                            posM.InnerText = (Notes[i].Time * 2).ToString();
                            noteM.AppendChild(posM);

                            var typeM = xml.CreateElement("typeL");
                            typeM.InnerText = "LM";
                            noteM.AppendChild(typeM);

                            noteM.AppendChild(startlineL.Clone());

                            noteM.AppendChild(startposL.Clone());
                            continue;
                        }

                        if ((Notes[i].NoteType == NoteType.滑条a_结束 ||
                             Notes[i].NoteType == NoteType.滑条a_粉键结束) && Notes[i].Time != note.Time)
                        {
                            var noteE = xml.CreateElement("noteL");
                            Save.AppendChild(noteE);

                            var lineE = xml.CreateElement("lineL");
                            lineE.InnerText = (Notes[i].Track - 4).ToString();
                            noteE.AppendChild(lineE);

                            var posE = xml.CreateElement("posL");
                            posE.InnerText = (Notes[i].Time * 2).ToString();
                            noteE.AppendChild(posE);

                            var typeE = xml.CreateElement("typeL");
                            typeE.InnerText = Notes[i].NoteType == NoteType.滑条a_结束 ? "LE" : "LF";
                            noteE.AppendChild(typeE);

                            noteE.AppendChild(startlineL.Clone());

                            noteE.AppendChild(startposL.Clone());
                            break;
                        }
                    }
                }

                if (note.NoteType == NoteType.滑条b_开始)
                {
                    var noteL = xml.CreateElement("noteL");
                    Save.AppendChild(noteL);

                    var lineL = xml.CreateElement("lineL");
                    lineL.InnerText = (note.Track - 4).ToString();
                    noteL.AppendChild(lineL);

                    var posL = xml.CreateElement("posL");
                    posL.InnerText = (note.Time * 2).ToString();
                    noteL.AppendChild(posL);

                    var typeL = xml.CreateElement("typeL");
                    typeL.InnerText = "LS";
                    noteL.AppendChild(typeL);

                    var startlineL = xml.CreateElement("startlineL");
                    startlineL.InnerText = (note.Track - 4).ToString();
                    noteL.AppendChild(startlineL);

                    var startposL = xml.CreateElement("startposL");
                    startposL.InnerText = (note.Time * 2).ToString();
                    noteL.AppendChild(startposL);

                    for (var i = index + 1; i < Notes.Count; i++)
                    {
                        if (Notes[i].NoteType == NoteType.滑条b_中间 && Notes[i].Time != note.Time)
                        {
                            var noteM = xml.CreateElement("noteL");
                            Save.AppendChild(noteM);

                            var lineM = xml.CreateElement("lineL");
                            lineM.InnerText = (Notes[i].Track - 4).ToString();
                            noteM.AppendChild(lineM);

                            var posM = xml.CreateElement("posL");
                            posM.InnerText = (Notes[i].Time * 2).ToString();
                            noteM.AppendChild(posM);

                            var typeM = xml.CreateElement("typeL");
                            typeM.InnerText = "LM";
                            noteM.AppendChild(typeM);

                            noteM.AppendChild(startlineL.Clone());

                            noteM.AppendChild(startposL.Clone());
                            continue;
                        }

                        if ((Notes[i].NoteType == NoteType.滑条b_结束 ||
                             Notes[i].NoteType == NoteType.滑条b_粉键结束) && Notes[i].Time != note.Time)
                        {
                            var noteE = xml.CreateElement("noteL");
                            Save.AppendChild(noteE);

                            var lineE = xml.CreateElement("lineL");
                            lineE.InnerText = (Notes[i].Track - 4).ToString();
                            noteE.AppendChild(lineE);

                            var posE = xml.CreateElement("posL");
                            posE.InnerText = (Notes[i].Time * 2).ToString();
                            noteE.AppendChild(posE);

                            var typeE = xml.CreateElement("typeL");
                            typeE.InnerText = Notes[i].NoteType == NoteType.滑条b_结束 ? "LE" : "LF";
                            noteE.AppendChild(typeE);

                            noteE.AppendChild(startlineL.Clone());

                            noteE.AppendChild(startposL.Clone());
                            break;
                        }
                    }
                }

                if (note.NoteType == NoteType.长键_开始)
                {
                    var noteL = xml.CreateElement("noteL");
                    Save.AppendChild(noteL);

                    var lineL = xml.CreateElement("lineL");
                    lineL.InnerText = (note.Track - 4).ToString();
                    noteL.AppendChild(lineL);

                    var posL = xml.CreateElement("posL");
                    posL.InnerText = (note.Time * 2).ToString();
                    noteL.AppendChild(posL);

                    var typeL = xml.CreateElement("typeL");
                    typeL.InnerText = "LS";
                    noteL.AppendChild(typeL);

                    var startlineL = xml.CreateElement("startlineL");
                    startlineL.InnerText = (note.Track - 4).ToString();
                    noteL.AppendChild(startlineL);

                    var startposL = xml.CreateElement("startposL");
                    startposL.InnerText = (note.Time * 2).ToString();
                    noteL.AppendChild(startposL);

                    for (var i = index + 1; i < Notes.Count; i++)
                    {
                        if ((Notes[i].NoteType == NoteType.长键_结束 ||
                             Notes[i].NoteType == NoteType.长键_粉键结束) && Notes[i].Time != note.Time &&
                            Notes[i].Track == note.Track)
                        {
                            var noteE = xml.CreateElement("noteL");
                            Save.AppendChild(noteE);

                            var lineE = xml.CreateElement("lineL");
                            lineE.InnerText = (Notes[i].Track - 4).ToString();
                            noteE.AppendChild(lineE);

                            var posE = xml.CreateElement("posL");
                            posE.InnerText = (Notes[i].Time * 2).ToString();
                            noteE.AppendChild(posE);

                            var typeE = xml.CreateElement("typeL");
                            typeE.InnerText = Notes[i].NoteType == NoteType.长键_结束 ? "LE" : "LF";
                            noteE.AppendChild(typeE);

                            noteE.AppendChild(startlineL.Clone());

                            noteE.AppendChild(startposL.Clone());
                            break;
                        }
                    }
                }

                index++;
            }

            var result = Helper.ConvertXmlDocumentTostring(xml);

            return(result);
        }