2025-03-06 16:46:25 +01:00
|
|
|
import { Level, Palette, RawLevel, Upgrade } from "./types";
|
2025-03-16 17:45:29 +01:00
|
|
|
import _palette from "./data/palette.json";
|
|
|
|
import _rawLevelsList from "./data/levels.json";
|
|
|
|
import _appVersion from "./data/version.json";
|
2025-03-19 20:14:55 +01:00
|
|
|
import { rawUpgrades } from "./upgrades";
|
2025-03-15 10:34:01 +01:00
|
|
|
import { getLevelBackground } from "./getLevelBackground";
|
2025-03-16 17:45:29 +01:00
|
|
|
import { levelIconHTML } from "./levelIcon";
|
2025-04-22 16:37:56 +02:00
|
|
|
|
|
|
|
import {automaticBackgroundColor} from "./pure_functions";
|
2025-03-16 17:45:29 +01:00
|
|
|
|
2025-03-06 14:06:02 +01:00
|
|
|
const palette = _palette as Palette;
|
|
|
|
|
2025-03-06 16:46:25 +01:00
|
|
|
const rawLevelsList = _rawLevelsList as RawLevel[];
|
2025-03-06 14:06:02 +01:00
|
|
|
|
|
|
|
export const appVersion = _appVersion as string;
|
|
|
|
|
2025-03-11 13:56:42 +01:00
|
|
|
export const icons = {} as { [k: string]: string };
|
2025-04-14 13:39:30 +02:00
|
|
|
|
|
|
|
export function transformRawLevel(level: RawLevel) {
|
2025-04-22 16:29:17 +02:00
|
|
|
const splitBricks=level.bricks
|
2025-04-14 13:39:30 +02:00
|
|
|
.split("")
|
2025-04-22 16:29:17 +02:00
|
|
|
const bricks = splitBricks
|
2025-04-14 13:39:30 +02:00
|
|
|
.map((c) => palette[c])
|
|
|
|
.slice(0, level.size * level.size);
|
|
|
|
const bricksCount = bricks.filter((i) => i).length;
|
|
|
|
const icon = levelIconHTML(bricks, level.size, level.color);
|
|
|
|
icons[level.name] = icon;
|
|
|
|
return {
|
|
|
|
...level,
|
|
|
|
bricks,
|
|
|
|
bricksCount,
|
|
|
|
icon,
|
2025-04-22 16:29:17 +02:00
|
|
|
color: automaticBackgroundColor(splitBricks) ,
|
2025-04-14 13:39:30 +02:00
|
|
|
svg: getLevelBackground(level),
|
|
|
|
sortKey: ((Math.random() + 3) / 3.5) * bricksCount,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const allLevelsAndIcons = rawLevelsList.map(
|
|
|
|
transformRawLevel,
|
|
|
|
) as Level[];
|
2025-03-06 16:46:25 +01:00
|
|
|
|
2025-04-07 14:50:35 +02:00
|
|
|
export const allLevels = allLevelsAndIcons.filter(
|
|
|
|
(l) => !l.name.startsWith("icon:"),
|
|
|
|
);
|
2025-04-07 14:22:59 +02:00
|
|
|
|
2025-03-06 16:46:25 +01:00
|
|
|
export const upgrades = rawUpgrades.map((u) => ({
|
|
|
|
...u,
|
2025-03-28 19:40:59 +01:00
|
|
|
icon: icons["icon:" + u.id],
|
2025-03-06 16:46:25 +01:00
|
|
|
})) as Upgrade[];
|