MCPcopy Create free account
hub / github.com/cryptii/cryptii / settingValueDidChange

Method settingValueDidChange

src/Encoder/ADFGXCipher.js:227–259  ·  view source on GitHub ↗

* Triggered when a setting field has changed. * @param {Field} setting Sender setting field * @param {mixed} value New field value

(setting, value)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 10

getVariantMethod · 0.80
setSettingValuesMethod · 0.80
getSettingMethod · 0.80
setSettingValueMethod · 0.80
extendMethod · 0.80
setMaxLengthMethod · 0.80
getSettingValueMethod · 0.80
getNameMethod · 0.45
isValidMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected