private static void FormatCodeBlock(this string text, int indent, List <string> lines) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (lines == null) { throw new ArgumentNullException(nameof(lines)); } int beginPos = 0; int endPos = 0; void AddCodeLines(string txt, int idt, List <string> list) { string[] items = txt.SplitBlockLine(); list.AddRange(items.Where(l => l.Length > 0) .Select(l => l.SetIndent(idt)) .ToArray()); } if (GetBlockPositions(text, ref beginPos, ref endPos) == true) { AddCodeLines(text.Partialstring(0, beginPos - 1), indent, lines); if (BlockStartPrefix.Equals(Environment.NewLine)) { lines.Add(BlockStart.ToString().SetIndent(indent)); } else { lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockStartPrefix}{BlockStart}"; } text.Partialstring(beginPos + 1, endPos - 1).FormatCodeBlock(indent + 1, lines); if (BlockEndPrefix.Equals(Environment.NewLine)) { lines.Add(BlockEnd.ToString().SetIndent(indent)); } else { lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockEndPrefix}{BlockEnd}"; } text.Partialstring(endPos + 1, text.Length - 1).FormatCodeBlock(indent, lines); } else { AddCodeLines(text, indent, lines); } }
public void StartBlock(IEntity source, List <QueueAction> qa, BlockStart gameBlock = null) { if (qa == null) { Game.OnBlockEmpty(gameBlock); return; } #if _QUEUE_DEBUG DebugLog.WriteLine("Queue (Game " + Game.GameId + "): Spawning new queue at depth " + (Depth + 1) + " for " + source.ShortDescription + " with actions: " + string.Join(" ", qa.Select(a => a.ToString())) + " for action block: " + (gameBlock?.ToString() ?? "none")); #endif QueueStack.Push(Queue); Queue = new Deque <QueueActionEventArgs>(); BlockStack.Push(gameBlock); EnqueueDeferred(source, qa); }