Exemple #1
0
        public List <string> GetCompoundCommandLines(ParsingElement element, int i)
        {
            var lines = element.Lines.GetRange(i, element.Lines.Count - i);

            return(lines.TakeWhile(l => l.TakeWhile(char.IsWhiteSpace).Count() > lines[0].TakeWhile(char.IsWhiteSpace).Count() ||
                                   ReferenceEquals(l, lines[0])).ToList());
        }
Exemple #2
0
        public VisualElement Parse(ParsingElement element)
        {
            try
            {
                VisualElement osbElement = GetOsbElement(element.Lines.FirstOrDefault(), element.LineStart);

                for (int i = 1; i < element.Lines.Count; i++)
                {
                    var values = element.Lines[i].Trim().Split(',');

                    if (IsCompoundCommand(values[0]))
                    {
                        List <string> Lines = GetCompoundCommandLines(element, i);
                        osbElement.Commands = osbElement.Commands.Append(ParseCompoundCommandLine(Lines, element.LineStart, osbElement.InitialPosition));
                        i = i + Lines.Count - 1;
                    }
                    else
                    {
                        osbElement.Commands = osbElement.Commands.Append(ParseCommandLine(element.Lines[i], element.LineStart + i, osbElement.InitialPosition));
                    }
                }

                return(osbElement);
            }
            catch (Exception)
            {
                throw new Exception($"Parsing commands failed for element at line {element.LineStart}");
            }
        }
        private List <ParsingElement> GetParsingElements(IEnumerable <string> content, int lineStart)
        {
            List <ParsingElement> parsingElements = new List <ParsingElement>();
            ParsingElement        parsingElement  = new ParsingElement();

            bool skip = true;

            //<= because it's 1 based for the linenumber, not 0 based for the index
            for (int lineNumber = lineStart; lineNumber <= content.Count(); lineNumber++)
            {
                string line = content.ElementAt(lineNumber - 1);

                //we reached the end of the eventsection
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                //we don't do storyboarded hitsounds (yet)
                if (line.StartsWith("//Storyboard Sound Samples"))
                {
                    break;
                }

                //ignore background and video events and break periods for simplicity's sake (for now)
                if (line.StartsWith("//Storyboard Layer 0 (Background)"))
                {
                    skip = false;
                }

                if (line.StartsWith("//") || line == "[Events]")
                {
                    continue;
                }

                if (!line.StartsWith(' ') && !skip)
                {
                    parsingElement           = new ParsingElement();
                    parsingElement.LineStart = lineNumber + LineOffset;
                    parsingElements.Add(parsingElement);
                }

                parsingElement.Lines.Add(line);
            }
            return(parsingElements);
        }