* Triggered when a setting field has changed. * @param {Field} setting Sender setting field * @param {mixed} value New field value
(setting, value)
| 225 | * @param {mixed} value New field value |
| 226 | */ |
| 227 | settingValueDidChange (setting, value) { |
| 228 | switch (setting.getName()) { |
| 229 | case 'variant': { |
| 230 | // Configure the Polybius square according to the given variant |
| 231 | const variant = this.constructor.getVariant(value) |
| 232 | this._polybiusSquare.setSettingValues({ |
| 233 | rows: variant.squarePositions, |
| 234 | columns: variant.squarePositions |
| 235 | }) |
| 236 | |
| 237 | // Update alphabet, if setting is valid |
| 238 | const alphabetSetting = this.getSetting('alphabet') |
| 239 | if (alphabetSetting.isValid()) { |
| 240 | this._polybiusSquare.setSettingValue('alphabet', |
| 241 | alphabetSetting.getValue().extend(variant.alphabet)) |
| 242 | } |
| 243 | |
| 244 | // Configure variant constraints |
| 245 | this.getSetting('alphabet').setMaxLength(variant.alphabet.length) |
| 246 | this.getSetting('key').setMaxLength(variant.alphabet.length - 1) |
| 247 | break |
| 248 | } |
| 249 | |
| 250 | case 'alphabet': { |
| 251 | // Derive Polybius square mixed alphabet from the alphabet setting |
| 252 | const variant = this.constructor.getVariant( |
| 253 | this.getSettingValue('variant')) |
| 254 | this._polybiusSquare.setSettingValue('alphabet', |
| 255 | value.extend(variant.alphabet)) |
| 256 | break |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Returns a variant for the given name. |
nothing calls this directly
no test coverage detected