FormatHelper Class
The format-helper contains a of functions usable inside of scripts or javascript formulas which are in regular used to calculate display text. The functions are technically not bound to a FormatHelper class. Example:
WRONG:
{
........
"valueFormula": "return FormatHelper.fmtNumVar(p.variable)"
}
CORRECT:
{
........
"valueFormula": "return fmtNumVar(p.variable)"
}
Item Index
Methods
fmtBoolVar
-
variableOrValue
Returns the display text for the specified boolean variable (Switch) or value. If the specified variable is actually a boolean value the boolean value will be returned without any formatting.
Parameters:
-
variableOrValue
Variable | Boolean- The variable or constant value.
Returns:
The formatted display text or the constant boolean value.
fmtColor
-
color
Returns the display text for the specified color.
Parameters:
-
color
Color- The color to get the display text for.
Returns:
The formatted display text.
fmtDocument
-
uid
Returns the display text for the specified document.
Parameters:
-
uid
String- The UID of the document to get the diplay text for.
Returns:
The formatted display text.
fmtDuration
-
durationValue
Returns the display text for a duration value. It converts the duration value, which is stored in frames internally, into milliseconds and adds "ms" suffix. So an input value of 60 results in "1000ms" display text. (If GS.CONST.GAME_FRAME_RATE is 60).
Parameters:
-
durationValue
Number- The duration value to get the display text for.
Returns:
The display text.
fmtListVar
-
variable
Returns the display text for the specified list variable.
Parameters:
-
variable
Variable- The list variable
Returns:
The formatted display text.
fmtNumVar
-
variableOrValue
Returns the display text for the specified number variable or value. If the specified variable is actually a number value the number value will be returned without any formatting.
Parameters:
-
variableOrValue
Variable | Number- The variable or constant value.
Returns:
The formatted display text or the constant number value.
fmtRecord
-
category
-
index
Returns the display text for the specified database record.
Parameters:
-
category
String- The database category name
-
index
Number- The index of the database record to get the display text for. The index starts at 0.
Returns:
The formatted display text.
fmtResource
-
resource
Returns the display text for a resource. The specified resource can also be a string variable.
Parameters:
-
resource
Resource- The resource to get the display text for.
Returns:
The display text.
fmtStrVar
-
variableOrValue
Returns the display text for the specified string variable or value. If the specified variable is actually a string value the string value will be returned without any formatting.
Parameters:
-
variableOrValue
Variable | String- The variable or constant value.
Returns:
The formatted display text or the constant string value.
fmtTone
-
tone
Returns the display text for the specified tone.
Parameters:
-
tone
Tone- The tone to get the display text for.
Returns:
The formatted display text.
fmtVar
-
variableOrValue
-
type
Returns the display text for the specified variable or value. If the specified variable is actually a constant value the value will be returned without any formatting.
Parameters:
-
variableOrValue
Variable | Number | String | Boolean- The variable or constant value.
-
type
String- The variable type, can be: "numbers", "strings", "booleans" or "lists".
Returns:
The formatted display text or the constant number value.
isVar
-
value
Indicates if the specified value is actually a variable.
Parameters:
-
value
Object- The value to check.
Returns:
If true the value is a variable. Otherwise false.
lcs
-
key
-
bundleName
Returns the translated phrase for the specified phrase-key. The name "lcs" originally stand for "Language Configuration String".
Parameters:
-
key
String- The phrase's key. It can also be
. to directly specify the bundle.
- The phrase's key. It can also be
-
bundleName
String- The name of the bundle to read the phrase from. Can be omitted if the bundle name is already specified in key-string.
Returns:
The translated phrase.
lcsg
-
text
Returns the text for the specified localizable string. It can be a localized string object like or a constant string. The function will check if a text for the lcId of the localized string object exists in the game's language configuration. If not, the defaultText property of the localized string object will be returned. If that property is null or not present the function returns:
STRING NOT FOUND:
If a constant string is specified the function will just return that string. The name "lcsg" originally stand for "Language Configuration String Game". See data-format reference for more info about LocalizedString object.
Parameters:
-
text
String | LocalizedString- The localized string object to get the text for.
Returns:
The text for the localized string object.
record
-
category
-
index
Returns database record at the specified index.
Parameters:
-
category
String- The database category name
-
index
Number- The index of the database record to get. The index starts at 0.
Returns:
The database record which is not the whole document but only the items.data content.
scase
-
value
-
values
-
results
Executes a quick switch-case on the specified values. For Example:
scase(1, [0, 1, 2], ["Apple", "Orange", "Banana"])
Output:
Orange
The name "scase" stands for "switch-case".
Parameters:
-
value
Object- The value to check.
-
values
Object- The values to check against.
-
results
Object- The result values.
Returns:
The matching value or null if none of the specified values matches.