TextCache
Index
Constructors
constructor
Creates a new TextCache from the provided CSV file path.
Parameters
path: string
The path to the CSV lookup file for this TextCache instance
_build_cache: boolean = true
Returns TextCache
Properties
cache
language
loaded
path
rebuildListeners
Methods
buildCache
Kicks off a build of the text lookup cache
Returns Promise<void>
buildTranslations
Maps lines of a CSV to equivalent CSV lines with values translated according to the corresponding translation file
Parameters
lines: string[][]
An array of string arrays corresponding to lines in the CSV file
translations: string[]
An array of strings in translation file format (with EN and translated values on alternate lines)
Returns string[][]
- An array of string arrays corresponding to lines in the CSV file with the values translated to the current game language
cacheLines
Stores the contents of a CSV file in the TextCache's internal cache
Parameters
lines: string[][]
An array of string arrays corresponding to lines in the CSV file
Returns void
- Nothing
fetchCsv
Fetches and parses the CSV file for this TextCache
Returns Promise<string[][]>
- A promise resolving to an array of string arrays, corresponding to lines of CSV values in the CSV file.
fileName
Return the basename of the cached file
Returns string
get
Looks up a string from this TextCache. If the cache contains a value for the provided key and a translation is available, the return value will be automatically translated. Otherwise the EN string will be used. If the cache does not contain a value for the requested key, the key will be returned.
Parameters
key: string
The text key to lookup
Returns string
- The text value corresponding to the provided key, translated into the current language, if available
log
Parameters
msg: any
Returns void
onRebuild
Adds a callback function as a rebuild listener. Rebuild listeners will be called whenever the cache has completed a rebuild (either after initial construction, or after a language change).
Parameters
callback: (cache?: TextCache) => void
The callback to register
optionalimmediate: boolean = true
Whether or not the callback should be called on registration
Returns Function
- A callback function which can be used to unsubscribe the added listener
translate
Translates the contents of a CSV file into the current game language
Parameters
lines: string[][]
An array of string arrays corresponding to lines in the CSV file
Returns Promise<string[][]>
- A promise resolving to an array of string arrays corresponding to lines in the CSV file with the values translated to the current game language
staticbuildAsync
Creates a new TextCache from the provided CSV file path asynchronously, promising its return after the cache has been build.
Parameters
path: string
The path to the CSV lookup file for this TextCache instance
Returns Promise<TextCache>
A class that can be used to cache a simple key/value CSV file for easy text lookups. Text lookups will be automatically translated to the game's current language, if a translation is available.