UNPKG

@kitten-science/kitten-scientists

Version:

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

49 lines 2.2 kB
import { Button } from "../Button.js"; import stylesButton from "../Button.module.css"; import { Dialog } from "../Dialog.js"; export class StockButton extends Button { setting; resourceName; constructor(parent, setting, locale, resourceName, options) { super(parent, "", null, { ...options, onClick: async () => { const value = await Dialog.prompt(parent, parent.host.engine.i18n("resources.stock.prompt"), parent.host.engine.i18n("resources.stock.promptTitle", [ resourceName, parent.host.renderAbsolute(setting.stock, locale.selected), ]), parent.host.renderAbsolute(setting.stock), parent.host.engine.i18n("resources.stock.promptExplainer")); if (value === undefined) { return; } if (value === "" || value.startsWith("-")) { setting.stock = -1; return; } if (value === "0") { setting.enabled = false; } setting.stock = parent.host.parseAbsolute(value) ?? setting.stock; }, onRefresh: () => { const stockValue = this.host.renderAbsolute(this.setting.stock); const title = this.setting.stock < 0 ? this.host.engine.i18n("resources.stock.titleInfinite", [this.resourceName]) : this.setting.stock === 0 ? this.host.engine.i18n("resources.stock.titleZero", [this.resourceName]) : this.host.engine.i18n("resources.stock.title", [ this.host.renderAbsolute(this.setting.stock), this.resourceName, ]); this.updateTitle(title); this.updateLabel(stockValue); }, }); this.element.addClass(stylesButton.stockButton); this.resourceName = resourceName; this.setting = setting; } toString() { return `[${StockButton.name}#${this.componentId}]`; } } //# sourceMappingURL=StockButton.js.map