Beispiel #1
0
        public LuaRoutine(ScripterRoutine routine)
        {
            Name          = routine.Name;
            _switch       = new LuaIf();
            _currentScope = new LuaIfScope
            {
                Condition = $"STATE == {GetNextStateIdx()}",
            };
            Lines.Add(_switch);
            _switch.Scopes.Add(_currentScope);

            // All routine commands are in states
            for (var i = 0; i < routine.Lines.Count; i++)
            {
                var line = routine.Lines[i];
                TranslateLine(line, i);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Parses a header. Sets parser state accordingly.
        /// </summary>
        /// <remarks>
        /// A header is in the following format
        /// [headerName, param1, param2, ...]
        ///
        /// So for example
        /// [objects]
        ///
        /// Or more complex
        /// [routine,_Routine1,1,true]
        /// </remarks>
        /// <param name="line">The header line</param>
        private void ParseHeaders(string line)
        {
            _currentHeading = line
                              .Trim('[', ']')
                              .Split(',')
                              .Select(x => x.Trim())
                              .ToArray();

            Validate("A heading must have at least one value in it",
                     () => _currentHeading.Length > 0);

            _state = _currentHeading[0] switch
            {
                "objects" => ParserState.Objects,
                "positions" => ParserState.Positions,
                "variables" => ParserState.Variables,
                "text" => ParserState.Text,
                "routine" => ParserState.Routines,
                _ => ParserState.Invalid
            };

            Validate($"Current heading produced invalid state {line}",
                     () => _state != ParserState.Invalid);

            // Check if we are a new routine, if so populate current routine
            if (_state == ParserState.Routines)
            {
                if (_currentRoutine != null)
                {
                    _currentRoutine.EndLineNumber = _lineNo - 1;
                }

                // Routine is in format [routine,ROUTINE_NAME,1,ACTIVE_ON_START]
                _currentRoutine = new ScripterRoutine
                {
                    Name = _currentHeading[1],
                    GlobalRoutineSpeed    = int.Parse(_currentHeading[2]),
                    GlobalRoutinePriority = bool.Parse(_currentHeading[3]),
                    LineNumber            = _lineNo,
                };
                Routines.Add(_currentRoutine);
            }
        }