UNPKG

@kitten-science/kitten-scientists

Version:

Add-on for the wonderful incremental browser game: https://kittensgame.com/web/

49 lines 2.49 kB
import { isNil } from "@oliversalzburg/js-utils/data/nil.js"; import { Container } from "./components/Container.js"; import stylesLabelListItem from "./components/LabelListItem.module.css"; import { SettingListItem } from "./components/SettingListItem.js"; import { SettingsList } from "./components/SettingsList.js"; import { SettingsPanel } from "./components/SettingsPanel.js"; export class PolicySettingsUi extends SettingsPanel { constructor(parent, settings, locale, sectionSetting) { const label = parent.host.engine.i18n("ui.upgrade.policies"); super(parent, settings, new SettingListItem(parent, settings, label, { onCheck: (_isBatchProcess) => { parent.host.engine.imessage("status.auto.enable", [label]); }, onUnCheck: (_isBatchProcess) => { parent.host.engine.imessage("status.auto.disable", [label]); }, }).addChildrenHead([new Container(parent, { classes: [stylesLabelListItem.fillSpace] })]), { onRefreshRequest: () => { this.expando.ineffective = sectionSetting.enabled && settings.enabled && !Object.values(settings.policies).some(policy => policy.enabled); }, }); const policies = this.host.game.science.policies.filter(policy => !isNil(this.setting.policies[policy.name])); const items = []; let lastLabel = policies[0].label; for (const policy of policies.sort((a, b) => a.label.localeCompare(b.label, locale.selected))) { const option = this.setting.policies[policy.name]; const element = new SettingListItem(this, option, policy.label, { onCheck: () => { this.host.engine.imessage("status.sub.enable", [policy.label]); }, onUnCheck: () => { this.host.engine.imessage("status.sub.disable", [policy.label]); }, }); if (this.host.engine.localeSupportsFirstLetterSplits(locale.selected)) { if (lastLabel[0] !== policy.label[0]) { element.element.addClass(stylesLabelListItem.splitter); } } items.push(element); lastLabel = policy.label; } this.addChildContent(new SettingsList(this).addChildren(items)); } } //# sourceMappingURL=PolicySettingsUi.js.map