cstdotnet/usage.md
Tony Bark 0ff7bb68c4 UIText class
The UIText class allows for travseing in "/<directory>/<language>.dir"  directories and searching for CST files by their Id number.  See usage.md for more info.
2020-12-13 07:48:15 -05:00

1.7 KiB

Usage

Basic Parsing

1 ^The quick brown fox jumps over the lazy dog.^
#r "nuget:Sixam.CST,1.1"
using System;
using System.IO;
using Sixam.CST;

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

Console.WriteLine(example);

See working example on .NET Fiddle.

Complex Scenarios

In production, CST files were used in The Sims Online (TSO) 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.cst1

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"
using Sixam.CST;

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

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

Note that GetText() remains unchanged because the translation is expected to be same id and key, despite being in a different directory.

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" },
};

  1. TSO only supported English. ↩︎