Beispiel #1
0
        private IEnumerator StartParsing()
        {
            Bms = Parser.Parse(SceneChanger.SongPath == "" ? _path : SceneChanger.SongPath);
            Bms.AddNoteOnMeasure(Bms.Data.TotalBar + 1, 2, "1");
            Bms.AddNoteOnMeasure(Bms.Data.TotalBar + 1, 3, "64");

            yield return(new WaitUntil(() => Bms.Head.WavFileCount == Bms.Head.WavFiles.Count));

            yield return(StartCoroutine(PreProcess()));

            IsDone = true;
        }
Beispiel #2
0
        public static Bms ParseHead(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Debug.LogError($"{filePath} cant Exists while Parsing");
                throw new FileLoadException();
            }

            var bms = new Bms();

            var qData      = File.ReadAllLines(filePath);
            var fileParent = Directory.GetParent(filePath).FullName;

            foreach (var line in qData)
            {
                if (line == "")
                {
                    continue;
                }

                if (SubString(line, "#TITLE"))
                {
                    var length = line.Length - 7;
                    bms.SetTitle(line.Substring(7, length));
                }
                else if (SubString(line, "#ARTIST"))
                {
                    var length = line.Length - 8;
                    bms.SetArtist(line.Substring(8, length));
                }
                else if (SubString(line, "#STAGEFILE"))
                {
                    var length = line.Length - 11;
                    bms.SetStageFile(fileParent + '/' + line.Substring(11, length));
                }
                else if (SubString(line, "#BANNER"))
                {
                    var length = line.Length - 8;
                    bms.SetBanner(fileParent + '/' + line.Substring(8, length));
                }

                if (line == "*---------------------- MAIN DATA FIELD")
                {
                    break;
                }
            }

            return(bms);
        }
