Beispiel #1
0
        private void WriteVariables(string bornPath)
        {
            if ((m_ProcessedVariables.Keys.Count < 1) || (false == m_IsVariablesChanged))
            {
                return;
            }

            m_IsVariablesChanged = false;

            string path = m_RootPath + Path.DirectorySeparatorChar + "all-game-variables.rpy";

            m_Log.AppendLogLine($"Writing all variables to {Path.GetFileName(path)}");

            using (var writer = new StatStreamWriter(path))
            {
                var names = new List <string>(m_ProcessedVariables.Keys);

                names.Sort();
                writer.WriteLine("init python:");

                foreach (var varName in names)
                {
                    var varValue = m_ProcessedVariables[varName];

                    writer.Write($"    {varName} = ");

                    switch (varValue.type)
                    {
                    case DDVarType.String: writer.WriteLine($"\"{varValue.value}\""); break;

                    case DDVarType.Integer: writer.WriteLine($"{varValue.value}"); break;

                    case DDVarType.Boolean: writer.WriteLine(string.Format("{0}", varValue.Equals("true") ? "True" : "False")); break;
                    }
                }

                m_Log.AppendLogLine($"Variables finished. Size: {writer.TotalWritten}");
            }
        }
Beispiel #2
0
        private int WriteMessage(DDNode node, ref DDNode nextNode, int level, bool prevIsBox)
        {
            if ((null == node) || (false == node.node_type.Equals("show_message")))
            {
                return(0);
            }

            int    written = 0;
            string padding = GetPadding(level);
            string curText = node.GetText(node.text);
            string quotedText;

            if (curText.Contains("\n\n") ||
                curText.Contains("\r\n\r\n") ||
                curText.Contains($"{Environment.NewLine}{Environment.NewLine}"))
            {
                // Monologue mode
                quotedText = $"\"\"\"{Environment.NewLine}{curText}{Environment.NewLine}\"\"\"";
            }
            else
            {
                // Normal text
                quotedText = $"\"{curText}\"";
            }

            if (node.is_box != prevIsBox)
            {
                written += WriteSetNvlMode(node.is_box, level);
            }

            if (node.choices == null)
            {
                string character = node.character[0].ToString();

                if ("Player".Equals(character) || string.IsNullOrEmpty(character))
                {
                    written += m_Writer.WriteLine($"{padding}{quotedText}");
                }
                else
                {
                    written += m_Writer.WriteLine($"{padding}{character} {quotedText}");

                    m_Manager.ProcessCharacter(character);
                }
            }
            else
            {
                string menuPadding = GetPadding(level + 1);

                written += m_Writer.WriteLine(string.Empty);
                written += m_Writer.WriteLine($"{padding}menu:");

                if (false == string.IsNullOrEmpty(curText))
                {
                    written += m_Writer.WriteLine($"{menuPadding}{quotedText}");
                }

                foreach (var choice in node.choices)
                {
                    written += m_Writer.WriteLine(string.Empty);
                    written += m_Writer.Write($"{menuPadding}\"{node.GetText(choice.text)}\"");

                    if (choice.is_condition)
                    {
                        written += m_Writer.Write($" if {choice.condition}");
                    }

                    written += m_Writer.WriteLine($":");

                    written += WritePassIfNeed(ProcessNode(m_Object.GetNode(choice.next), level + 2, node.is_box), level + 2);
                }
            }

            nextNode = node.NextNode;
            return(written);
        }