Something went wrong. Try again.
An atproto Tilemap editor
Something went wrong. Try again.
1.5 kB · 41 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142// ---------------------------------------------------------------------------// Document kinds shared by the library sidebar: the three first-class entities// (tileset, map, world), the atproto collection (NSID) each lives in, and the// `$type` discriminator that tags a repo record.//// A record's top-level `$type` equals its entity's collection NSID, so// `kindFromType` can resolve a kind from the tag alone.// ---------------------------------------------------------------------------
import { TILESET_NSID } from '@/lexicon/tileset'
export type DocKind = 'tileset' | 'map' | 'world'
/** Collection NSIDs. Tilesets have a published lexicon; map/world records reuse * the same naming and the local document shapes until their lexicons land. */export const MAP_NSID = 'world.tilemap.map'export const WORLD_NSID = 'world.tilemap.world'export { TILESET_NSID }
export const COLLECTION_BY_KIND: Record<DocKind, string> = { tileset: TILESET_NSID, map: MAP_NSID, world: WORLD_NSID,}
/** Human label for a kind (singular). */export const KIND_LABEL: Record<DocKind, string> = { tileset: 'Tileset', map: 'Map', world: 'World',}
/** Map a record/file `$type` (or a `#fragment` on a collection) to its kind. */export function kindFromType(type: unknown): DocKind | null { if (typeof type !== 'string') return null const nsid = type.split('#')[0] for (const kind of Object.keys(COLLECTION_BY_KIND) as DocKind[]) { if (COLLECTION_BY_KIND[kind] === nsid) return kind } return null}