28 lines
638 B
TypeScript
28 lines
638 B
TypeScript
export const selectRandomHPGMissionSzenery = (code: string) => {
|
|
const scenery = code
|
|
.split("_")
|
|
.map((n: string) => {
|
|
const numbers = n.split(",");
|
|
|
|
const parsedNumbers = numbers
|
|
.map((num) => {
|
|
if (num.includes("-")) {
|
|
const [min, max] = num.split("-").map(Number);
|
|
// creae a range of numbers
|
|
return Array.from(
|
|
{
|
|
length: max! - min! + 1,
|
|
},
|
|
(_, ai) => ai + min!,
|
|
);
|
|
}
|
|
return Number(num);
|
|
})
|
|
.flat();
|
|
const randomI = Math.floor(Math.random() * parsedNumbers.length);
|
|
return parsedNumbers[randomI];
|
|
})
|
|
.join("_");
|
|
return scenery;
|
|
};
|