Word Game Builder 2.0.1f2
Reference Manual
Public Member Functions | Static Public Member Functions | Properties | List of all members
WordGameLanguage Class Reference

Represents a language for a word game. More...

+ Inheritance diagram for WordGameLanguage:
+ Collaboration diagram for WordGameLanguage:

Public Member Functions

void ClearCulture ()
 Clears the culture of a language, resetting it to use the invariant culture. More...
 
void ClearRandomLetterCache ()
 Clears the cache of random letters. More...
 
WordGameLanguage Copy ()
 Deep copy this language to a new language. A unique name will be assigned to the language identifier. More...
 
WordGameLanguage Copy (string newName, string newIdentifier)
 Deep copy this language to a new language. More...
 
void ExportLettersToCsv (Stream stream)
 Exports the letters of a language to a CSV file. More...
 
void ExportWordsToCsv (Stream stream)
 Exports the words of a language to a CSV file. More...
 
Letter GetLetter (string letter)
 Gets the Letter struct for the specified string (Letter.text). More...
 
Letter GetLetter (char letterValue)
 Gets the Letter struct for the specified character value (Letter.character). More...
 
Letter GetRandomLetter ()
 Gets a random letter from the language's alphabet. More...
 
Letter GetRandomLetter (bool weighted)
 Gets a random letter from the language's alphabet. More...
 
IList< LetterGetRandomLetters (int count)
 Gets a list of random letters from the language's alphabet, up to the specified count. More...
 
IList< LetterGetRandomLetters (int count, bool weighted)
 Gets a list of random letters from the language's alphabet, up to the specified count. More...
 
System.Random GetRandomNumberGenerator ()
 Gets the psuedo-random number generator for the language. More...
 
string GetRandomWord ()
 Gets a random word from the language. More...
 
string GetRandomWord (int maxLetters)
 Gets a random word from the language, ensuring that it is under the maximum amount of letters. More...
 
IList< string > GetWords ()
 Gets an array of all words in the language. More...
 
void ImportLettersFromCsv (Stream stream)
 Imports the letters of a language from a CSV stream. More...
 
void ImportWordsFromCsv (Stream stream)
 Imports the words of a language from a CSV file. More...
 
void ImportWordsFromCsv (Stream stream, bool append)
 Imports the words of a language from a CSV file. More...
 
Letter NextLetter (Letter firstLetter)
 Gets the next letter in the language's alphabet. More...
 
Letter NextLetter (Letter firstLetter, bool wrap)
 Gets the next letter in the language's alphabet. More...
 
Letter PreviousLetter (Letter firstLetter)
 Gets the previous letter in the language's alphabet. More...
 
Letter PreviousLetter (Letter firstLetter, bool wrap)
 Gets the previous letter in the language's alphabet. More...
 
void SetCulture (string cultureCode)
 Sets the culture of a language. More...
 
void SetRandomNumberGenerator (int seed)
 Sets the psuedo-random number generator for the language. The pRNG's seed is time-based by default. More...
 
override string ToString ()
 Returns a string that represents the current language. More...
 

Static Public Member Functions

static WordGameLanguage Create (string name, string identifier)
 Creates a language with the given name and identifier (file name). More...
 
static WordGameLanguage FindByIdentifier (string identifier)
 Finds a loaded language by identifier. More...
 
static WordGameLanguage FindByName (string name)
 Finds the first occurance of a loaded language by name. More...
 
static void LoadAllLanguages ()
 Loads all language files from resources. More...
 
static WordGameLanguage LoadLanguage (string identifier)
 Loads a language by identifier (file name). More...
 
static void RemoveAll ()
 Completely unloads all languages. More...
 
static void RemoveByIdentifier (string identifier)
 Unloads a language by identifier. More...
 
static void RemoveByName (string name)
 Unloads the first occurance of a language by name. More...
 

Properties

bool allowBlanks [get, set]
 Gets or sets whether the language should allow blank or wildcard letters. More...
 
int blankLetterWeight [get, set]
 Gets or sets the weight of blank letters for random distribution. More...
 
bool caseSensitive [get, set]
 Gets or sets whether string lookups should be case-sensitive. More...
 
CultureInfo culture [get]
 The language's culture. More...
 
string cultureName [get]
 The language's culture code. More...
 
static WordGameLanguage current [get, set]
 Gets or sets the current language. More...
 
static bool decompressOnLoad [get, set]
 Should a language automatically be decompressed on load? More...
 
static string defaultLanguage [get, set]
 Gets or sets the default language, by name. This value is saved to PlayerPrefs. More...
 
string identifier [get, set]
 Gets or sets the language's identifier (usually the file name). More...
 
string languageName [get, set]
 Gets or sets the language name. More...
 
IList< Letterletters [get]
 Gets the list of letters in the language. More...
 
