Module: wk/util/concretize

Methods


<static> concretize(p_config, p_environment, p_specials, p_level)

Computes a concrete value, if a template value is passed. Otherwise the original value is returned. Templates are:
  • An array with at least two elements whose first element is "@some". For such an array some of its other elements is returned randomly.
  • An object that contains two special attributes named "@min" and "@max". The values of those attributes have to be numbers. Returned is a random value within the interval defined by "@min" and "@max". There are further attributes that affect the computation of the random value:
    • "@integer": true/false: If true, an integer value is computed within the interval [@min, @max]. If false, a float value is computed within the interval [@min, @max[.
    • "@positive": value: The value has to be a number greater or equal 0 and less or equal 1. The randomly computed number is with a probability of value a member of [@min, @max] or [@min, @max[ resp. and with a probability of 1-value a member of [-@max, -@min] or [-@max, -@min[.
    • "@relative": "name" (a string value): The computed value is multiplied with the environment value p_environment[name], if that value exists.
  • {"@stringToHeX": "#AFFE00"}: A six byte color key is converted into the corresponding integer code of that color. This is needed by PixiJS, as that library can only deal with integer color codes instead of string color codes. Hex values, such as 0xAFFE00 which are accepted by PixiJS, on the other sides, cannot be stored in JSON-Files....
  • "@@NAME": Two @-symbols at the beginning of a key name (including "@@some") are replace by one. So, those keys are not concretized by the first invocation of this function but by the second. If the key name starts with more then two @-symbols, concretize must applied correspondingly often to concretize the value associated.
Parameters:
Name Type Argument Description
p_config Object An object which may contain a @-values that have to be replaced by concrete values.
p_environment Object An object containing base values which can be referred by @-values. The environment is stored and reused by later calls, if no new environment is passed by those calls.
p_specials Array.<String> If not null, only those specials are expanded that are member of the array p_specials.
p_level number <nullable>
The number of levels that shall be concretized recursively.
Source:
Returns:
The computed value if one has been computed, p_config otherwise.
Type
*