MCPcopy Create free account
hub / github.com/Barrior/JParticles / optionsNormalize

Method optionsNormalize

src/wave.ts:99–132  ·  view source on GitHub ↗

* 标准化配置项

()

Source from the content-addressed store, hash-verified

97 * 标准化配置项
98 */
99 protected optionsNormalize(): void {
100 stdProperties.forEach((property) => {
101 let num = this.options.num
102
103 // 选项原始值
104 const rawValue = this.options[property]
105
106 // 选项标准值
107 const stdValue: ValueOf<StdOptions> = []
108
109 // 比例范围
110 const scaleRange =
111 property === 'offsetLeft' ? this.canvasWidth : this.canvasHeight
112
113 // 将数组、字符串、数字、布尔类型等属性标准化,利于内部代码编写
114 //
115 // 例如 num = 3 时,
116 // crestHeight: 2或[]或[2]或[2, 2], 将标准化成: [2, 2, 2]
117 // crestHeight: 没有传值时则使用默认值,将标准化成: [x, x, x], x表示默认值
118 while (num--) {
119 const value = Array.isArray(rawValue) ? rawValue[num] : rawValue
120
121 stdValue[num] = isUndefined(value)
122 ? this.getOptionDefaultValue(property)
123 : Wave.getOptionProcessedValue(property, value, scaleRange)
124
125 if (property === 'crestCount') {
126 this.waveLength[num] = this.canvasWidth / (stdValue[num] as number)
127 }
128 }
129
130 this.options[property] = stdValue as never
131 })
132 }
133
134 /**
135 * 配置项缺省情况下对应的默认值

Callers 2

initMethod · 0.95
initMethod · 0.45

Calls 3

getOptionDefaultValueMethod · 0.95
isUndefinedFunction · 0.90

Tested by

no test coverage detected