cstdotnet/usage.md
Tony Bark 229ab4f0ad This release drops .NET Standard in favor of .NET 6.
There are a lot of significant under the hood changes with the release. See the change log for details.
2021-11-19 13:52:26 -05:00

1.7 KiB

Usage

Basic Parsing

1 ^The quick brown fox jumps over the lazy dog.^
#r "nuget:Sixam.CST,1.1.100" // If using notebooks
using Sixam.CST;

var file = File.ReadAllText("example.cst");
var example = CaretSeparatedText.Parse(file, 1);

Console.WriteLine(example);

Complex Scenarios

In production, CST files were used in The Sims Online to provide translations It was required that they were prefixed with numbers enclosed in underscores, known as the ID. The IDs were used to locate the right file without knowing it's name. Meanwhile, each translation was split into their respective uitext/<languae>.dir directories:

  • uitext/english.dir/_154_miscstrings.cst
  • uitext/swedish.dir/_154_miscstrings.cst

Starting with 1.1, the UIText class provides methods that directorly map to these directories relative to the application's.

#r "nuget:Sixam.CST,1.1.100"
using Sixam.CST;

var english = new UIText(); // UIText assumes English
var swedish = new UIText("swedish");
var engExample = english.GetText(152, 1); // english.dir/_154_miscstrings.cst
var sweExample = swedish.GetText(152, 1); // swedish.dir/_154_miscstrings.cst

Console.WriteLine(engExample);
Console.WriteLine(sweExample);

Note that the IDs and keys in both GetText() examples remains the same. This is because it was historically assumed that the English and translations files were identical. However, the original never saw any new languages added.

Changing base directories

If you want to change the base directory, you can. Though, this is still a work in progress and not recommended.

#r "nuget:Sixam.CST,1.1"
using Sixam.CST;

var example = new UIText()
{
    BasePath = new[] { "gamedata", "uitext" },
};