breakout71/src/startingPerks.ts

67 lines
1.8 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 15:25:58 +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 15:25:58 +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-10 13:17:38 +02:00
export function isBlackListedForStart(u: Upgrade) {
return !!(
u.requires ||
["instant_upgrade"].includes(u.id) ||
u.threshold > getTotalScore()
);
}
2025-04-07 14:08:48 +02:00
export function isStartingPerk(u: Upgrade): boolean {
2025-04-10 13:17:38 +02:00
return (
!isBlackListedForStart(u) &&
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() {
2025-04-10 13:17:38 +02:00
const avaliable = upgrades.filter((u) => !isBlackListedForStart(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),
2025-04-10 13:17:38 +02:00
value: [u],
2025-04-02 10:42:01 +02:00
checked,
};
});
2025-04-10 13:17:38 +02:00
const checkedList = buttons.filter((b) => b.checked);
2025-04-02 10:41:35 +02:00
2025-04-10 13:17:38 +02:00
const perks: 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: [
2025-04-10 13:17:38 +02:00
checkedList.length
? t("main_menu.starting_perks_checked")
: t("main_menu.starting_perks_full_random"),
...checkedList,
2025-04-02 10:42:01 +02:00
t("main_menu.starting_perks_unchecked"),
...buttons.filter((b) => !b.checked),
],
});
2025-04-10 13:17:38 +02:00
if (perks) {
perks?.forEach((perk) => {
setSettingValue("start_with_" + perk.id, !isStartingPerk(perk));
});
2025-04-02 10:42:01 +02:00
openStartingPerksEditor();
}
}