protected virtual Script DeserializeScript(ReloadedScriptEntry reloadedScript) { var eventReader = new EventReader(new MemoryParser(reloadedScript.YamlEvents)); var scriptCollection = (ScriptCollection)YamlSerializer.Deserialize(eventReader, null, typeof(ScriptCollection), log != null ? new SerializerContextSettings { Logger = new YamlForwardLogger(log) } : null); var script = scriptCollection.Count == 1 ? scriptCollection[0] : null; return script; }
protected override void ReplaceScript(ScriptComponent scriptComponent, ReloadedScriptEntry reloadedScript) { // Create new script instance var newScript = DeserializeScript(reloadedScript); // Dispose and unregister old script (and their MicroThread, if any) var oldScript = scriptComponent.Scripts[reloadedScript.ScriptIndex]; // Flag scripts as being live reloaded if (game != null) { game.Script.LiveReload(oldScript, newScript); } // Replace with new script // TODO: Remove script before serializing it, so cancellation code can run scriptComponent.Scripts[reloadedScript.ScriptIndex] = newScript; oldScript.Dispose(); if (oldScript.MicroThread != null && !oldScript.MicroThread.IsOver) { // Force the script to be cancelled oldScript.MicroThread.RaiseException(new MicroThreadCancelledException()); } }
protected virtual Script DeserializeScript(ReloadedScriptEntry reloadedScript) { var eventReader = new EventReader(new MemoryParser(reloadedScript.YamlEvents)); var scriptCollection = (ScriptCollection)YamlSerializer.Deserialize(eventReader, null, typeof(ScriptCollection), log != null ? new SerializerContextSettings { Logger = new YamlForwardLogger(log) } : null); var script = scriptCollection.Count == 1 ? scriptCollection[0] : null; return(script); }
protected virtual Script DeserializeScript(ReloadedScriptEntry reloadedScript) { var eventReader = new EventReader(new MemoryParser(reloadedScript.YamlEvents)); var scriptCollection = new ScriptCollection(); // Use the newly created script during second pass for proper cycle deserialization var newScript = ((ReloadedScriptEntryLive)reloadedScript).NewScript; if (newScript != null) { scriptCollection.Add(newScript); } // Try to create script first YamlSerializer.Deserialize(eventReader, scriptCollection, typeof(ScriptCollection)); var script = scriptCollection.Count == 1 ? scriptCollection[0] : null; return(script); }
protected virtual void ReplaceScript(ScriptComponent scriptComponent, ReloadedScriptEntry reloadedScript) { // TODO: Let PropertyGrid know that we updated the script scriptComponent.Scripts[reloadedScript.ScriptIndex] = DeserializeScript(reloadedScript); }
protected virtual Script DeserializeScript(ReloadedScriptEntry reloadedScript) { var eventReader = new EventReader(new MemoryParser(reloadedScript.YamlEvents)); var scriptCollection = new ScriptCollection(); // Use the newly created script during second pass for proper cycle deserialization var newScript = ((ReloadedScriptEntryLive)reloadedScript).NewScript; if (newScript != null) scriptCollection.Add(newScript); // Try to create script first YamlSerializer.Deserialize(eventReader, scriptCollection, typeof(ScriptCollection)); var script = scriptCollection.Count == 1 ? scriptCollection[0] : null; return script; }