mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-16 06:06:11 +01:00
18 lines
730 B
TypeScript
18 lines
730 B
TypeScript
import { api } from "../api/dynamic";
|
|
import type { TankState } from "./tankState";
|
|
|
|
const tanks = await api.tanks();
|
|
|
|
// Turns the ids held in a tank state into their definitions
|
|
export function resolveTankModules(state: TankState) {
|
|
// TODO: consider changing array to a map just like modules
|
|
const tank = tanks.tanks[state.tank];
|
|
const turret = tank.turrets.find(({ id }) => id === state.turret)!;
|
|
const gun = turret.guns.find(({ id }) => id === state.gun)!;
|
|
const shell = gun.shells.find(({ id }) => id === state.shell)!;
|
|
const engine = tank.engines.find(({ id }) => id === state.engine)!;
|
|
const track = tank.tracks.find(({ id }) => id === state.track)!;
|
|
|
|
return { tank, turret, gun, shell, engine, track };
|
|
}
|