int wordCount [get]
 Gets the number of words in the language. More...
 
WordSet wordSet [get]
 The WordSet data structure of the language. More...
 

Detailed Description

Represents a language for a word game.

Most aspects of a language are edited through the Language Editor.

Member Function Documentation

void ClearCulture ( )
inline

Clears the culture of a language, resetting it to use the invariant culture.

void ClearRandomLetterCache ( )
inline

Clears the cache of random letters.

This needs to be called manually if you use a random letter method and change letter information or enable/disable blank letters at runtime.

WordGameLanguage Copy ( )
inline

Deep copy this language to a new language. A unique name will be assigned to the language identifier.

Returns
The newly copied language.

> The language's random number generator is not deep copied with this method.

+ Here is the call graph for this function:

WordGameLanguage Copy ( string  newName,
string  newIdentifier 
)
inline

Deep copy this language to a new language.

Parameters
newNameThe name of the new language.
newIdentifierThe idenfitier of the new language. Must be unique.
Returns
The newly copied language. This language will not be expanded and must be decompressed. Runtime sets will not be copied.

> The language's random number generator is not deep copied with this method.

+ Here is the call graph for this function:

static WordGameLanguage Create ( string  name,
string  identifier 
)
inlinestatic

Creates a language with the given name and identifier (file name).

Parameters
nameThe new language name.
identifierThe new language identifier. Must be unique.
Returns
The created language.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExportLettersToCsv ( Stream  stream)
inline

Exports the letters of a language to a CSV file.

Parameters
streamThe stream to export letters to.

After exporting, the stream must be closed manually.

void ExportWordsToCsv ( Stream  stream)
inline

Exports the words of a language to a CSV file.

Parameters
streamThe stream to export letters to.

After exporting, the stream must be closed manually.

+ Here is the call graph for this function:

static WordGameLanguage FindByIdentifier ( string  identifier)
inlinestatic

Finds a loaded language by identifier.

Parameters
identifierThe identifier to search for.
Returns
The found language, or null if no language was found.

.

+ Here is the caller graph for this function:

static WordGameLanguage FindByName ( string  name)
inlinestatic

Finds the first occurance of a loaded language by name.

Parameters
nameThe name to search for.
Returns
The found language, or null if no language was found.

.

+ Here is the caller graph for this function:

Letter GetLetter ( string  letter)
inline

Gets the Letter struct for the specified string (Letter.text).

Parameters
letterThe letter string to search for.
Returns
A Letter struct representing the specified string.

+ Here is the caller graph for this function:

Letter GetLetter ( char  letterValue)
inline

Gets the Letter struct for the specified character value (Letter.character).

Parameters
letterValueThe letter character value to search for.
Returns
A Letter struct representing the specified character value.
Letter GetRandomLetter ( )
inline

Gets a random letter from the language's alphabet.

Uses a weighted distribution based on score by default.

Returns
A weighted random letter.
Letter GetRandomLetter ( bool  weighted)
inline

Gets a random letter from the language's alphabet.

Uses a weighted distribution based on score by default.

Parameters
weightedIf true, a weighted distribution of letters will be used, based on score.
Returns
A random letter.
IList<Letter> GetRandomLetters ( int  count)
inline

Gets a list of random letters from the language's alphabet, up to the specified count.

Uses a weighted distribution based on score by default.

Parameters
countThe amount of random letters to obtain.
Returns
A list of random letters.
IList<Letter> GetRandomLetters ( int  count,
bool  weighted 
)
inline

Gets a list of random letters from the language's alphabet, up to the specified count.

Uses a weighted distribution based on score by default.

Parameters
countThe amount of random letters to obtain.
weightedIf true, a weighted distribution of letters will be used, based on score.
Returns
A list of random letters.
System.Random GetRandomNumberGenerator ( )
inline

Gets the psuedo-random number generator for the language.

The pRNG is used for picking random letters, random words, and lossy prefix search.

Returns
The language's random number generator.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string GetRandomWord ( )
inline

Gets a random word from the language.

Returns
A random word from the language.
string GetRandomWord ( int  maxLetters)
inline

Gets a random word from the language, ensuring that it is under the maximum amount of letters.

This is a recursive random search and hard-capped at 10,000 iterations (it returns null on failure). It is recommended to prune unused words from the language to help ensure this search does not fail.

Parameters
maxLettersThe maximum amount of letters permitted for a random word.
Returns
A random word from the language, up to maxLetters.
IList<string> GetWords ( )
inline

Gets an array of all words in the language.

This is a very expensive operation and is usually not needed.

Returns
An list of all words. This array can be very large!
void ImportLettersFromCsv ( Stream  stream)
inline

Imports the letters of a language from a CSV stream.

Parameters
streamThe stream to import letters from.

After importing, the stream must be closed manually.

+ Here is the caller graph for this function:

void ImportWordsFromCsv ( Stream  stream)
inline

Imports the words of a language from a CSV file.

Parameters
streamThe stream to import words from.

After importing, the stream must be closed manually.

+ Here is the caller graph for this function:

void ImportWordsFromCsv ( Stream  stream,
bool  append 
)
inline

Imports the words of a language from a CSV file.

Parameters
streamThe stream to import words from.
appendIf true, append the words to the current set.

After importing, the stream must be closed manually.

static void LoadAllLanguages ( )
inlinestatic

Loads all language files from resources.

+ Here is the caller graph for this function:

static WordGameLanguage LoadLanguage ( string  identifier)
inlinestatic

Loads a language by identifier (file name).

Parameters
identifierThe language identifier to load.
Returns
The loaded language.

+ Here is the caller graph for this function:

Letter NextLetter ( Letter  firstLetter)
inline

Gets the next letter in the language's alphabet.

Wraps back to the first letter by default. If allowBlanks is enabled, includes a blank letter at the end of the alphabet.

Parameters
firstLetterThe letter to move from.
Returns
The next letter in the alphabet.
Letter NextLetter ( Letter  firstLetter,
bool  wrap 
)
inline

Gets the next letter in the language's alphabet.

If allowBlanks is enabled, includes a blank letter at the end of the alphabet.

Parameters
firstLetterThe letter to move from.
wrapIf true, wrap to the first letter if this is run on the last letter.
Returns
The next letter in the alphabet.
Letter PreviousLetter ( Letter  firstLetter)
inline

Gets the previous letter in the language's alphabet.

Wraps back to the last letter by default. If allowBlanks is enabled, includes a blank letter at the end of the alphabet.

Parameters
firstLetterThe letter to move from.
Returns
The previous letter in the alphabet.
Letter PreviousLetter ( Letter  firstLetter,
bool  wrap 
)
inline

Gets the previous letter in the language's alphabet.

If allowBlanks is enabled, includes a blank letter at the end of the alphabet.

Parameters
firstLetterThe letter to move from.
wrapIf true, wrap to the last letter if this is run on the first letter.
Returns
The previous letter in the alphabet.
static void RemoveAll ( )
inlinestatic

Completely unloads all languages.

This method does not delete the actual language file, to prevent unintentional data loss.

+ Here is the call graph for this function:

static void RemoveByIdentifier ( string  identifier)
inlinestatic

Unloads a language by identifier.

This method does not delete the actual language file, to prevent unintentional data loss.

Parameters
identifierThe identifier to search for.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void RemoveByName ( string  name)
inlinestatic

Unloads the first occurance of a language by name.

This method does not delete the actual language file, to prevent unintentional data loss.

Parameters
nameThe name to search for.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SetCulture ( string  cultureCode)
inline

Sets the culture of a language.

Parameters
cultureCodeThe culture code to set.

This will trigger a re-optimization of the language.

+ Here is the call graph for this function:

void SetRandomNumberGenerator ( int  seed)
inline

Sets the psuedo-random number generator for the language. The pRNG's seed is time-based by default.

Parameters
seedThe random seed to assign to the language.

The pRNG is used for picking random letters, random words, and lossy prefix search.

override string ToString ( )
inline

Returns a string that represents the current language.

Returns
A string that represents the current language.

Property Documentation

bool allowBlanks
getset

Gets or sets whether the language should allow blank or wildcard letters.

int blankLetterWeight
getset

Gets or sets the weight of blank letters for random distribution.

Must be positive. Higher values = less occurances.

bool caseSensitive
getset

Gets or sets whether string lookups should be case-sensitive.

If disabled, all data is normalized to upper-case.

CultureInfo culture
get

The language's culture.

Returns the invariant culture by default.

string cultureName
get

The language's culture code.

WordGameLanguage current
staticgetset

Gets or sets the current language.

If the current language is not set, this property returns the default language (if available), or the first loaded language. If no languages are loaded, this property attempts to load all langauges with Language.LoadLanguages(). Due to how Unity compares objects, this property is not thread-safe. To get around this, cache the language first.

bool decompressOnLoad
staticgetset

Should a language automatically be decompressed on load?

Note that this only applies to languages called with Language.current. Other languages will only decompress if set to the current language.

string defaultLanguage
staticgetset

Gets or sets the default language, by name. This value is saved to PlayerPrefs.

This is initially set to English.

string identifier
getset

Gets or sets the language's identifier (usually the file name).

string languageName
getset

Gets or sets the language name.

IList<Letter> letters
get

Gets the list of letters in the language.

This list is automatically sorted in alphabetical order, based on the language's culture. Modifying this list may automatically trigger word list optimization.

int wordCount
get

Gets the number of words in the language.

WordSet wordSet
get

The WordSet data structure of the language.

This holds all of a language's words.