Pardon our dust! Docs for Yarn Spinner for Unity 3.2 and Yarn Spinner for Godot C# are on docs.yarnspinner.dev (the old docs site). Docs for Yarn Spinner for Unity 3.3 (pre-release, out ASAP), Yarn Spinner for Godot GDScript and Yarn Spinner for Unreal Engine (work in progress) are on /docs/ (the new docs site).

Utility

Utility methods for working with line tags.
public static class Utility

Inherits from System.Object

#Methods

#DetermineNodeConnections(string[])

Finds and collates every jump in every node.
public static List<List<GraphingNode>> DetermineNodeConnections(string[] YarnFileContents)

Parameters

  • YarnFileContentsstring[]
    The collection of yarn file content to parse and walk

Returns List: A list of lists of GraphingNode each containing a node, its jumps, and any positional info.

#ExtractStringBlocks(IEnumerable<Node>, ProjectDebugInfo)

Gets the collection of contiguous runs of lines in the provided nodes. Each run of lines is guaranteed to run to completion once entered.
public static List<List<string>> ExtractStringBlocks(IEnumerable<Node> nodes, ProjectDebugInfo projectDebugInfo)

Parameters

  • nodesSystem.Collections.Generic.IEnumerable<Yarn.Node>
    The nodes to get string blocks for.
  • An object containing debugging information for the project.

Returns List: A collection of runs of lines.

#GenerateYarnFileWithDeclarations(IEnumerable<Yarn.Compiler.Declaration>, string, IEnumerable<string>?, IDictionary<string, string>?)

Generates a Yarn script that contains a node that declares variables.
public static string GenerateYarnFileWithDeclarations(IEnumerable<Yarn.Compiler.Declaration> declarations, string title = "Program", IEnumerable<string>? tags = null, IDictionary<string, string>? headers = null)

Parameters

  • declarationsSystem.Collections.Generic.IEnumerable<Yarn.Compiler.Declaration>
    The collection of Declaration objects to include in the output.
  • titlestring
    The title of the node that should be generated.
  • tagsSystem.Collections.Generic.IEnumerable<string>
    The collection of tags that should be generated for the node. If this is null, no tags will be generated.
  • headersSystem.Collections.Generic.IDictionary<string, string>
    The collection of additional headers that should be generated for the node. If this is null, no additional headers will be generated.

Returns String: A string containing a Yarn script that declares the specified variables.

This method is intended to be called by tools that let the user manage variable declarations. Such tools can read the existing variable declarations in from a script (by compiling the script with the CompilationType value set to TypeCheck), allow the user to make changes, and then write the changes to disk by calling this method and saving the results.

#GetCompiledCodeAsString(Program, CompilationResult?)

Gets a string containing a representation of the compiled bytecode for a Program.
public static string GetCompiledCodeAsString(Program program, CompilationResult? result = null)

Parameters

Returns String

#GetRange(ParserRuleContext)

Gets the range covered by a ParserRuleContext in the source code.
public static Range GetRange(ParserRuleContext context)

Parameters

  • contextParserRuleContext
    The context to get a range for.

Returns Range: The Range covered by this context.

#GetYarnValue(IConvertible)

Returns an IYarnValue representation of the provided value.
public static IYarnValue? GetYarnValue(IConvertible clrValue)

Parameters

  • clrValueSystem.IConvertible
    The value to get a Yarn representation of.

Returns IYarnValue: An IYarnValue representation of clrValue.

#ParseSource(string) Obsolete

Use ParseSourceText

Parses a string of Yarn source code, and produces a FileParseResult and (if there were any problems) a collection of diagnostics.
public static (FileParseResult, IEnumerable<Diagnostic>) ParseSource(string source)

Parameters

  • sourcestring
    The source code to parse.

Returns ValueTuple: A tuple containing a FileParseResult that stores the parse tree and tokens, and a collection of Diagnostic objects that describe problems in the source code.

#ParseSourceText(string, string)

Parses a string of Yarn source code, and produces a FileParseResult.
public static FileParseResult ParseSourceText(string source, string sourceName = "<input>")

Parameters

  • sourcestring
    The source code to parse.
  • sourceNamestring
    The name of the source.

Returns FileParseResult: A FileParseResult representing the result of parsing the source.

#TagLines(ISourceInput, HashSet<string>?, ILineTagGenerator?, ILineTagGenerator.TagAbortBehaviour)

Given Yarn source code, adds line tags to the ends of all lines that need one and do not already have one.
public static (string ModifiedSource, ICollection<string> LineIDs, List<ILineTagGenerator.LineTaggingException> TagExceptions) TagLines(ISourceInput contents, HashSet<string>? excludedLineIDs = null, ILineTagGenerator? lineTagGenerator = null, ILineTagGenerator.TagAbortBehaviour tagAbortBehaviour = ILineTagGenerator.TagAbortBehaviour.CurrentNode)

Parameters

Returns ValueTuple: Tuple of the modified source code, with line tags added, an updated list of line IDs that were added, and any tagging exceptions that were encountered during tagging.

This method ensures that it does not generate line tags that are already present in the file.

Line tags are added to any line of source code that contains user-visible text: lines, options, and shortcut options.

#TagLines(string, HashSet<string>?, ILineTagGenerator?, ILineTagGenerator.TagAbortBehaviour)

Given Yarn source code, adds line tags to the ends of all lines that need one and do not already have one.
public static (string ModifiedSource, ICollection<string> LineIDs, List<ILineTagGenerator.LineTaggingException> TagExceptions) TagLines(string contents, HashSet<string>? excludedLineIDs = null, ILineTagGenerator? lineTagGenerator = null, ILineTagGenerator.TagAbortBehaviour tagAbortBehaviour = ILineTagGenerator.TagAbortBehaviour.CurrentNode)

Parameters

  • contentsstring
    The source code to add line tags to.
  • excludedLineIDsSystem.Collections.Generic.HashSet<string>
    A collection of line IDs that should not be used for generation. Primarily intended for other line tags from a different compilation job.
  • The line tag generator to use when generating a new line ID.
  • Controls how the line tagging should handle encountering issues while tagging.

Returns ValueTuple: Tuple of the modified source code, with line tags added, an updated list of line IDs that were added, and any tagging exceptions that were encountered during tagging.

This method ensures that it does not generate line tags that are already present in the file.

Line tags are added to any line of source code that contains user-visible text: lines, options, and shortcut options.

#TryGetNodeTitle(string?, YarnSpinnerParser.NodeContext, string?, string?, string?, string?)

Gets the title for a node as defined in the source code, along with its unique title (which may be different to the source title.)
public static bool TryGetNodeTitle(string? sourceFileName, YarnSpinnerParser.NodeContext nodeContext, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? sourceTitle, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? uniqueTitle, out string? subtitle, out string? nodeGroupName)

Parameters

  • sourceFileNamestring
    The name of the file in which the node is defined, or null if not available.
  • nodeContextYarn.Compiler.YarnSpinnerParser.NodeContext
    The parsed node's context.
  • sourceTitlestring
    On return, contains the title of the node, as it appears in the source code.
  • uniqueTitlestring
    On return, contains the unique title of the node, as stored in the output program.
  • subtitlestring
    The sub-title of the node, if present. This value is always null if the node is not in a node group.
  • nodeGroupNamestring
    The name of the node group the node is a member of, if any.

Returns Boolean: true if the sourceTitle and uniqueTitle could be determined; false otherwise.

#WithSeverityOverrides(IEnumerable<Diagnostic>, IDictionary<string, Diagnostic.DiagnosticSeverity>?)

Returns a collection of Diagnostic objects with overridden severities.
public static IEnumerable<Diagnostic> WithSeverityOverrides(this IEnumerable<Diagnostic> diagnostics, IDictionary<string, Diagnostic.DiagnosticSeverity>? overrides)

Parameters

  • diagnosticsSystem.Collections.Generic.IEnumerable<Yarn.Compiler.Diagnostic>
    The collection of Diagnostic objects to override the severities of.
  • overridesSystem.Collections.Generic.IDictionary<string, Yarn.Compiler.Diagnostic.DiagnosticSeverity>
    A dictionary of diagnostic codes to diagnostic severities.

Returns IEnumerable: The updated collection.

Generated from Yarn Spinner for Unity 3.3.