deadhead-space-freight-tycoon/packages/content/src/bundle.ts

25 lines
775 B
TypeScript

import { cargoTypes, skills } from "./data/cargo";
import { gameConfig } from "./data/config";
import { locations } from "./data/locations";
import { shipModels } from "./data/ships";
/** Returns a lookup that gives `undefined` for an unknown id instead of throwing. */
function byId<T extends { id: string }>(items: readonly T[]): (id: string) => T | undefined {
const map = new Map(items.map((item) => [item.id, item]));
return (id) => map.get(id);
}
/** All static game data in one object, with lookups by id. */
export const content = {
locations,
shipModels,
cargoTypes,
skills,
config: gameConfig,
location: byId(locations),
shipModel: byId(shipModels),
cargoType: byId(cargoTypes),
skill: byId(skills),
};
export type Content = typeof content;