public FieldSaver(GameSaver saver) { m_saver = saver; // Use Reflection to create instances of all IFieldSavers foreach (Type t in TextAdventures.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(), typeof(IFieldSaver))) { AddSaver((IFieldSaver)Activator.CreateInstance(t)); } }
public void Save(GameXmlWriter writer, WorldModel worldModel) { ObjectSaver elementSaver = new ObjectSaver(); elementSaver.GameSaver = GameSaver; IEnumerable <Element> allObjects = worldModel.Elements.GetElements(ElementType.Object).OrderBy(o => o.MetaFields[MetaFieldDefinitions.SortIndex]); foreach (Element e in allObjects.Where(e => e.Parent == null && GameSaver.CanSave(e))) { SaveObjectAndChildren(writer, allObjects, e, elementSaver); } }
public override void Save(GameXmlWriter writer, Element element, string attribute, object value) { writer.WriteStartElement(attribute); if (element == null || !GameSaver.IsImpliedType(element, attribute, "list")) { writer.WriteAttributeString("type", "list"); } QuestList <object> list = (QuestList <object>)value; foreach (var item in list) { FieldSaver.SaveValue(writer, "value", item); } writer.WriteEndElement(); }
public override void Save(GameXmlWriter writer, Element e) { writer.WriteStartElement("function"); writer.WriteAttributeString("name", e.Name); if (e.Fields[FieldDefinitions.ParamNames] != null && e.Fields[FieldDefinitions.ParamNames].Count > 0) { writer.WriteAttributeString("parameters", string.Join(", ", e.Fields[FieldDefinitions.ParamNames].ToArray())); } if (!string.IsNullOrEmpty(e.Fields[FieldDefinitions.ReturnType])) { writer.WriteAttributeString("type", e.Fields[FieldDefinitions.ReturnType]); } if (e.Fields[FieldDefinitions.Script] != null) { writer.WriteString(GameSaver.SaveScript(writer, e.Fields[FieldDefinitions.Script], 0)); } writer.WriteEndElement(); }
public void Save(GameXmlWriter writer, Element element, string attribute, object value) { writer.WriteStartElement(attribute); if (element == null || !GameSaver.IsImpliedType(element, attribute, "scriptdictionary")) { writer.WriteAttributeString("type", "scriptdictionary"); } QuestDictionary <IScript> dictionary = (QuestDictionary <IScript>)value; foreach (var item in dictionary) { writer.WriteStartElement("item"); writer.WriteAttributeString("key", item.Key); writer.WriteString(GameSaver.SaveScript(writer, item.Value, 0)); writer.WriteEndElement(); } writer.WriteEndElement(); }
public override void Save(GameXmlWriter writer, Element element, string attribute, object value) { writer.WriteStartElement(attribute); if (element == null || !GameSaver.IsImpliedType(element, attribute, TypeName)) { writer.WriteAttributeString("type", TypeName); } var dictionary = (QuestDictionary <T>)value; foreach (var item in dictionary) { writer.WriteStartElement("item"); writer.WriteStartElement("key"); writer.WriteString(item.Key); writer.WriteEndElement(); WriteXml(writer, item.Value); writer.WriteEndElement(); } writer.WriteEndElement(); }
protected void WriteAttribute(GameXmlWriter writer, Element element, string attribute, string type, string value) { if (!s_regex.IsMatch(attribute)) { // For attribute names with spaces or accented characters, we output // <attr name="my attribute" ... /> writer.WriteStartElement("attr"); writer.WriteAttributeString("name", attribute); } else { // For attribute names without spaces, we output // <myattribute ... /> writer.WriteStartElement(attribute); } if (element == null || !GameSaver.IsImpliedType(element, attribute, type) || value.Length == 0) { writer.WriteAttributeString("type", type); } writer.WriteString(value); writer.WriteEndElement(); }
private bool InitialiseInternal(GameLoader loader) { if (m_state != GameState.NotStarted) { throw new Exception("Game already initialised"); } loader.FilenameUpdated += loader_FilenameUpdated; loader.LoadStatus += loader_LoadStatus; m_state = GameState.Loading; bool success; if (m_data != null) { success = loader.Load(data: m_data); } else { success = m_filename == null || loader.Load(m_filename); } DebugEnabled = !loader.IsCompiledFile; m_state = success ? GameState.Running : GameState.Finished; m_errors = loader.Errors; m_saver = new GameSaver(this); if (Version <= WorldModelVersion.v530) { m_legacyOutputLogger = new LegacyOutputLogger(this); m_outputLogger = m_legacyOutputLogger; } else { m_outputLogger = new OutputLogger(this); } return success; }
public override void Save(GameXmlWriter writer, Element element, string attribute, object value) { DelegateImplementation impl = (DelegateImplementation)value; base.WriteAttribute(writer, element, attribute, impl.Definition.Name, GameSaver.SaveScript(writer, impl.Implementation.Fields[FieldDefinitions.Script], 1)); }
void saver_Progress(object sender, GameSaver.ProgressEventArgs e) { if (Progress != null) { Progress(this, new ProgressEventArgs { Progress = e.PercentComplete }); } }
public CompilerResults Compile(CompileOptions compileOptions) { CompilerResults result = new CompilerResults(); GameLoader loader = new GameLoader(); UpdateStatus(string.Format("Compiling {0} to {1}", compileOptions.Filename, compileOptions.OutputFolder)); if (!loader.Load(compileOptions.Filename)) { result.Errors = loader.Errors; } else { UpdateStatus("Loaded successfully"); result.Warnings = loader.Warnings; result.Success = true; var substitutionText = GetSubstitutionText(loader, compileOptions.Profile); UpdateStatus("Copying dependencies"); result.IndexHtml = CopyDependenciesToOutputFolder(compileOptions.OutputFolder, substitutionText, compileOptions.DebugMode, compileOptions.Profile, compileOptions.Minify, loader, compileOptions); string saveData = string.Empty; UpdateStatus("Saving"); GameSaver saver = new GameSaver(loader.Elements); saver.Progress += saver_Progress; saveData = saver.Save(); UpdateStatus("Copying resources"); CopyResourcesToOutputFolder(loader.ResourcesFolder, compileOptions.OutputFolder); saveData += GetEmbeddedHtmlFileData(loader.ResourcesFolder); string saveJs = System.IO.Path.Combine(compileOptions.OutputFolder, "game.js"); saveData = System.IO.File.ReadAllText(saveJs) + saveData; if (compileOptions.Minify) { var minifier = new Microsoft.Ajax.Utilities.Minifier(); saveData = minifier.MinifyJavaScript(saveData, new Microsoft.Ajax.Utilities.CodeSettings { MacSafariQuirks = true, RemoveUnneededCode = true, LocalRenaming = Microsoft.Ajax.Utilities.LocalRenaming.CrunchAll }); var encoding = (Encoding)Encoding.ASCII.Clone(); encoding.EncoderFallback = new Microsoft.Ajax.Utilities.JSEncoderFallback(); using (var writer = new System.IO.StreamWriter(saveJs, false, encoding)) { writer.Write(saveData); } } else { System.IO.File.WriteAllText(saveJs, saveData); } UpdateStatus("Finished"); } return result; }