File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var MATH = require ( '../../math' ) ;
2+ var GetObjectValue = require ( './GetObjectValue' ) ;
3+
4+ // Allowed types:
5+
6+ // Implicit
7+ // {
8+ // x: 4
9+ // }
10+ //
11+ // From function
12+ // {
13+ // x: function ()
14+ // }
15+ //
16+ // Randomly pick one element from the array
17+ // {
18+ // x: [a, b, c, d, e, f]
19+ // }
20+ //
21+ // Random integer between min and max:
22+ // {
23+ // x: { randInt: [min, max] }
24+ // }
25+ //
26+ // Random float between min and max:
27+ // {
28+ // x: { randFloat: [min, max] }
29+ // }
30+
31+ var GetAdvancedValue = function ( source , key , defaultValue )
32+ {
33+ var value = GetObjectValue ( source , key , null ) ;
34+
35+ if ( value === null )
36+ {
37+ return defaultValue ;
38+ }
39+ else if ( Array . isArray ( value ) )
40+ {
41+ return MATH . RND . pick ( value ) ;
42+ }
43+ else if ( typeof value === 'object' )
44+ {
45+ if ( value . hasOwnProperty ( 'randInt' ) )
46+ {
47+ return MATH . RND . integerInRange ( value . randInt [ 0 ] , value . randInt [ 1 ] ) ;
48+ }
49+ else if ( value . hasOwnProperty ( 'randFloat' ) )
50+ {
51+ return MATH . RND . realInRange ( value . randFloat [ 0 ] , value . randFloat [ 1 ] ) ;
52+ }
53+ }
54+ else if ( typeof value === 'function' )
55+ {
56+ return value ( key ) ;
57+ }
58+
59+ return value ;
60+ } ;
61+
62+ module . exports = GetAdvancedValue ;
You can’t perform that action at this time.
0 commit comments