void ParseQRC(Quest quest, List <string> lines) { const string parseIdError = "Could not parse text '{0}' to an int. Expected message ID value."; const string idCol = "id"; Table staticMessagesTable = QuestMachine.Instance.StaticMessagesTable; for (int i = 0; i < lines.Count; i++) { // Skip empty lines while scanning for start of message block if (string.IsNullOrEmpty(lines[i].Trim())) { continue; } // Check for start of message block // Only present in QRC section // Begins with field Message: (or fixed message type) string[] parts = SplitField(lines[i]); if (staticMessagesTable.HasValue(parts[0])) { // Read ID of message int messageID = 0; if (parts[1].StartsWith("[") && parts[1].EndsWith("]")) { // Fixed message types use ID from table messageID = staticMessagesTable.GetInt(idCol, parts[0]); if (messageID == -1) { throw new Exception(string.Format(parseIdError, staticMessagesTable.GetInt(idCol, parts[0]))); } } else { // Other messages use ID from message block header if (!int.TryParse(parts[1], out messageID)) { throw new Exception(string.Format(parseIdError, parts[1])); } } // Keep reading message lines until empty line is found, indicating end of block List <string> messageLines = new List <string>(); while (true) { // Check for end of lines // This handles a case where final message block isn't terminated an empty line causing an overflow if (i + 1 >= lines.Count) { break; } // Read line string text = lines[++i].TrimEnd('\r'); if (string.IsNullOrEmpty(text)) { // Sometimes quest author will forget single space in front of an empty message line // Peek ahead to see if next line is really a new message header // Otherwise just treat this as a line break in message (add a single ' ' character) if (!PeekMessageEnd(lines, i)) { messageLines.Add(" "); continue; } else { break; } } else { messageLines.Add(text); } } // Instantiate message Message message = new Message(quest, messageID, messageLines.ToArray()); // Add message to collection quest.AddMessage(messageID, message); } else { throw new Exception(string.Format("Could not parse message block near '{0}'. Check message header syntax, spelling, and casing are all correct.", lines[i])); } } }
void ParseQRC(Quest quest, List <string> lines) { const string parseIdError = "Could not parse text '{0}' to an int. Expected message ID value."; const string idCol = "id"; Table staticMessagesTable = QuestMachine.Instance.StaticMessagesTable; for (int i = 0; i < lines.Count; i++) { // Skip empty lines while scanning for start of message block if (string.IsNullOrEmpty(lines[i].Trim())) { continue; } // Check for start of message block // Only present in QRC section // Begins with field Message: (or fixed message type) string[] parts = SplitField(lines[i]); if (staticMessagesTable.HasValue(parts[0])) { // Read ID of message int messageID = 0; if (parts[1].StartsWith("[") && parts[1].EndsWith("]")) { // Fixed message types use ID from table messageID = staticMessagesTable.GetInt(idCol, parts[0]); if (messageID == -1) { throw new Exception(string.Format(parseIdError, staticMessagesTable.GetInt(idCol, parts[0]))); } } else { // Other messages use ID from message block header if (!int.TryParse(parts[1], out messageID)) { throw new Exception(string.Format(parseIdError, parts[1])); } } // Keep reading message lines until empty line is found, indicating end of block List <string> messageLines = new List <string>(); while (true) { string text = lines[++i].TrimEnd('\r'); if (string.IsNullOrEmpty(text)) { break; } else { messageLines.Add(text); } } // Instantiate message Message message = new Message(quest, messageID, messageLines.ToArray()); // Add message to collection quest.AddMessage(messageID, message); } } }