// Constructor internal StateStructure(DecorateParser parser, string statename) { string lasttoken = ""; firstsprite = null; // Skip whitespace while (parser.SkipWhitespace(true)) { // Read first token string token = parser.ReadToken(); token = token.ToLowerInvariant(); // One of the flow control statements? if ((token == "loop") || (token == "stop") || (token == "wait") || (token == "fail")) { // Ignore flow control } // Label? else if (token == ":") { // Rewind so that this label can be read again parser.DataStream.Seek(-(lasttoken.Length + 1), SeekOrigin.Current); // Done here return; } // End of scope? else if (token == "}") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Done here return; } else { // First part of the sprite name if (token == null) { parser.ReportError("Unexpected end of structure"); return; } // Frames of the sprite name parser.SkipWhitespace(true); string spriteframes = parser.ReadToken(); if (spriteframes == null) { parser.ReportError("Unexpected end of structure"); return; } // Label? else if (spriteframes == ":") { // Rewind so that this label can be read again parser.DataStream.Seek(-(token.Length + 1), SeekOrigin.Current); // Done here return; } // No first sprite yet? if ((firstsprite == null) && (spriteframes.Length > 0)) { // Make the sprite name firstsprite = token + spriteframes[0]; firstsprite = firstsprite.ToUpperInvariant(); // Ignore some odd ZDoom thing if (IGNORE_SPRITE.StartsWith(firstsprite)) { firstsprite = null; } } // Continue until the end of the line string t = ""; while ((t != "\n") && (t != null)) { parser.SkipWhitespace(false); t = parser.ReadToken(); } } lasttoken = token; } }
} //mxd #endregion #region ================== Constructor / Disposer // Constructor internal ActorStructure(DecorateParser parser, DecorateCategoryInfo catinfo) { // Initialize this.catinfo = catinfo; //mxd flags = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase); props = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); states = new Dictionary <string, StateStructure>(StringComparer.OrdinalIgnoreCase); uservars = new Dictionary <string, UniversalType>(StringComparer.OrdinalIgnoreCase); //mxd bool done = false; //mxd // Always define a game property, but default to 0 values props["game"] = new List <string>(); inheritclass = "actor"; replaceclass = null; baseclass = null; skipsuper = false; // First next token is the class name parser.SkipWhitespace(true); classname = parser.StripTokenQuotes(parser.ReadToken(ACTOR_CLASS_SPECIAL_TOKENS)); if (string.IsNullOrEmpty(classname)) { parser.ReportError("Expected actor class name"); return; } //mxd. Fail on duplicates if (parser.ActorsByClass.ContainsKey(classname.ToLowerInvariant())) { parser.ReportError("Actor \"" + classname + "\" is double-defined"); return; } // Parse tokens before entering the actor scope while (parser.SkipWhitespace(true)) { string token = parser.ReadToken(); if (!string.IsNullOrEmpty(token)) { token = token.ToLowerInvariant(); switch (token) { case ":": // The next token must be the class to inherit from parser.SkipWhitespace(true); inheritclass = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(inheritclass)) { parser.ReportError("Expected class name to inherit from"); return; } // Find the actor to inherit from baseclass = parser.GetArchivedActorByName(inheritclass); break; case "replaces": // The next token must be the class to replace parser.SkipWhitespace(true); replaceclass = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(replaceclass)) { parser.ReportError("Expected class name to replace"); return; } break; case "native": // Igore this token break; case "{": // Actor scope begins here, // break out of this parse loop done = true; break; case "-": // This could be a negative doomednum (but our parser sees the - as separate token) // So read whatever is after this token and ignore it (negative doomednum indicates no doomednum) parser.ReadToken(); break; default: //mxd. Property begins with $? Then the whole line is a single value if (token.StartsWith("$")) { // This is for editor-only properties such as $sprite and $category props[token] = new List <string> { (parser.SkipWhitespace(false) ? parser.ReadLine() : "") }; continue; } if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out doomednum)) // Check if numeric { // Not numeric! parser.ReportError("Expected editor number or start of actor scope while parsing \"" + classname + "\""); return; } //mxd. Range check if ((doomednum < General.Map.FormatInterface.MinThingType) || (doomednum > General.Map.FormatInterface.MaxThingType)) { // Out of bounds! parser.ReportError("Actor \"" + classname + "\" has invalid editor number. Editor number must be between " + General.Map.FormatInterface.MinThingType + " and " + General.Map.FormatInterface.MaxThingType); return; } break; } if (done) { break; //mxd } } else { parser.ReportError("Unexpected end of structure"); return; } } // Now parse the contents of actor structure string previoustoken = ""; done = false; //mxd while (parser.SkipWhitespace(true)) { string token = parser.ReadToken(); token = token.ToLowerInvariant(); switch (token) { case "+": case "-": // Next token is a flag (option) to set or remove bool flagvalue = (token == "+"); parser.SkipWhitespace(true); string flagname = parser.ReadToken(); if (!string.IsNullOrEmpty(flagname)) { // Add the flag with its value flagname = flagname.ToLowerInvariant(); flags[flagname] = flagvalue; } else { parser.ReportError("Expected flag name"); return; } break; case "action": case "native": // We don't need this, ignore up to the first next ; while (parser.SkipWhitespace(true)) { string t = parser.ReadToken(); if (string.IsNullOrEmpty(t) || t == ";") { break; } } break; case "skip_super": skipsuper = true; break; case "states": // Now parse actor states until we reach the end of the states structure while (parser.SkipWhitespace(true)) { string statetoken = parser.ReadToken(); if (!string.IsNullOrEmpty(statetoken)) { // Start of scope? if (statetoken == "{") { // This is fine } // End of scope? else if (statetoken == "}") { // Done with the states, // break out of this parse loop break; } // State label? else if (statetoken == ":") { if (!string.IsNullOrEmpty(previoustoken)) { // Parse actor state StateStructure st = new StateStructure(this, parser); if (parser.HasError) { return; } states[previoustoken.ToLowerInvariant()] = st; } else { parser.ReportError("Expected actor state name"); return; } } else { // Keep token previoustoken = statetoken; } } else { parser.ReportError("Unexpected end of structure"); return; } } break; case "var": //mxd // Type parser.SkipWhitespace(true); string typestr = parser.ReadToken().ToUpperInvariant(); UniversalType type = UniversalType.EnumOption; // There is no Unknown type, so let's use something impossiburu... switch (typestr) { case "INT": type = UniversalType.Integer; break; case "FLOAT": type = UniversalType.Float; break; default: parser.LogWarning("Unknown user variable type"); break; } // Name parser.SkipWhitespace(true); string name = parser.ReadToken(); if (string.IsNullOrEmpty(name)) { parser.ReportError("Expected User Variable name"); return; } if (!name.StartsWith("user_", StringComparison.OrdinalIgnoreCase)) { parser.ReportError("User Variable name must start with \"user_\" prefix"); return; } if (uservars.ContainsKey(name)) { parser.ReportError("User Variable \"" + name + "\" is double defined"); return; } if (!skipsuper && baseclass != null && baseclass.uservars.ContainsKey(name)) { parser.ReportError("User variable \"" + name + "\" is already defined in one of the parent classes"); return; } // Rest parser.SkipWhitespace(true); string next = parser.ReadToken(); if (next == "[") // that's User Array. Let's skip it... { int arrlen = -1; if (!parser.ReadSignedInt(ref arrlen)) { parser.ReportError("Expected User Array length"); return; } if (arrlen < 1) { parser.ReportError("User Array length must be a positive value"); return; } if (!parser.NextTokenIs("]") || !parser.NextTokenIs(";")) { return; } } else if (next != ";") { parser.ReportError("Expected \";\", but got \"" + next + "\""); return; } else { // Add to collection uservars.Add(name, type); } break; case "}": //mxd. Get user vars from the BaseClass, if we have one if (!skipsuper && baseclass != null && baseclass.uservars.Count > 0) { foreach (var group in baseclass.uservars) { uservars.Add(group.Key, group.Value); } } // Actor scope ends here, break out of this parse loop done = true; break; // Monster property? case "monster": // This sets certain flags we are interested in flags["shootable"] = true; flags["countkill"] = true; flags["solid"] = true; flags["canpushwalls"] = true; flags["canusewalls"] = true; flags["activatemcross"] = true; flags["canpass"] = true; flags["ismonster"] = true; break; // Projectile property? case "projectile": // This sets certain flags we are interested in flags["noblockmap"] = true; flags["nogravity"] = true; flags["dropoff"] = true; flags["missile"] = true; flags["activateimpact"] = true; flags["activatepcross"] = true; flags["noteleport"] = true; break; // Clearflags property? case "clearflags": // Clear all flags flags.Clear(); break; // Game property? case "game": // Include all tokens on the same line List <string> games = new List <string>(); while (parser.SkipWhitespace(false)) { string v = parser.ReadToken(); if (string.IsNullOrEmpty(v)) { parser.ReportError("Expected \"Game\" property value"); return; } if (v == "\n") { break; } if (v == "}") { return; //mxd } if (v != ",") { games.Add(v.ToLowerInvariant()); } } props[token] = games; break; // Property default: // Property begins with $? Then the whole line is a single value if (token.StartsWith("$")) { // This is for editor-only properties such as $sprite and $category props[token] = new List <string> { (parser.SkipWhitespace(false) ? parser.ReadLine() : "") }; } else { // Next tokens up until the next newline are values List <string> values = new List <string>(); while (parser.SkipWhitespace(false)) { string v = parser.ReadToken(); if (string.IsNullOrEmpty(v)) { parser.ReportError("Unexpected end of structure"); return; } if (v == "\n") { break; } if (v == "}") { return; //mxd } if (v != ",") { values.Add(v); } } //mxd. Translate scale to xscale and yscale if (token == "scale") { props["xscale"] = values; props["yscale"] = values; } else { props[token] = values; } } break; } if (done) { break; //mxd } // Keep token previoustoken = token; } //mxd. Check if baseclass is valid if (inheritclass.ToLowerInvariant() != "actor" && doomednum > -1 && baseclass == null) { //check if this class inherits from a class defined in game configuration Dictionary <int, ThingTypeInfo> things = General.Map.Config.GetThingTypes(); string inheritclasscheck = inheritclass.ToLowerInvariant(); foreach (KeyValuePair <int, ThingTypeInfo> ti in things) { if (!string.IsNullOrEmpty(ti.Value.ClassName) && ti.Value.ClassName.ToLowerInvariant() == inheritclasscheck) { //states if (states.Count == 0 && !string.IsNullOrEmpty(ti.Value.Sprite)) { states.Add("spawn", new StateStructure(ti.Value.Sprite.Substring(0, 5))); } //flags if (ti.Value.Hangs && !flags.ContainsKey("spawnceiling")) { flags["spawnceiling"] = true; } if (ti.Value.Blocking > 0 && !flags.ContainsKey("solid")) { flags["solid"] = true; } //properties if (!props.ContainsKey("height")) { props["height"] = new List <string> { ti.Value.Height.ToString() } } ; if (!props.ContainsKey("radius")) { props["radius"] = new List <string> { ti.Value.Radius.ToString() } } ; return; } } parser.LogWarning("Unable to find \"" + inheritclass + "\" class to inherit from, while parsing \"" + classname + ":" + doomednum + "\""); } }
// Constructor internal StateStructure(ActorStructure actor, DecorateParser parser) { string lasttoken = ""; this.gotostate = null; this.parser = parser; this.sprites = new List <FrameInfo>(); // Skip whitespace while (parser.SkipWhitespace(true)) { // Read first token string token = parser.ReadToken().ToLowerInvariant(); // One of the flow control statements? if ((token == "loop") || (token == "stop") || (token == "wait") || (token == "fail")) { // Ignore flow control } // Goto? else if (token == "goto") { gotostate = new StateGoto(actor, parser); if (parser.HasError) { return; } } // Label? else if (token == ":") { // Rewind so that this label can be read again if (!string.IsNullOrEmpty(lasttoken)) { parser.DataStream.Seek(-(lasttoken.Length + 1), SeekOrigin.Current); } // Done here return; } //mxd. Start of inner scope? else if (token == "{") { int bracelevel = 1; while (!string.IsNullOrEmpty(token) && bracelevel > 0) { parser.SkipWhitespace(false); token = parser.ReadToken(); switch (token) { case "{": bracelevel++; break; case "}": bracelevel--; break; } } } // End of scope? else if (token == "}") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Done here return; } else { // First part of the sprite name token = parser.StripTokenQuotes(token); //mxd. First part of the sprite name can be quoted if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected sprite name"); return; } // Frames of the sprite name parser.SkipWhitespace(true); string spriteframes = parser.StripTokenQuotes(parser.ReadToken()); //mxd. Frames can be quoted if (string.IsNullOrEmpty(spriteframes)) { parser.ReportError("Expected sprite frame"); return; } // Label? if (spriteframes == ":") { // Rewind so that this label can be read again parser.DataStream.Seek(-(token.Length + 1), SeekOrigin.Current); // Done here return; } // No first sprite yet? FrameInfo info = new FrameInfo(); //mxd if (spriteframes.Length > 0) { //mxd. I'm not even 50% sure the parser handles all bizzare cases without shifting sprite name / frame blocks, // so let's log it as a warning, not an error... if (token.Length != 4) { parser.LogWarning("Invalid sprite name \"" + token.ToUpperInvariant() + "\". Sprite names must be exactly 4 characters long"); } else { // Make the sprite name string spritename = (token + spriteframes[0]).ToUpperInvariant(); // Ignore some odd ZDoom things if (!spritename.StartsWith("TNT1") && !spritename.StartsWith("----") && !spritename.Contains("#")) { info.Sprite = spritename; //mxd sprites.Add(info); } } } // Continue until the end of the line parser.SkipWhitespace(false); string t = parser.ReadToken(); while (!string.IsNullOrEmpty(t) && t != "\n") { //mxd. Bright keyword support... if (t == "bright") { info.Bright = true; } //mxd. Light() expression support... else if (t == "light") { if (!parser.NextTokenIs("(")) { return; } if (!parser.SkipWhitespace(true)) { parser.ReportError("Unexpected end of the structure"); return; } info.LightName = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(info.LightName)) { parser.ReportError("Expected dynamic light name"); return; } if (!parser.SkipWhitespace(true)) { parser.ReportError("Unexpected end of the structure"); return; } if (!parser.NextTokenIs(")")) { return; } } //mxd. Inner scope start. Step back and reparse using parent loop else if (t == "{") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Break out of this loop break; } //mxd. Function params start (those can span multiple lines) else if (t == "(") { int bracelevel = 1; while (!string.IsNullOrEmpty(token) && bracelevel > 0) { parser.SkipWhitespace(true); token = parser.ReadToken(); switch (token) { case "(": bracelevel++; break; case ")": bracelevel--; break; } } } //mxd. Because stuff like this is also valid: "Actor Oneliner { States { Spawn: WOOT A 1 A_FadeOut(0.1) Loop }}" else if (t == "}") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Done here return; } // Read next token parser.SkipWhitespace(false); t = parser.ReadToken().ToLowerInvariant(); } } lasttoken = token; } }
// Constructor internal ActorStructure(DecorateParser parser) { // Initialize flags = new Dictionary <string, bool>(); props = new Dictionary <string, List <string> >(); states = new Dictionary <string, StateStructure>(); // Always define a game property, but default to 0 values props["game"] = new List <string>(); inheritclass = "actor"; replaceclass = null; baseclass = null; skipsuper = false; // First next token is the class name parser.SkipWhitespace(true); classname = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(classname)) { parser.ReportError("Expected actor class name"); return; } // Parse tokens before entering the actor scope while (parser.SkipWhitespace(true)) { string token = parser.ReadToken(); if (!string.IsNullOrEmpty(token)) { token = token.ToLowerInvariant(); if (token == ":") { // The next token must be the class to inherit from parser.SkipWhitespace(true); inheritclass = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(inheritclass) || parser.IsSpecialToken(inheritclass)) { parser.ReportError("Expected class name to inherit from"); return; } else { // Find the actor to inherit from baseclass = parser.GetArchivedActorByName(inheritclass); if (baseclass == null) { General.ErrorLogger.Add(ErrorType.Warning, "Unable to find the DECORATE class '" + inheritclass + "' to inherit from, while parsing '" + classname + "'"); } } } else if (token == "replaces") { // The next token must be the class to replace parser.SkipWhitespace(true); replaceclass = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(replaceclass) || parser.IsSpecialToken(replaceclass)) { parser.ReportError("Expected class name to replace"); return; } } else if (token == "native") { // Igore this token } else if (token == "{") { // Actor scope begins here, // break out of this parse loop break; } else if (token == "-") { // This could be a negative doomednum (but our parser sees the - as separate token) // So read whatever is after this token and ignore it (negative doomednum indicates no doomednum) parser.ReadToken(); } else { // Check if numeric if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out doomednum)) { // Not numeric! parser.ReportError("Expected numeric editor thing number or start of actor scope"); return; } } } else { parser.ReportError("Unexpected end of structure"); return; } } // Now parse the contents of actor structure string previoustoken = ""; while (parser.SkipWhitespace(true)) { string token = parser.ReadToken(); token = token.ToLowerInvariant(); if ((token == "+") || (token == "-")) { // Next token is a flag (option) to set or remove bool flagvalue = (token == "+"); parser.SkipWhitespace(true); string flagname = parser.ReadToken(); if (!string.IsNullOrEmpty(flagname)) { // Add the flag with its value flagname = flagname.ToLowerInvariant(); flags[flagname] = flagvalue; } else { parser.ReportError("Expected flag name"); return; } } else if ((token == "action") || (token == "native")) { // We don't need this, ignore up to the first next ; while (parser.SkipWhitespace(true)) { string t = parser.ReadToken(); if ((t == ";") || (t == null)) { break; } } } else if (token == "skip_super") { skipsuper = true; } else if (token == "states") { // Now parse actor states until we reach the end of the states structure while (parser.SkipWhitespace(true)) { string statetoken = parser.ReadToken(); if (!string.IsNullOrEmpty(statetoken)) { // Start of scope? if (statetoken == "{") { // This is fine } // End of scope? else if (statetoken == "}") { // Done with the states, // break out of this parse loop break; } // State label? else if (statetoken == ":") { if (!string.IsNullOrEmpty(previoustoken)) { // Parse actor state StateStructure st = new StateStructure(this, parser, previoustoken); if (parser.HasError) { return; } states[previoustoken.ToLowerInvariant()] = st; } else { parser.ReportError("Unexpected end of structure"); return; } } else { // Keep token previoustoken = statetoken; } } else { parser.ReportError("Unexpected end of structure"); return; } } } else if (token == "}") { // Actor scope ends here, // break out of this parse loop break; } // Monster property? else if (token == "monster") { // This sets certain flags we are interested in flags["shootable"] = true; flags["countkill"] = true; flags["solid"] = true; flags["canpushwalls"] = true; flags["canusewalls"] = true; flags["activatemcross"] = true; flags["canpass"] = true; flags["ismonster"] = true; } // Projectile property? else if (token == "projectile") { // This sets certain flags we are interested in flags["noblockmap"] = true; flags["nogravity"] = true; flags["dropoff"] = true; flags["missile"] = true; flags["activateimpact"] = true; flags["activatepcross"] = true; flags["noteleport"] = true; } // Clearflags property? else if (token == "clearflags") { // Clear all flags flags.Clear(); } // Game property? else if (token == "game") { // Include all tokens on the same line List <string> games = new List <string>(); while (parser.SkipWhitespace(false)) { string v = parser.ReadToken(); if (v == null) { parser.ReportError("Unexpected end of structure"); return; } if (v == "\n") { break; } if (v != ",") { games.Add(v.ToLowerInvariant()); } } props[token] = games; } // Property else { // Property begins with $? Then the whole line is a single value if (token.StartsWith("$")) { // This is for editor-only properties such as $sprite and $category List <string> values = new List <string>(); if (parser.SkipWhitespace(false)) { values.Add(parser.ReadLine()); } else { values.Add(""); } props[token] = values; } else { // Next tokens up until the next newline are values List <string> values = new List <string>(); while (parser.SkipWhitespace(false)) { string v = parser.ReadToken(); if (v == null) { parser.ReportError("Unexpected end of structure"); return; } if (v == "\n") { break; } if (v != ",") { values.Add(v); } } props[token] = values; } } // Keep token previoustoken = token; } }
// Constructor internal StateGoto(ActorStructure actor, DecorateParser parser) { string firsttarget = ""; string secondtarget = ""; bool commentreached = false; bool offsetreached = false; string offsetstr = ""; int cindex = 0; // This is a bitch to parse because for some bizarre reason someone thought it // was funny to allow quotes here. Read the whole line and start parsing this manually. string line = parser.ReadLine(); // Skip whitespace while ((cindex < line.Length) && ((line[cindex] == ' ') || (line[cindex] == '\t'))) { cindex++; } // Parse first target while ((cindex < line.Length) && (line[cindex] != ':')) { // When a comment is reached, we're done here if (line[cindex] == '/') { if ((cindex + 1 < line.Length) && ((line[cindex + 1] == '/') || (line[cindex + 1] == '*'))) { commentreached = true; break; } } // Whitespace ends the string if ((line[cindex] == ' ') || (line[cindex] == '\t')) { break; } // + sign indicates offset start if (line[cindex] == '+') { cindex++; offsetreached = true; break; } // Ignore quotes if (line[cindex] != '"') { firsttarget += line[cindex]; } cindex++; } if (!commentreached && !offsetreached) { // Skip whitespace while ((cindex < line.Length) && ((line[cindex] == ' ') || (line[cindex] == '\t'))) { cindex++; } // Parse second target while (cindex < line.Length) { // When a comment is reached, we're done here if (line[cindex] == '/') { if ((cindex + 1 < line.Length) && ((line[cindex + 1] == '/') || (line[cindex + 1] == '*'))) { commentreached = true; break; } } // Whitespace ends the string if ((line[cindex] == ' ') || (line[cindex] == '\t')) { break; } // + sign indicates offset start if (line[cindex] == '+') { cindex++; offsetreached = true; break; } // Ignore quotes and semicolons if ((line[cindex] != '"') && (line[cindex] != ':')) { secondtarget += line[cindex]; } cindex++; } } // Try to find the offset if we still haven't found it yet if (!offsetreached) { // Skip whitespace while ((cindex < line.Length) && ((line[cindex] == ' ') || (line[cindex] == '\t'))) { cindex++; } if ((cindex < line.Length) && (line[cindex] == '+')) { cindex++; offsetreached = true; } } if (offsetreached) { // Parse offset while (cindex < line.Length) { // When a comment is reached, we're done here if (line[cindex] == '/') { if ((cindex + 1 < line.Length) && ((line[cindex + 1] == '/') || (line[cindex + 1] == '*'))) { commentreached = true; break; } } // Whitespace ends the string if ((line[cindex] == ' ') || (line[cindex] == '\t')) { break; } // Ignore quotes and semicolons if ((line[cindex] != '"') && (line[cindex] != ':')) { offsetstr += line[cindex]; } cindex++; } } // We should now have a first target, optionally a second target and optionally a sprite offset // Check if we don't have the class specified if (string.IsNullOrEmpty(secondtarget)) { // First target is the state to go to classname = actor.ClassName; statename = firsttarget.ToLowerInvariant().Trim(); } else { // First target is the base class to use // Second target is the state to go to classname = firsttarget.ToLowerInvariant().Trim(); statename = secondtarget.ToLowerInvariant().Trim(); } if (offsetstr.Length > 0) { int.TryParse(offsetstr, out spriteoffset); } if ((classname == "super") && (actor.BaseClass != null)) { classname = actor.BaseClass.ClassName; } }
internal DecorateStateStructure(ActorStructure actor, ZDTextParser zdparser) { DecorateParser parser = (DecorateParser)zdparser; string lasttoken = ""; // Skip whitespace while (parser.SkipWhitespace(true)) { // Read first token string token = parser.ReadToken().ToLowerInvariant(); // One of the flow control statements? if ((token == "loop") || (token == "stop") || (token == "wait") || (token == "fail")) { // Ignore flow control // [ZZ] sometimes "fail" is a sprite name... (Skulltag, Zandronum) // probably the same can happen to other single-word flow control keywords. // check if next token is newline. long cpos = parser.DataStream.Position; parser.SkipWhitespace(false); string newline = parser.ReadToken(); parser.DataStream.Position = cpos; if (newline == "\n") // this is actually a loop/stop/wait/fail directive and not a sprite name or something { lasttoken = token; continue; } } // Goto? if (token == "goto") { gotostate = new DecorateStateGoto(actor, parser); if (parser.HasError) { return; } } // Label? else if (token == ":") { // Rewind so that this label can be read again if (!string.IsNullOrEmpty(lasttoken)) { parser.DataStream.Seek(-(lasttoken.Length + 1), SeekOrigin.Current); } // Done here goto endofallthings; } //mxd. Start of inner scope? else if (token == "{") { int bracelevel = 1; while (!string.IsNullOrEmpty(token) && bracelevel > 0) { parser.SkipWhitespace(false); token = parser.ReadToken(); switch (token) { case "{": bracelevel++; break; case "}": bracelevel--; break; } } } // End of scope? else if (token == "}") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Done here goto endofallthings; } else { // First part of the sprite name token = parser.StripTokenQuotes(token); //mxd. First part of the sprite name can be quoted if (string.IsNullOrEmpty(token)) { parser.ReportError("Expected sprite name"); return; } // Frames of the sprite name parser.SkipWhitespace(true); string spriteframes = parser.StripTokenQuotes(parser.ReadToken()); //mxd. Frames can be quoted if (string.IsNullOrEmpty(spriteframes)) { parser.ReportError("Expected sprite frame"); return; } // Label? if (spriteframes == ":") { // Rewind so that this label can be read again parser.DataStream.Seek(-(token.Length + 1), SeekOrigin.Current); // Done here goto endofallthings; } // No first sprite yet? FrameInfo info = new FrameInfo(); //mxd if (spriteframes.Length > 0) { //mxd. I'm not even 50% sure the parser handles all bizzare cases without shifting sprite name / frame blocks, // so let's log it as a warning, not an error... if (token.Length != 4) { parser.LogWarning("Invalid sprite name \"" + token.ToUpperInvariant() + "\". Sprite names must be exactly 4 characters long"); } else { // Make the sprite name string spritename = (token + spriteframes[0]).ToUpperInvariant(); // Ignore some odd ZDoom things if (/*!realspritename.StartsWith("TNT1") && */ !spritename.StartsWith("----") && !spritename.Contains("#")) // [ZZ] some actors have only TNT1 state and receive a random image because of this { info.Sprite = spritename; //mxd int duration = -1; parser.SkipWhitespace(false); string durationstr = parser.ReadToken(); if (durationstr == "-") { durationstr += parser.ReadToken(); } if (string.IsNullOrEmpty(durationstr) || durationstr == "\n") { parser.ReportError("Expected frame duration"); return; } if (!int.TryParse(durationstr.Trim(), out duration)) { parser.DataStream.Seek(-(durationstr.Length), SeekOrigin.Current); } info.Duration = duration; sprites.Add(info); } } } // Continue until the end of the line parser.SkipWhitespace(false); string t = parser.ReadToken(); while (!string.IsNullOrEmpty(t) && t != "\n") { //mxd. Bright keyword support... if (t == "bright") { info.Bright = true; } //mxd. Light() expression support... else if (t == "light") { if (!parser.NextTokenIs("(")) { return; } if (!parser.SkipWhitespace(true)) { parser.ReportError("Unexpected end of the structure"); return; } info.LightName = parser.StripTokenQuotes(parser.ReadToken()); if (string.IsNullOrEmpty(info.LightName)) { parser.ReportError("Expected dynamic light name"); return; } if (!parser.SkipWhitespace(true)) { parser.ReportError("Unexpected end of the structure"); return; } if (!parser.NextTokenIs(")")) { parser.ReportError("Expected closing parenthesis in Light()"); return; } } //mxd. Inner scope start. Step back and reparse using parent loop else if (t == "{") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Break out of this loop break; } //mxd. Function params start (those can span multiple lines) else if (t == "(") { int bracelevel = 1; while (!string.IsNullOrEmpty(token) && bracelevel > 0) { parser.SkipWhitespace(true); token = parser.ReadToken(); switch (token) { case "(": bracelevel++; break; case ")": bracelevel--; break; } } } //mxd. Because stuff like this is also valid: "Actor Oneliner { States { Spawn: WOOT A 1 A_FadeOut(0.1) Loop }}" else if (t == "}") { // Rewind so that this scope end can be read again parser.DataStream.Seek(-1, SeekOrigin.Current); // Done here goto endofallthings; } // Read next token parser.SkipWhitespace(false); t = parser.ReadToken().ToLowerInvariant(); } } lasttoken = token; } // return endofallthings: TrimLeft(); }