protected override void WriteSeperator(ScriptWriter writer) { if (writer is JsScriptWriter && ((JsScriptWriter)writer).Condensed && this.SeperatorCondensed != null) writer.Write(this.SeperatorCondensed); else base.WriteSeperator(writer); }
protected override void OnRender(ScriptWriter writer, bool multiLine, bool startOnNewLine) { if (multiLine && startOnNewLine) writer.WriteNewLineAndIndent(); string quote = this.DoubleQuotes ? "\"" : "'"; if (Text == null) writer.Write(quote + quote); writer.Write(quote + JsScriptWriter.JsConvert(Text).ToString().Replace(quote, @"\" + quote) + quote); }
protected override void OnRender(ScriptWriter writer, bool multiLine, bool startOnNewLine) { if (multiLine && startOnNewLine) writer.WriteNewLineAndIndent(); writer.Write("function("); Parameters.Render(writer, 1); writer.Write(") {"); Commands.Render(writer, 1); if (Commands.MultiLine && !Commands.IsNothing()) writer.WriteNewLineAndIndent(); writer.Write("}"); }
protected override void OnRender(ScriptWriter writer, bool multiLine, bool startOnNewLine) { if (multiLine && startOnNewLine) writer.WriteNewLineAndIndent(); if (New) writer.Write("new "); writer.Write(Function); writer.Write("("); Parameters.Render(writer, 1); if (multiLine && !Parameters.IsNothing()) writer.WriteNewLineAndIndent(); writer.Write(")"); }
protected override void OnRender(ScriptWriter writer, bool multiLine, bool startOnNewLine) { if (multiLine && startOnNewLine) writer.WriteNewLineAndIndent(); writer.Write(Name + ": "); if (Value is IScriptItem) { if (!((IScriptItem)Value).IsNothing()) { ((IScriptItem)Value).Render(writer); } } else { writer.Write(Value); } }
/// <summary> /// Renders the text content after encoding it /// </summary> /// <param name="e"></param> protected override void OnRender(RenderingEventArgs e) { base.OnRender(e); IScriptWriter writer = e.Writer; if (this.Layout == ScriptLayout.Block && this.HasRenderContent) writer.WriteNewLineAndIndent(); // as we have to process the contents we will have to render it seperately StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw, e.Writer); // use same format provider sw.Write(this.Text); string text = tw.ToString(); writer.Write(Encode(text)); }
/// <summary> /// Renders the cdata section /// Special handing is done to cope if the data contains the illegal closing cdata character sequence (which I can't use here!) /// </summary> /// <param name="e">includes the script writer to render content to</param> protected override void OnRender(RenderingEventArgs e) { base.OnRender(e); IScriptWriter writer = e.Writer; if (this.Layout == ScriptLayout.Block && this.HasRenderContent) writer.WriteNewLineAndIndent(); // as we have to process the contents we will have to render it seperately StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw, e.Writer); // use same format provider sw.Write(this.Data); string text = tw.ToString(); text = text.Replace("]]>", "]]>]]><![CDATA["); // resolve embedded ]]> by changing to two cdatas with a text node writer.Write("<![CDATA["); writer.Write(text); writer.Write("]]>"); }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { FormatHelper.FormatGlobalSet(_globalVariable, _value, Jsm.GlobalUInt16, sw, formatterContext, services); }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .Property(nameof(FieldObject.IsActive)) .Assign(true) .Comment(nameof(USE));
void GetAllVariables() { ScrWri_Level = GameObject.FindObjectOfType <ScriptWriter>(); }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .Property(nameof(FieldObject.Animation)) .Method(nameof(FieldObjectAnimation.Play)) .Argument("animationId", _animationId) .Comment(nameof(RANIME));
/// <summary> /// renders the component /// </summary> /// <param name="e"></param> protected override void OnRender(RenderingEventArgs e) { base.OnRender(e); Script script = Sb.Script(); // work out the component name StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw, e.Writer); // use same format provider sw.Write(this.ComponentName); string componentName = tw.ToString(); string nameSpace = ExtJs.GetNamespace(componentName); // namespace script if (!String.IsNullOrEmpty(nameSpace)) script.Add(Js.Statement(Js.Call("Ext.ns", Js.Q(nameSpace)))); // register namespace // component script script.Add( Js.Statement(ComponentName, " = ", Js.Call(ScriptLayout.InlineBlock,"Ext.extend", Js.List( this.BaseComponent, Js.Object(ScriptLayout.InlineBlock, this.Object ) ) ) ) ); // register script if (!String.IsNullOrEmpty(this.RegistryName)) script.Add(Js.Statement(Js.Call("Ext.reg", Js.Q(this.RegistryName), this.ComponentName))); // register xtype e.Writer.Write(script); }
/// <summary> /// Add a CData section to the supplied element /// Special handing is done to cope if the data contains the illegal closing cdata character sequence /// </summary> /// <param name="parentElement"></param> public void Render(XmlElement parentElement) { XmlDocument doc = parentElement.OwnerDocument; // as we have to process the contents we will have to render it seperately StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw); // use same format provider sw.Write(this.Data); string text = tw.ToString(); while (text.Contains("]]>")) { string subData = text.Substring(0, text.IndexOf("]]>")); text = text.Substring(text.IndexOf("]]>") + 3); XmlCDataSection subCdata = doc.CreateCDataSection(subData); parentElement.AppendChild(subCdata); XmlText textNode = doc.CreateTextNode("]]>"); parentElement.AppendChild(textNode); } if (!String.IsNullOrEmpty(text)) { XmlCDataSection cdata = doc.CreateCDataSection(text); parentElement.AppendChild(cdata); } }
public bool SaveScript(FlipWindow window) { if (window == null) { throw new ArgumentNullException("window"); } if (attacher == null) { throw new InvalidOperationException("No attacher to save scripts with."); } if (!window.IsComplete) { //ActivityLog.Write(new Activity("TriedToSaveIncompleteScript")); Log.WriteMessage("tried to save incomplete script"); MessageBox.Show("Your script isn't finished! Fill in all the blanks before saving."); return(false); } IScriptFrame scriptFrame = window.GetCurrentScriptFrame(); AbstractScriptWriter scriptWriter; if (window.Mode == ScriptType.Conditional) { scriptWriter = new ConditionalScriptWriter(window.ConditionalFrame); } else { scriptWriter = new ScriptWriter(window.TriggerBar); } string code = scriptWriter.GetCombinedCode(); FlipScript script = new FlipScript(code, window.Mode, String.Empty); string address = scriptFrame.GetAddress(); try { string savedAs = attacher.Attach(script, address); window.TriggerBar.CurrentScriptIsBasedOn = savedAs; window.ConditionalFrame.CurrentScriptIsBasedOn = savedAs; window.IsDirty = false; //ActivityLog.Write(new Activity("SavedScript","SavedAs",savedAs)); Log.WriteAction(LogAction.saved, "script", "as " + savedAs); //MessageBox.Show("Script was saved successfully."); try { string nl = window.NaturalLanguage; if (String.IsNullOrEmpty(nl)) { window.NaturalLanguage = "Saved."; } else { window.NaturalLanguage = nl + Environment.NewLine + "Saved."; } } catch (Exception) {} return(true); } catch (MatchingInstanceNotFoundException x) { //ActivityLog.Write(new Activity("TriedToSaveScriptButTargetCouldNotBeFound","TargetType",x.Address.TargetType.ToString(),"TargetTagOrResRef",x.Address.InstanceTag)); Log.WriteMessage("tried to save script but couldn't find target (was looking for " + x.Address.TargetType + " with tag/resref " + x.Address.InstanceTag + ")"); MessageBox.Show(String.Format("There's no {0} like this (with tag '{1}') in any area that's open.\nMake sure that the area containing " + "the {0} is open when you try to save, or it won't work.", x.Address.TargetType, x.Address.InstanceTag)); return(false); } catch (Exception x) { string errorMessage = x.ToString(); if (errorMessage.Contains("flip_functions")) { try { string path = Path.Combine(NWN2Toolset.NWN2.IO.NWN2ResourceManager.Instance.OverrideDirectory.DirectoryName, "flip_functions.nss"); if (!File.Exists(path)) { MessageBox.Show("File " + path + " is missing. Scripts will not compile successfully. Please re-install Flip."); return(false); } } catch (Exception) {} } MessageBox.Show(String.Format("Something went wrong when saving the script.{0}{0}{1}", Environment.NewLine, errorMessage)); return(false); } }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { sw.AppendLine("else"); FormatBranch(sw, formatterContext, services, GetBodyInstructions()); }
/// <summary> /// Wraps the quotes around the rendering of the text object /// escapes internal quotes and new lines /// </summary> /// <param name="e"></param> protected override void OnRender(RenderingEventArgs e) { base.OnRender(e); IScriptWriter writer = e.Writer; if (this.Layout == ScriptLayout.Block) writer.WriteNewLineAndIndent(); string quote = this.DoubleQuotes ? "\"" : "'"; if (Text == null) writer.Write(quote + quote); // as we have to process the contents we will have to render it seperately StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw, e.Writer); // use same format provider sw.Write(this.Text); string text = tw.ToString(); // now process it text = text.Replace(quote, @"\" + quote); text = text.Replace(Environment.NewLine, "\\n\\r"); writer.Write(quote + text + quote); }
/// <summary> /// Adds a text node to the parent element which contains the supplied text /// </summary> /// <param name="parentElement"></param> public void Render(XmlElement parentElement) { XmlDocument doc = parentElement.OwnerDocument; // as we have to process the contents we will have to render it seperately StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw); // use same format provider sw.Write(this.Text); string text = tw.ToString(); XmlText textNode = doc.CreateTextNode(text); parentElement.AppendChild(textNode); }
protected override void DeparseDerivedTableNode(ScriptWriter writer, IQsiDerivedTableNode node, QsiScript script) { if (node is CqlDerivedTableNode cqlNode) { writer.Write("SELECT "); if (cqlNode.IsJson) { writer.Write("JSON "); } if (cqlNode.IsDistinct) { writer.Write("DISTINCT "); } if (node.Columns != null) { DeparseTreeNode(writer, node.Columns, script); } writer.WriteSpace(); writer.Write("FROM "); DeparseTreeNode(writer, node.Source, script); if (node.Where != null) { writer.WriteSpace(); DeparseTreeNode(writer, node.Where, script); } if (node.Grouping != null) { writer.WriteSpace(); DeparseTreeNode(writer, node.Grouping, script); } if (node.Order != null) { writer.WriteSpace(); DeparseTreeNode(writer, node.Order, script); } if (!cqlNode.PerPartitionLimit.IsEmpty) { writer.WriteSpace(); writer.Write("PER PARTITION LIMIT "); DeparseTreeNode(writer, cqlNode.PerPartitionLimit.Value, script); } if (node.Limit != null) { writer.WriteSpace(); DeparseTreeNode(writer, node.Limit, script); } if (cqlNode.AllowFiltering) { writer.WriteSpace(); writer.Write("ALLOW FILTERING"); } return; } base.DeparseDerivedTableNode(writer, node, script); }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { sw.AppendLine($"return {nameof(IRET)}({Unknown});"); }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .StaticType(nameof(IFieldService)) .Method(nameof(IFieldService.FadeIn)) .Comment(nameof(FadeIn));
public void Compressed() { Script script = Sb.Script(); AddJavaScript(script); StringWriter sw = new StringWriter(); ScriptWriter writer = new ScriptWriter(sw, JsFormatProvider.Instance); writer.IndentText = String.Empty; writer.NewLine = String.Empty; script.Render(writer); Console.WriteLine(sw.ToString()); }
public TeeScriptWriter(ScriptWriter scriptWriter) { _writers.Add(scriptWriter); }
public void FullWrite() { Script script = new Script(); AddScript(script); TextWriter stringWriter = new StringWriter(); ScriptWriter scriptWriter = new ScriptWriter(stringWriter); script.Render(scriptWriter); string result = stringWriter.ToString(); Console.WriteLine(result); }
public TeeScriptWriter(ScriptWriter scriptWriter1, ScriptWriter scriptWriter2) { _writers.Add(scriptWriter1); _writers.Add(scriptWriter2); }
/// <summary> /// Adds the attribute to the supplied element /// </summary> /// <param name="parentElement"></param> public void Render(XmlElement parentElement) { // as we have to process the contents we will have to render it seperately StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw); // use same format provider sw.Write(this.Value); string text = tw.ToString(); parentElement.SetAttribute(this.Name, text); }
/// <nodoc /> public DScriptPrettyPrintVisitor(ScriptWriter writer, bool attemptToPreserveNewlinesForListMembers = true) : base(writer, onlyPrintHeader: false, attemptToPreserveNewlinesForListMembers: attemptToPreserveNewlinesForListMembers) { }
private static void WriteOutput(TextWriter writer, DdlWriterCommandLine cmdLine) { try { // load the persistent store defined by the current set of binaries var store = (PersistentStore)PersistentStoreRegistry.GetDefaultStore(); // get config // run pre-processors var preProcessor = new PreProcessor(cmdLine.CreateIndexes, cmdLine.AutoIndexForeignKeys); preProcessor.Process(store); // if this is an upgrade, load the baseline model file RelationalModelInfo baselineModel = null; if (!string.IsNullOrEmpty(cmdLine.BaselineModelFile)) { var serializer = new RelationalModelSerializer(); baselineModel = serializer.ReadModel(File.OpenText(cmdLine.BaselineModelFile)); } switch (cmdLine.Format) { case DdlWriterCommandLine.FormatOptions.sql: // create script writer and set properties based on command line var scriptWriter = new ScriptWriter(store) { Options = new RelationalSchemaOptions { EnumOption = cmdLine.EnumOption, SuppressForeignKeys = !cmdLine.CreateForeignKeys, SuppressUniqueConstraints = !cmdLine.CreateUniqueKeys, NamespaceFilter = new RelationalSchemaOptions.NamespaceFilterOption(cmdLine.Namespace) }, QualifyNames = cmdLine.QualifyNames, BaselineModel = baselineModel }; // decide whether to write a creation or upgrade script, depending on if a baseline was supplied if (baselineModel == null) scriptWriter.WriteCreateScript(writer); else scriptWriter.WriteUpgradeScript(writer); break; case DdlWriterCommandLine.FormatOptions.xml: // we don't currently support outputting upgrades in XML format if (baselineModel != null) throw new NotSupportedException("Upgrade is not compatible with XML output format."); var serializer = new RelationalModelSerializer(); var relationalModelInfo = new RelationalModelInfo(store, new RelationalSchemaOptions.NamespaceFilterOption(cmdLine.Namespace)); serializer.WriteModel(relationalModelInfo, writer); break; default: throw new NotSupportedException(string.Format("{0} is not a valid output format.", cmdLine.Format)); } } catch (Exception e) { Log(e, LogLevel.Error); } }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { // This instruction is part of conditional jumps and isn't exists as is. }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .StaticType(nameof(IGameplayService)) .Property(nameof(IGameplayService.IsRandomBattlesEnabled)) .Assign(true) .Comment(nameof(BattleOff));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .StaticType(nameof(IGameplayService)) .Property(nameof(IGameplayService.IsUserControlEnabled)) .Assign(false) .Comment(nameof(UCOff));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .StaticType(nameof(IMusicService)) .Method(nameof(IMusicService.ChangeMusicVolume)) .Argument("volume", _volume) .Argument("flag", _flag) .Comment(nameof(MUSICVOL));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .Property(nameof(FieldObject.Model)) .Property(nameof(FieldObjectInteraction.SoundFootsteps)) .Assign(true) .Comment(nameof(FootStepOn));
public void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { String name = formatterContext.GetObjectNameByIndex(_fieldObjectId.Value); sw.Append($"typeof({name})"); }
public virtual void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.AppendLine(this.ToString());
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .StaticType(nameof(ISalaryService)) .Property(nameof(ISalaryService.IsSalaryEnabled)) .Assign(true) .Comment(nameof(SaralyOn));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .Property(nameof(FieldObject.Model)) .Method(nameof(FieldObjectModel.SetHitBox)) .Argument("p1", _p1.ToString()) .Argument("p2", _p2.ToString()) .Comment(nameof(SETLINE));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .Property(nameof(FieldObject.Model)) .Property(nameof(FieldObjectInteraction.IsTalkScriptActive)) .Assign(true) .Comment(nameof(TALKON));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .Property(nameof(FieldObject.Model)) .Method(nameof(FieldObjectModel.Show)) .Comment(nameof(Show));
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { formatterContext.GetObjectScriptNamesById(_scriptId, out String typeName, out String methodName); sw.AppendLine($"{nameof(REQSW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());"); }
private static void WriteBool(ScriptWriter writer, ImmutableContextBase context, object value) { writer.AppendToken((bool)value == true ? "true" : "false"); }
public void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) { FormatHelper.FormatGlobalGet(_globalVariable, Jsm.GlobalUInt32, sw, formatterContext, services); }
private static void WriteInt(ScriptWriter writer, ImmutableContextBase context, object value) { writer.AppendToken(((int)value).ToString(CultureInfo.InvariantCulture)); }
/// <summary> /// Provide a string representation of the object /// using a javascript format provider /// </summary> /// <param name="o"></param> /// <param name="indentations">number of indentations to start with</param> /// <returns></returns> public static string Render(object o, int indentations) { if (o == null) return String.Empty; StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw, JsFormatProvider.Instance); sw.CurrentIndentLevel = indentations; sw.Write(o); return tw.ToString(); }
private static void WriteString(ScriptWriter writer, ImmutableContextBase context, object value) { writer.AppendQuotedString((string)value, false); }
protected override void OnRender(ScriptWriter writer, bool multiLine, bool startOnNewLine) { EnsureBuilt(); Content.Render(writer); }
private static void WriteEnumValue(ScriptWriter writer, ImmutableContextBase context, object value) { var enumValue = (EnumValue)value; writer.AppendToken(enumValue.Name.ToString(context.StringTable)); }
/// <summary> /// render the class /// </summary> /// <param name="e"></param> protected override void OnRender(RenderingEventArgs e) { base.OnRender(e); // work out the class name StringWriter tw = new StringWriter(); ScriptWriter sw = new ScriptWriter(tw, e.Writer); // use same format provider sw.Write(this.ClassName); string className = tw.ToString(); Script script = Sb.Script(); string nameSpace = ExtJs.GetNamespace(className); Script constructor = Sb.Script(); if (!String.IsNullOrEmpty(nameSpace)) script.Add(Js.Statement(Js.Call("Ext.ns", Js.Q(nameSpace)))); // register namespace script.AddRange( Js.Statement(ClassName, " = ", Js.Function(ScriptLayout.InlineBlock, Parameters, Constructor ) ), Js.Statement(Js.Call("Ext.extend",ClassName,BaseClass)) // make it inherit from base class ); e.Writer.Write(script); }
private static void WriteStringId(ScriptWriter writer, ImmutableContextBase context, object value) { var stringId = (StringId)value; writer.AppendToken(stringId.IsValid ? stringId.ToString(context.StringTable) : "invalid"); }
private static void WriteObjectLiteralSlim(ScriptWriter writer, ImmutableContextBase context, object value) { var literal = (ObjectLiteral)value; WriteObjectLiteral(writer, context, literal); }
public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services) .StaticType(nameof(IRenderingService)) .Method(nameof(IRenderingService.Wait)) .Comment(nameof(ColSync));