private bool ParseGlowingFlats() { // Next sould be opening brace if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } // Parse inner blocks while (SkipWhitespace(true)) { string token = ReadToken().ToLowerInvariant(); if (token == "}") { break; // End of Glow structure } switch (token) { case "walls": case "flats": if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } while (SkipWhitespace(true)) { token = StripQuotes(ReadToken(false)); if (string.IsNullOrEmpty(token)) { continue; } if (token == "}") { break; } // Add glow data. Hash the name exactly as given. long flatnamehash = Lump.MakeLongName(token, true); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, Fullbright = true, Color = new PixelColor(255, 255, 255, 255), CalculateTextureColor = true }; } break; case "texture": { PixelColor color = new PixelColor(); int glowheight = DEFAULT_GLOW_HEIGHT; string texturename; if (!ReadTextureName(out texturename)) { return(false); } if (string.IsNullOrEmpty(texturename)) { ReportError("Expected " + token + " name"); return(false); } // Now we should find a comma if (!NextTokenIs(",", false)) { ReportError("Expected a comma"); return(false); } // Next is color SkipWhitespace(true); token = ReadToken(false); if (!GetColorFromString(token, ref color)) { ReportError("Expected glow color value, but got \"" + token + "\""); return(false); } // The glow data is valid at thispoint. Hash the name exactly as given. long texturehash = Lump.MakeLongName(texturename, true); // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Color = color.WithAlpha(255), CalculateTextureColor = false }; continue; } // Can be glow height SkipWhitespace(true); token = ReadToken(); int h; if (int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out h)) { // Can't pass glowheight directly cause TryParse will unconditionally set it to 0 glowheight = h; // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Color = color.WithAlpha(255), CalculateTextureColor = false }; continue; } // Read the flag SkipWhitespace(true); token = ReadToken().ToLowerInvariant(); } // Next must be "fullbright" flag if (token != "fullbright") { ReportError("Expected \"fullbright\" flag, but got \"" + token + "\""); return(false); } // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Fullbright = true, Color = color.WithAlpha(255), CalculateTextureColor = false }; } break; } } // All done here return(true); }
private bool ParseGlowingFlats() { // Next sould be opening brace if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } // Parse inner blocks while (SkipWhitespace(true)) { string token = ReadToken().ToLowerInvariant(); if (token == "}") { break; // End of Glow structure } switch (token) { case "walls": case "flats": if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } while (SkipWhitespace(true)) { token = ReadToken(); if (token == "}") { break; } // Add glow data long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames)); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, Fullbright = true, Color = new PixelColor(255, 255, 255, 255), CalculateTextureColor = true }; } break; case "subwalls": case "subflats": if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } while (SkipWhitespace(true)) { token = ReadToken(); if (token == "}") { break; } // Add glow data long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames)); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, Fullblack = true, Subtractive = true, Color = new PixelColor(255, 0, 0, 0), CalculateTextureColor = false }; } break; case "subtexture": case "texture": { int color; int glowheight = DEFAULT_GLOW_HEIGHT; bool subtractivetexture = (token == "subtexture"); string texturename = StripQuotes(ReadToken(false)); if (string.IsNullOrEmpty(texturename)) { ReportError("expected " + token + " name"); return(false); } // Now we should find a comma if (!NextTokenIs(",", false)) { ReportError("Expected a comma"); return(false); } // Next is color SkipWhitespace(true); token = ReadToken(); if (!int.TryParse(token, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out color)) { //probably it's a color name? Color c = Color.FromName(token); //should be similar to C++ color name detection, I suppose if (c.IsKnownColor) { color = PixelColor.FromColor(c).ToInt(); } else { ReportError("expected glow color value, but got \"" + token + "\""); return(false); } } // The glow data is valid at thispoint. Let's get texture hash long texturehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(texturename, General.Map.Options.UseLongTextureNames)); // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Subtractive = subtractivetexture, Color = PixelColor.FromInt(color).WithAlpha(255), CalculateTextureColor = false }; continue; } // Can be glow height SkipWhitespace(true); token = ReadToken(); int h; if (int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out h)) { // Can't pass glowheight directly cause TryParse will unconditionally set it to 0 glowheight = h; // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Subtractive = subtractivetexture, Color = PixelColor.FromInt(color).WithAlpha(255), CalculateTextureColor = false }; continue; } // Read the flag SkipWhitespace(true); token = ReadToken().ToLowerInvariant(); } // Next is "fullbright" or "fullblack" flag bool fullbright = (token == "fullbright"); bool fullblack = (!subtractivetexture && token == "fullblack"); if (!fullblack && !fullbright) { string expectedflags = (subtractivetexture ? "\"fullbright\"" : "\"fullbright\" or \"fullblack\""); ReportError("expected " + expectedflags + " flag, but got \"" + token + "\""); return(false); } // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Fullbright = fullbright, Fullblack = fullblack, Subtractive = subtractivetexture, Color = PixelColor.FromInt(color).WithAlpha(255), CalculateTextureColor = false }; } break; } } // All done here return(true); }