Exemplo n.º 1
0
        // Constructor
        internal TextureStructure(TexturesParser parser, string typename)
        {
            string tokenstr;

            // Initialize
            this.typename = typename;
            patches       = new List <PatchStructure>(4);
            xscale        = 0.0f;
            yscale        = 0.0f;

            // There should be 3 tokens separated by 2 commas now:
            // Name, Width, Height

            // First token is the class name
            parser.SkipWhitespace(true);
            name = parser.StripTokenQuotes(parser.ReadToken());
            if (string.IsNullOrEmpty(name))
            {
                parser.ReportError("Expected texture or sprite name");
                return;
            }

            // Now we should find a comma
            parser.SkipWhitespace(true);
            tokenstr = parser.ReadToken();
            if (tokenstr != ",")
            {
                parser.ReportError("Expected a comma");
                return;
            }

            // Next is the texture width
            parser.SkipWhitespace(true);
            tokenstr = parser.ReadToken();
            if (string.IsNullOrEmpty(tokenstr) || !int.TryParse(tokenstr, NumberStyles.Integer, CultureInfo.InvariantCulture, out width))
            {
                parser.ReportError("Expected width in pixels");
                return;
            }

            // Now we should find a comma again
            parser.SkipWhitespace(true);
            tokenstr = parser.ReadToken();
            if (tokenstr != ",")
            {
                parser.ReportError("Expected a comma");
                return;
            }

            // Next is the texture height
            parser.SkipWhitespace(true);
            tokenstr = parser.ReadToken();
            if (string.IsNullOrEmpty(tokenstr) || !int.TryParse(tokenstr, NumberStyles.Integer, CultureInfo.InvariantCulture, out height))
            {
                parser.ReportError("Expected height in pixels");
                return;
            }

            // Next token should be the beginning of the texture scope
            parser.SkipWhitespace(true);
            tokenstr = parser.ReadToken();
            if (tokenstr != "{")
            {
                parser.ReportError("Expected begin of structure");
                return;
            }

            // Now parse the contents of texture structure
            while (parser.SkipWhitespace(true))
            {
                string token = parser.ReadToken();
                token = token.ToLowerInvariant();
                if (token == "xscale")
                {
                    if (!ReadTokenFloat(parser, token, out xscale))
                    {
                        return;
                    }
                }
                else if (token == "yscale")
                {
                    if (!ReadTokenFloat(parser, token, out yscale))
                    {
                        return;
                    }
                }
                else if (token == "worldpanning")
                {
                    worldpanning = true;
                }
                else if (token == "offset")
                {
                    // Read x offset
                    if (!ReadTokenInt(parser, token, out xoffset))
                    {
                        return;
                    }

                    // Now we should find a comma
                    parser.SkipWhitespace(true);
                    tokenstr = parser.ReadToken();
                    if (tokenstr != ",")
                    {
                        parser.ReportError("Expected a comma");
                        return;
                    }

                    // Read y offset
                    if (!ReadTokenInt(parser, token, out yoffset))
                    {
                        return;
                    }
                }
                else if (token == "patch")
                {
                    // Read patch structure
                    PatchStructure pt = new PatchStructure(parser);
                    if (parser.HasError)
                    {
                        break;
                    }

                    // Add the patch
                    patches.Add(pt);
                }
                else if (token == "}")
                {
                    // Actor scope ends here,
                    // break out of this parse loop
                    break;
                }
            }
        }
Exemplo n.º 2
0
        // Constructor
        internal TextureStructure(TexturesParser parser, string typename, string virtualpath)
        {
            // Initialize
            this.typename    = typename;
            this.virtualpath = virtualpath;
            patches          = new List <PatchStructure>(4);
            xscale           = 0.0f;
            yscale           = 0.0f;

            // There should be 3 tokens separated by 2 commas now:
            // Name, Width, Height

            // First token is the texture name
            parser.SkipWhitespace(true);
            name = parser.StripTokenQuotes(parser.ReadToken(false));             //mxd. Don't skip newline

            //mxd. It can also be "optional" keyword.
            if (name.ToLowerInvariant() == "optional")
            {
                optional = true;
                parser.SkipWhitespace(true);
                name = parser.StripTokenQuotes(parser.ReadToken(false));                 //mxd. Don't skip newline
            }

            if (string.IsNullOrEmpty(name))
            {
                parser.ReportError("Expected " + typename + " name");
                return;
            }

            // Now we should find a comma
            if (!parser.NextTokenIs(","))
            {
                return;                                      //mxd
            }
            // Next is the texture width
            parser.SkipWhitespace(true);
            string tokenstr = parser.ReadToken();

            if (string.IsNullOrEmpty(tokenstr) || !int.TryParse(tokenstr, NumberStyles.Integer, CultureInfo.InvariantCulture, out width))
            {
                parser.ReportError("Expected width in pixels");
                return;
            }

            // Now we should find a comma again
            if (!parser.NextTokenIs(","))
            {
                return;                                      //mxd
            }
            // Next is the texture height
            parser.SkipWhitespace(true);
            tokenstr = parser.ReadToken();
            if (string.IsNullOrEmpty(tokenstr) || !int.TryParse(tokenstr, NumberStyles.Integer, CultureInfo.InvariantCulture, out height))
            {
                parser.ReportError("Expected height in pixels");
                return;
            }

            // Next token should be the beginning of the texture scope
            if (!parser.NextTokenIs("{", false))            //mxd
            {
                parser.ReportError("Expected begin of structure");
                return;
            }

            // Now parse the contents of texture structure
            bool done = false;             //mxd

            while (!done && parser.SkipWhitespace(true))
            {
                string token = parser.ReadToken();
                token = token.ToLowerInvariant();

                switch (token)
                {
                case "xscale":
                    if (!ReadTokenFloat(parser, token, out xscale))
                    {
                        return;
                    }
                    break;

                case "yscale":
                    if (!ReadTokenFloat(parser, token, out yscale))
                    {
                        return;
                    }
                    break;

                case "worldpanning":
                    worldpanning = true;
                    break;

                case "nulltexture":                         //mxd
                    nulltexture = true;
                    break;

                case "offset":
                    // Read x offset
                    if (!ReadTokenInt(parser, token, out xoffset))
                    {
                        return;
                    }

                    // Now we should find a comma
                    if (!parser.NextTokenIs(","))
                    {
                        return;                                                      //mxd
                    }
                    // Read y offset
                    if (!ReadTokenInt(parser, token, out yoffset))
                    {
                        return;
                    }
                    break;

                case "patch":
                    // Read patch structure
                    PatchStructure pt = new PatchStructure(parser);
                    if (parser.HasError)
                    {
                        break;
                    }

                    // Add the patch
                    patches.Add(pt);
                    break;

                case "}":
                    // Actor scope ends here,
                    // break out of this parse loop
                    done = true;
                    break;
                }
            }
        }