コード例 #1
0
        public void Compile(string script)
        {
            lastError = "0 error(s), you're good to go!";

            try
            {
                ParticleEmitterTokenizer tokenizer = new ParticleEmitterTokenizer();

                Init();

                // parse the character string into tokens.
                tokenizer.Tokenize(script);

                var tokenIter = tokenizer.TokenVector.GetEnumerator();

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenizer.TokenVector.Count < 2)
                {
                    throw new Exception("This script is too small to be valid.");
                }

                // the first three tokens out of the gate should be
                // ParticleSystem, followed by a name and version number, then
                // an open brace.
                if (tokenIter.Current.Type != TokenType.KeywordParticleSystem)
                {
                    throw new Exception("First word must be ParticleSystem");
                }

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.Quote)
                {
                    throw new Exception("Must name particle system");
                }

                name = tokenIter.Current.StringValue.RemoveQuotes();
                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.RealNumber)
                {
                    throw new Exception("Must have version number");
                }

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.OpenBrace)
                {
                    throw new Exception("Missing opening brace for ParticleSystem block");
                }

                ProcessParticleSystemBlock(ref tokenIter);
            }
            catch (Exception ex)
            {
                lastError = ex.Message;
                Init();
                Debug.WriteLine(ex);
            }

            // do misc. processing and calcuations
            pos = posRange.GetRandomNumInRange();
        }