|
| 1 | +package com.fwdekker.randomness |
| 2 | + |
| 3 | +import com.fwdekker.randomness.string.SymbolSetSettings |
| 4 | +import com.fwdekker.randomness.template.TemplateList |
| 5 | +import com.fwdekker.randomness.template.TemplateSettings |
| 6 | +import com.fwdekker.randomness.word.DictionarySettings |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + * Contains references to various [Settings] objects. |
| 11 | + * |
| 12 | + * @property templateList The template list. |
| 13 | + * @property symbolSetSettings The symbol set settings. |
| 14 | + * @property dictionarySettings The dictionary settings. |
| 15 | + */ |
| 16 | +data class SettingsState( |
| 17 | + var templateList: TemplateList = TemplateList(emptyList()), |
| 18 | + var symbolSetSettings: SymbolSetSettings = SymbolSetSettings(emptyMap()), |
| 19 | + var dictionarySettings: DictionarySettings = DictionarySettings(emptySet()) |
| 20 | +) : State() { |
| 21 | + override fun doValidate() = |
| 22 | + templateList.doValidate() ?: symbolSetSettings.doValidate() ?: dictionarySettings.doValidate() |
| 23 | + |
| 24 | + override fun copyFrom(scheme: State) { |
| 25 | + require(scheme is SettingsState) { "Cannot copy from non-SettingsState." } |
| 26 | + |
| 27 | + templateList.copyFrom(scheme.templateList) |
| 28 | + symbolSetSettings.copyFrom(scheme.symbolSetSettings) |
| 29 | + dictionarySettings.copyFrom(scheme.dictionarySettings) |
| 30 | + } |
| 31 | + |
| 32 | + override fun deepCopy(retainUuid: Boolean) = |
| 33 | + copy( |
| 34 | + templateList = templateList.deepCopy(retainUuid = retainUuid), |
| 35 | + symbolSetSettings = symbolSetSettings.deepCopy(retainUuid = retainUuid), |
| 36 | + dictionarySettings = dictionarySettings.deepCopy(retainUuid = retainUuid) |
| 37 | + ).also { if (retainUuid) it.uuid = uuid } |
| 38 | + |
| 39 | + |
| 40 | + /** |
| 41 | + * Holds constants. |
| 42 | + */ |
| 43 | + companion object { |
| 44 | + /** |
| 45 | + * The persistent `SettingsState` instance. |
| 46 | + */ |
| 47 | + val default by lazy { |
| 48 | + SettingsState( |
| 49 | + TemplateSettings.default.state, |
| 50 | + SymbolSetSettings.default, |
| 51 | + DictionarySettings.default |
| 52 | + ) |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments