@kitten-science/kitten-scientists
Version:
Add-on for the wonderful incremental browser game: https://kittensgame.com/web/
41 lines • 1.93 kB
JavaScript
import { Icons } from "../../../images/Icons.js";
import { Button } from "../Button.js";
import stylesButton from "../Button.module.css";
import { Dialog } from "../Dialog.js";
export class ConsumeButton extends Button {
setting;
resourceName;
constructor(parent, setting, locale, resourceName, options) {
super(parent, "", Icons.DataUsage, {
...options,
onClick: async () => {
const value = await Dialog.prompt(parent, parent.host.engine.i18n("resources.consume.prompt"), parent.host.engine.i18n("resources.consume.promptTitle", [
resourceName,
parent.host.renderPercentage(setting.consume, locale.selected, true),
]), parent.host.renderPercentage(setting.consume), parent.host.engine.i18n("resources.consume.promptExplainer"));
if (value === undefined) {
return;
}
if (value === "" || value.startsWith("-")) {
return;
}
setting.consume = parent.host.parsePercentage(value);
},
onRefresh: () => {
const consumeValue = this.host.renderPercentage(this.setting.consume, this.host.engine.settings.locale.selected, true);
const title = this.setting.consume === 0
? this.host.engine.i18n("resources.consume.titleZero", [this.resourceName])
: this.host.engine.i18n("resources.consume.title", [consumeValue, this.resourceName]);
this.updateTitle(title);
options?.onRefresh?.();
},
});
this.element.addClass(stylesButton.consumeButton);
this.resourceName = resourceName;
this.setting = setting;
}
toString() {
return `[${ConsumeButton.name}#${this.componentId}]`;
}
}
//# sourceMappingURL=ConsumeButton.js.map