* Updates the settings interface to reflect the given model. * @protected * @param {string} modelName Model name * @return {EnigmaEncoder} Fluent interface
(modelName)
| 511 | * @return {EnigmaEncoder} Fluent interface |
| 512 | */ |
| 513 | applyModel (modelName) { |
| 514 | const model = EnigmaEncoder.getModel(modelName) |
| 515 | const maxSlotCount = EnigmaEncoder.getMaxSlotCount() |
| 516 | |
| 517 | // Update setting options and layout for each slot |
| 518 | for (let i = 0; i < maxSlotCount; i++) { |
| 519 | const slot = i < model.slots.length ? model.slots[i] : null |
| 520 | const slotVisible = slot !== null |
| 521 | |
| 522 | const rotorSetting = this.getSetting(`rotor${i + 1}`) |
| 523 | const ringSetting = this.getSetting(`ring${i + 1}`) |
| 524 | const positionSetting = this.getSetting(`position${i + 1}`) |
| 525 | |
| 526 | // Hide or show slot settings depending on model |
| 527 | rotorSetting.setVisible(slotVisible) |
| 528 | ringSetting.setVisible(slotVisible) |
| 529 | positionSetting.setVisible(slotVisible) |
| 530 | |
| 531 | if (slotVisible) { |
| 532 | // Configure rotor setting |
| 533 | const rotors = EnigmaEncoder.getRotors(slot.rotors) |
| 534 | rotorSetting.setElements( |
| 535 | rotors.map(rotor => rotor.name), |
| 536 | rotors.map(rotor => rotor.label), |
| 537 | null, |
| 538 | false) |
| 539 | |
| 540 | // Apply slot default if current value is not available for this model |
| 541 | if (rotorSetting.validateValue(rotorSetting.getValue()) !== true) { |
| 542 | rotorSetting.setValue(rotors[0].name) |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | // Update reflector setting options |
| 548 | const reflectorRotors = EnigmaEncoder.getRotors(model.reflectorRotors) |
| 549 | const reflectorSetting = this.getSetting('reflector') |
| 550 | |
| 551 | reflectorSetting.setElements( |
| 552 | reflectorRotors.map(rotor => rotor.name), |
| 553 | reflectorRotors.map(rotor => rotor.label), |
| 554 | null, |
| 555 | false) |
| 556 | |
| 557 | // Apply first rotor if current one is not available for this model |
| 558 | if (reflectorSetting.validateValue(reflectorSetting.getValue()) !== true) { |
| 559 | reflectorSetting.setValue(reflectorRotors[0].name) |
| 560 | } |
| 561 | |
| 562 | // Make reflector position and ring visible when it has a thumbwheel |
| 563 | reflectorSetting.setWidth(model.reflectorThumbwheel ? 4 : 12) |
| 564 | reflectorSetting.setVisible( |
| 565 | model.reflectorThumbwheel || reflectorRotors.length > 1) |
| 566 | |
| 567 | this.getSetting('positionReflector').setVisible(model.reflectorThumbwheel) |
| 568 | this.getSetting('ringReflector').setVisible(model.reflectorThumbwheel) |
| 569 | |
| 570 | // Only make plugboard visible when it is availabe for this model |
no test coverage detected