Adrià Vilanova MartÃnez | ad69676 | 2024-05-25 19:32:36 +0200 | [diff] [blame] | 1 | import { |
| 2 | OptionCodename, |
| 3 | OptionsValues, |
| 4 | optionCodenames, |
| 5 | } from './optionsPrototype'; |
| 6 | |
| 7 | /** |
| 8 | * Representation of a specific configuration of the option values. |
| 9 | */ |
| 10 | export class OptionsConfiguration { |
| 11 | constructor(public optionsValues: OptionsValues) {} |
| 12 | |
| 13 | getOptionValue<O extends OptionCodename>(option: O): OptionsValues[O] { |
| 14 | return this.optionsValues[option]; |
| 15 | } |
| 16 | |
| 17 | isEnabled(option: OptionCodename): boolean { |
| 18 | const value = this.getOptionValue(option); |
| 19 | return value === true; |
| 20 | } |
| 21 | |
| 22 | isEqualTo(otherConfiguration: OptionsConfiguration) { |
| 23 | for (const option of optionCodenames) { |
| 24 | const thisValue = this.getOptionValue(option); |
| 25 | const otherValue = otherConfiguration.getOptionValue(option); |
| 26 | if (thisValue !== otherValue) { |
| 27 | return false; |
| 28 | } |
| 29 | } |
| 30 | return true; |
| 31 | } |
| 32 | } |