Show / Hide Table of Contents

Class TextAssetReader

An helper class that creates a virtual layer for reading text from mods and loose files.

Inheritance
Object
TextAssetReader
Namespace: DaggerfallWorkshop.Utility.AssetInjection
Assembly: Assembly-CSharp.dll
Syntax
public static class TextAssetReader

Methods

| Improve this Doc View Source

Merge<T>(List<T>, String, Func<T, Dictionary<String, fsData>, Boolean>)

Reads all text assets with the given name, which are expected to contain a list or array of items, and merges all contributes in a single collection. If an item, identified by isItemData, is found more than one time, all of its data is merged in a single instance following mods load order.

Declaration
public static void Merge<T>(List<T> items, string name, Func<T, Dictionary<string, fsData>, bool> isItemData = null)
    where T : new()
Parameters
Type Name Description
List<T> items

A collection of items, which may be non-empty.

String name

Name of serialized text assets.

Func<T, Dictionary<String, FullSerializer.fsData>, Boolean> isItemData

A delegate that checks if serialized data of an item, provided as a dictionary, can be deserialized on top of the given item.

Type Parameters
Name Description
T

Type of each item, which can be a struct or a class.

| Improve this Doc View Source

ReadAll(String, String)

Gets content of all text files from loose files and text assets from mods inside the given relative directory. A folder named 'Assets' (i.e. Assets/Game/Mods/ExampleMod/Assets) is the equivalent of the 'StreamingAssets' folder on disk.

Declaration
public static List<string> ReadAll(string relativeDirectory, string extension = null)
Parameters
Type Name Description
String relativeDirectory

Relative path to a directory with forward slashes (i.e. 'Data/Foo' for 'Assets/Data/Foo' and 'StreamingAssets/Data/Foo').

String extension

The extension without leading dot (i.e. 'txt' for 'foo.txt') or null to match all extensions.

Returns
Type Description
List<String>

A list of text contents.

| Improve this Doc View Source

ReadAll<T>(String, String)

Gets deserialized content of all text files from loose files and text assets from mods inside the given relative directory. A folder named 'Assets' (i.e. Assets/Game/Mods/ExampleMod/Assets) is the equivalent of the 'StreamingAssets' folder on disk.

Declaration
public static IEnumerable<T> ReadAll<T>(string relativeDirectory, string extension = null)
Parameters
Type Name Description
String relativeDirectory

Relative path to a directory with forward slashes (i.e. 'Data/Foo' for 'Assets/Data/Foo' and 'StreamingAssets/Data/Foo').

String extension

The extension without leading dot (i.e. 'json' for 'foo.json') or null to match all extensions.

Returns
Type Description
IEnumerable<T>

A list of parsed contents.

Type Parameters
Name Description
T
| Improve this Doc View Source

TryRead(String, out String)

Gets content of a text file from loose files or a text asset from mods. A folder named 'Assets' (i.e. Assets/Game/Mods/ExampleMod/Assets) is the equivalent of the 'StreamingAssets' folder on disk.

Declaration
public static bool TryRead(string relativePath, out string content)
Parameters
Type Name Description
String relativePath

Relative path to text asset with forward slashes (i.e. 'Data/foo.json' for 'Assets/Data/foo.json' and 'StreamingAssets/Data/foo.json').

String content

Read content of text asset or null.

Returns
Type Description
Boolean

True if file found.

| Improve this Doc View Source

TryRead<T>(String, out T)

Gets deserialized content of a text file from loose files or a text asset from mods. A folder named 'Assets' (i.e. Assets/Game/Mods/ExampleMod/Assets) is the equivalent of the 'StreamingAssets' folder on disk.

Declaration
public static bool TryRead<T>(string relativePath, out T data)
Parameters
Type Name Description
String relativePath

Relative path to text asset with forward slashes (i.e. 'Data/foo.json' for 'Assets/Data/foo.json' and 'StreamingAssets/Data/foo.json').

T data

Deserialized content or type default.

Returns
Type Description
Boolean

True if asset found and parsed.

Type Parameters
Name Description
T
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX