示例#1
0
        public string Save(SaveMode mode, bool?includeWalkthrough = null, string html = null)
        {
            m_mode = mode;
            GameXmlWriter.GameXmlWriterOptions options = null;
            if (includeWalkthrough.HasValue)
            {
                options = new GameXmlWriter.GameXmlWriterOptions {
                    IncludeWalkthrough = includeWalkthrough.Value
                };
            }
            GameXmlWriter writer = new GameXmlWriter(mode, options);

            UpdateImpliedTypesCache();

            string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            writer.WriteComment(string.Format("Saved by Quest {0}", ver));
            writer.WriteStartElement("asl");
            if (mode == SaveMode.Editor)
            {
                m_worldModel.Version       = WorldModelVersion.v550;
                m_worldModel.VersionString = "550";
            }
            writer.WriteAttributeString("version", m_worldModel.VersionString);

            if (mode == SaveMode.SavedGame)
            {
                writer.WriteAttributeString("original", m_worldModel.Filename);
                m_worldModel.OutputLogger.Save(html);
            }

            foreach (ElementType t in Enum.GetValues(typeof(ElementType)))
            {
                if (m_elementsSavers.ContainsKey(t))
                {
                    // We have an IElementsSaver which saves all elements of a particular type at once
                    m_elementsSavers[t].Save(writer, m_worldModel);
                }
                else
                {
                    // Save the elements individually
                    IElementSaver saver;
                    if (m_elementSavers.TryGetValue(t, out saver))
                    {
                        if (saver.AutoSave)
                        {
                            foreach (Element e in m_worldModel.Elements.GetElements(t).Where(e => CanSave(e)))
                            {
                                saver.Save(writer, e);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("ERROR: No ElementSaver for type " + t.ToString());
                    }
                }
            }

            writer.WriteEndElement();
            writer.Close();

            return(writer.ToString());
        }
示例#2
0
文件: GameSaver.cs 项目: JatinR/quest
        public string Save(SaveMode mode, bool? includeWalkthrough = null, string html = null)
        {
            m_mode = mode;
            GameXmlWriter.GameXmlWriterOptions options = null;
            if (includeWalkthrough.HasValue)
            {
                options = new GameXmlWriter.GameXmlWriterOptions { IncludeWalkthrough = includeWalkthrough.Value };
            }
            GameXmlWriter writer = new GameXmlWriter(mode, options);

            UpdateImpliedTypesCache();

            string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            writer.WriteComment(string.Format("Saved by Quest {0}", ver));
            writer.WriteStartElement("asl");
            if (mode == SaveMode.Editor)
            {
                m_worldModel.Version = WorldModelVersion.v550;
                m_worldModel.VersionString = "550";
            }
            writer.WriteAttributeString("version", m_worldModel.VersionString);

            if (mode == SaveMode.SavedGame)
            {
                writer.WriteAttributeString("original", m_worldModel.Filename);
                m_worldModel.OutputLogger.Save(html);
            }

            foreach (ElementType t in Enum.GetValues(typeof(ElementType)))
            {
                if (m_elementsSavers.ContainsKey(t))
                {
                    // We have an IElementsSaver which saves all elements of a particular type at once
                    m_elementsSavers[t].Save(writer, m_worldModel);
                }
                else
                {
                    // Save the elements individually
                    IElementSaver saver;
                    if (m_elementSavers.TryGetValue(t, out saver))
                    {
                        if (saver.AutoSave)
                        {
                            foreach (Element e in m_worldModel.Elements.GetElements(t).Where(e => CanSave(e)))
                            {
                                saver.Save(writer, e);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("ERROR: No ElementSaver for type " + t.ToString());
                    }
                }
            }

            writer.WriteEndElement();
            writer.Close();

            return writer.ToString();
        }