Beispiel #3
0
        public static bool DiscriminationKey(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Debug.LogError($"{filePath} cant Exists while Parsing");
                throw new FileLoadException();
            }

            var bms = new Bms();

            var qData      = File.ReadAllLines(filePath);
            var fileParent = Directory.GetParent(filePath).FullName;
            var inMainData = false;

            foreach (var line in qData)
            {
                if (line == "")
                {
                    continue;
                }
                if (line == "*---------------------- MAIN DATA FIELD")
                {
                    inMainData = true;
                }
                if (!inMainData)
                {
                    continue;
                }

                if (!SubString(line, "#"))
                {
                    continue;
                }
                //#00101 aabbccdd length 15 9
                var channel = (Bms.DataSection.EventChannel) int.Parse(line.Substring(4, 2));

                if (channel == Bms.DataSection.EventChannel.P1SideKey7 ||
                    channel == Bms.DataSection.EventChannel.P1SideKey6 ||
                    channel == Bms.DataSection.EventChannel.P1SideLongNote6 ||
                    channel == Bms.DataSection.EventChannel.P1SideLongNote7)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        public static Bms Parse(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Debug.LogError($"{filePath} cant Exists while Parsing");
                throw new FileLoadException();
            }

            var bms = new Bms();

            var qData       = File.ReadAllLines(filePath);
            var headerField = true;
            var fileParent  = Directory.GetParent(filePath).FullName;
            var randomNum   = -1;
            var startIf     = false;
            var inIf        = false;

            foreach (var line in qData)
            {
                if (line == "")
                {
                    continue;
                }

                if (headerField)
                {
                    if (SubString(line, "#PLAYER"))
                    {
                        var length = line.Length - 8;
                        bms.SetPlayer(int.Parse(line.Substring(8, length)));
                    }
                    else if (SubString(line, "#GENRE"))
                    {
                        var length = line.Length - 7;
                        bms.SetGenre(line.Substring(7, length));
                    }
                    else if (SubString(line, "#TITLE"))
                    {
                        var length = line.Length - 7;
                        bms.SetTitle(line.Substring(7, length));
                    }
                    else if (SubString(line, "#ARTIST"))
                    {
                        var length = line.Length - 8;
                        bms.SetArtist(line.Substring(8, length));
                    }
                    else if (SubString(line, "#BPM "))
                    {
                        var length = line.Length - 5;
                        bms.SetBpm(int.Parse(line.Substring(5, length)));
                    }
                    else if (SubString(line, "#PLAYLEVEL"))
                    {
                        var length = line.Length - 11;
                        bms.SetPlayLevel(int.Parse(line.Substring(11, length)));
                    }
                    else if (SubString(line, "#RANK"))
                    {
                        var length = line.Length - 6;
                        bms.SetRank(int.Parse(line.Substring(6, length)));
                    }
                    else if (SubString(line, "#TOTAL"))
                    {
                        var length = line.Length - 7;
                        bms.SetTotal(int.Parse(line.Substring(7, length)));
                    }
                    else if (SubString(line, "#VOLWAV"))
                    {
                        var length = line.Length - 8;
                        bms.SetVolumeWav(int.Parse(line.Substring(8, length)));
                    }
                    else if (SubString(line, "#STAGEFILE"))
                    {
                        var length = line.Length - 11;
                        bms.SetStageFile(fileParent + '/' + line.Substring(11, length));
                    }
                    else if (SubString(line, "#WAV"))
                    {
                        var strNum = line.Substring(4, 2);

                        var length   = line.Length - 7 - 4; // 확장자 제거를 위하여 -4
                        var fileName = line.Substring(7, length);
                        bms.Head.WavFileCount++;

                        BMSCapacity.Instance.StartCoroutine(
                            bms.AddWavFIle($@"{fileParent}\", $"{fileName}", strNum));
                    }
                    else if (SubString(line, "#BMP"))
                    {
                        var strNum = line.Substring(4, 2);

                        var length   = line.Length - 7;
                        var fileName = line.Substring(7, length);
                        bms.AddBmpFile($@"{fileParent}\", $"{fileName}", strNum);
                    }
                    else if (SubString(line, "#STOP"))
                    {
                        var strNum = line.Substring(5, 2);

                        var length  = line.Length - 8;
                        var strData = line.Substring(8, length);
                        bms.AddStopCommand(strNum, strData);
                    }
                    else if (SubString(line, "#BPM"))
                    {
                        var strNum = line.Substring(4, 2);

                        var length  = line.Length - 7;
                        var strData = line.Substring(7, length);
                        bms.AddBpmCommand(strNum, strData);
                    }
                    else if (SubString(line, "#LNTYPE"))
                    {
                        bms.SetLongNoteType(line.Substring(8, 1));
                    }
                    else if (SubString(line, "#LNOBJ"))
                    {
                        bms.SetLongNoteType("LNOBJ");
                        bms.AddLongNote(line.Substring(7, 2));
                    }
                    else if (SubString(line, "#random"))
                    {
                        var num = int.Parse(line.Substring(8, 1));

                        randomNum = Random.Range(1, num);
                    }
                    else if (SubString(line, "#if"))
                    {
                        var num = int.Parse(line.Substring(4, line.Length - 4));
                        startIf = true;

                        inIf = num == randomNum;
                    }
                    else if (startIf && !inIf && SubString(line, "#else"))
                    {
                        inIf = true;
                    }
                    else if (SubString(line, "#endif"))
                    {
                        inIf = startIf = false;
                    }
                    else if (inIf)
                    {
                        if (!SubString(line, "#"))
                        {
                            continue;
                        }
                        //#00101 aabbccdd length 15 9
                        var measure = int.Parse(line.Substring(1, 3));
                        var channel = int.Parse(line.Substring(4, 2));
                        bms.AddNoteOnMeasure(measure, channel, line.Substring(7, line.Length - 7));
                    }

                    if (line == "*---------------------- MAIN DATA FIELD")
                    {
                        headerField = false;
                    }
                }
                else
                {
                    if (!SubString(line, "#"))
                    {
                        continue;
                    }
                    //#00101 aabbccdd length 15 9
                    var measure = int.Parse(line.Substring(1, 3));
                    var channel = int.Parse(line.Substring(4, 2));
                    bms.AddNoteOnMeasure(measure, channel, line.Substring(7, line.Length - 7));
                }
            }

            return(bms);
        }