Exemplo n.º 1
0
 public void RestoreSaveData(MessageSaveData_v1 data)
 {
     LoadMessage(data.id, data.lines);
 }
Exemplo n.º 2
0
        public MessageSaveData_v1 GetSaveData()
        {
            // Convert lines back to source format
            List <string> lines = new List <string>();

            for (int variant = 0; variant < variants.Count; variant++)
            {
                // Add split token for subsequent variants
                if (variant > 0)
                {
                    lines.Add(splitToken);
                }

                bool   foundText   = false;
                string currentLine = string.Empty;
                foreach (TextFile.Token token in variants[variant].tokens)
                {
                    switch (token.formatting)
                    {
                    case TextFile.Formatting.Text:
                        // Found another text token without a formatting line break - need to break to a new line
                        if (foundText)
                        {
                            lines.Add(currentLine);
                            currentLine = string.Empty;
                            foundText   = false;
                            continue;
                        }
                        // Just add the text
                        currentLine += token.text;
                        foundText    = true;
                        break;

                    case TextFile.Formatting.JustifyCenter:
                        // Prepend formatting token and start new line
                        currentLine = centerToken + currentLine;
                        lines.Add(currentLine);
                        currentLine = string.Empty;
                        foundText   = false;
                        break;

                    case TextFile.Formatting.Nothing:
                        // Probably last token in stream - add line and continue
                        lines.Add(currentLine);
                        currentLine = string.Empty;
                        foundText   = false;
                        continue;

                    default:
                        throw new System.Exception(string.Format("Message.GetSaveData() encountered unexpected formatting token {0}", token.formatting));
                    }
                }
            }

            // Create save data
            MessageSaveData_v1 data = new MessageSaveData_v1();

            data.id    = id;
            data.lines = lines.ToArray();

            return(data);
        }