breakout71/src/startingPerks.ts

57 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-04-02 10:42:01 +02:00
import { asyncAlert } from "./asyncAlert";
import { PerkId, Upgrade } from "./types";
import { t } from "./i18n/i18n";
import { icons, upgrades } from "./loadGameData";
import { getSettingValue, getTotalScore, setSettingValue } from "./settings";
2025-04-07 14:50:35 +02:00
import {isOptionOn} from "./options";
2025-04-02 10:41:35 +02:00
2025-04-02 10:42:01 +02:00
export function startingPerkMenuButton() {
return {
2025-04-07 14:50:35 +02:00
disabled:isOptionOn('easy'),
2025-04-02 10:42:01 +02:00
icon: icons["icon:starting_perks"],
text: t("main_menu.starting_perks"),
help: t("main_menu.starting_perks_help"),
async value() {
await openStartingPerksEditor();
},
};
2025-04-02 10:41:35 +02:00
}
2025-04-07 14:08:48 +02:00
export function isStartingPerk(u: Upgrade): boolean {
2025-04-02 10:42:01 +02:00
return getSettingValue("start_with_" + u.id, u.giftable);
2025-04-02 10:41:35 +02:00
}
2025-04-02 10:42:01 +02:00
export async function openStartingPerksEditor() {
const ts = getTotalScore();
const avaliable = upgrades.filter(
(u) =>
!u.requires && !["instant_upgrade"].includes(u.id) && u.threshold <= ts,
);
2025-04-07 14:08:48 +02:00
const starting = avaliable.filter((u) => isStartingPerk(u));
2025-04-02 10:42:01 +02:00
const buttons = avaliable.map((u) => {
2025-04-07 14:08:48 +02:00
const checked = isStartingPerk(u);
2025-04-02 10:42:01 +02:00
return {
icon: u.icon,
text: u.name,
tooltip: u.help(1),
value: u,
disabled: checked && starting.length < 2,
checked,
};
});
2025-04-02 10:41:35 +02:00
2025-04-02 10:42:01 +02:00
const perk: Upgrade | null | void = await asyncAlert({
2025-04-04 12:07:51 +02:00
title: t("main_menu.starting_perks"),
className: "actionsAsGrid",
2025-04-02 10:42:01 +02:00
content: [
t("main_menu.starting_perks_checked"),
...buttons.filter((b) => b.checked),
t("main_menu.starting_perks_unchecked"),
...buttons.filter((b) => !b.checked),
],
});
if (perk) {
2025-04-07 14:08:48 +02:00
setSettingValue("start_with_" + perk.id, !isStartingPerk(perk));
2025-04-02 10:42:01 +02:00
openStartingPerksEditor();
}
}