public static void DumpToStream(Stream stream, RawAffChart chart)
        {
            TextWriter writer = new StreamWriter(stream);

            writer.WriteLine($"AudioOffset:{chart.AudioOffset}");
            writer.WriteLine($"-");
            foreach (var item in chart.items)
            {
                writeItem(writer, item);
            }
            writer.Close();
        }
Exemple #2
0
        public static void DumpToStream(Stream stream, RawAffChart chart)
        {
            TextWriter writer = new StreamWriter(stream);

            writer.WriteLine($"AudioOffset:{chart.AudioOffset}");
            if (chart.TimingPointDensityFactor != 1f)
            {
                writer.WriteLine($"TimingPointDensityFactor:{chart.TimingPointDensityFactor}");
            }
            foreach (var entry in chart.additionalMetadata)
            {
                writer.WriteLine($"{entry.Key}:{entry.Value}");
            }
            writer.WriteLine($"-");
            foreach (var item in chart.items)
            {
                writeItem(writer, item);
            }
            writer.Close();
        }
Exemple #3
0
 public AffTypeChecker(RawAffChart chart, int lineOffset = 0)
 {
     this.lineOffset = lineOffset;
     this.chart      = chart;
 }
Exemple #4
0
 public AffErrorListener(RawAffChart chart, int lineOffset = 0)
 {
     this.lineOffset = lineOffset;
     this.chart      = chart;
 }
Exemple #5
0
        public static RawAffChart ParseFromPath(string path)
        {
            RawAffChart chart = new RawAffChart();

            using (StreamReader reader = new StreamReader(path))
            {
                // manually parse metadata
                int  metadataLinesCount          = 0;
                bool AudioOffsetSet              = false;
                bool TimingPointDensityFactorSet = false;
                while (true)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    metadataLinesCount++;
                    if (line == "-")
                    {
                        break;
                    }
                    int pos = line.IndexOf(":");
                    if (pos < 0)
                    {
                        chart.warning.Add($"第 {metadataLinesCount} 行:{line} 元信息格式错误,此行会被忽略");
                        continue;
                    }
                    string key   = line.Substring(0, pos);
                    string value = line.Substring(pos + 1);
                    if (key == "AudioOffset")
                    {
                        if (AudioOffsetSet)
                        {
                            chart.warning.Add($"第 {metadataLinesCount} 行:AudioOffset 被重复设置为 {value},此行会被忽略");
                        }
                        else
                        {
                            int offset;
                            if (Int32.TryParse(value, out offset))
                            {
                                chart.AudioOffset = offset;
                                AudioOffsetSet    = true;
                            }
                            else
                            {
                                chart.warning.Add($"第 {metadataLinesCount} 行:AudioOffset 的值不是整数,此行会被忽略");
                            }
                        }
                    }
                    else if (key == "TimingPointDensityFactor")
                    {
                        if (TimingPointDensityFactorSet)
                        {
                            chart.warning.Add($"第 {metadataLinesCount} 行:TimingPointDensityFactor 被重复设置为 {value},此行会被忽略");
                        }
                        else
                        {
                            float factor;
                            if (float.TryParse(value, out factor))
                            {
                                if (factor > 0)
                                {
                                    chart.TimingPointDensityFactor = factor;
                                    TimingPointDensityFactorSet    = true;
                                }
                                else
                                {
                                    chart.warning.Add($"第 {metadataLinesCount} 行:TimingPointDensityFactor 的值不是正数,此行会被忽略");
                                }
                            }
                            else
                            {
                                chart.warning.Add($"第 {metadataLinesCount} 行:TimingPointDensityFactor 的值不是浮点数,此行会被忽略");
                            }
                        }
                    }
                    else
                    {
                        if (chart.additionalMetadata.ContainsKey(key))
                        {
                            chart.warning.Add($"第 {metadataLinesCount} 行:{key}被重复设置为{value},此行会被忽略");
                        }
                        else
                        {
                            chart.additionalMetadata.Add(key, value);
                        }
                    }
                }
                ICharStream            stream             = CharStreams.fromTextReader(reader);
                ArcaeaFileFormatLexer  lexer              = new ArcaeaFileFormatLexer(stream);
                AffErrorListener <int> lexerErrorListener = new AffErrorListener <int>(chart, metadataLinesCount);
                lexer.RemoveErrorListeners();
                lexer.AddErrorListener(lexerErrorListener);
                ITokenStream           tokenStream = new CommonTokenStream(lexer);
                ArcaeaFileFormatParser parser      = new ArcaeaFileFormatParser(tokenStream);
                parser.BuildParseTree = true;
                AffErrorListener <IToken> parserErrorListener = new AffErrorListener <IToken>(chart, metadataLinesCount);
                parser.RemoveErrorListeners();
                parser.AddErrorListener(parserErrorListener);
                IParseTree tree = parser.file();
                if (chart.error.Count == 0)
                {
                    ParseTreeWalker.Default.Walk(new AffTypeChecker(chart, metadataLinesCount), tree);
                }
            }
            foreach (string warning in chart.warning)
            {
                Debug.LogWarning(warning);
            }
            foreach (string error in chart.error)
            {
                Debug.LogError(error);
            }
            return(chart);
        }