feat(mystery): parseEnding — markdown to typed Ending

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 09:17:11 -05:00
parent e108ca16e0
commit e60844a937
2 changed files with 50 additions and 2 deletions
+17 -1
View File
@@ -1,7 +1,7 @@
import matter from 'gray-matter'
import type { Room, RoomDescriptions, Item } from './types'
import type { Direction } from '../engine/types'
import { roomFrontmatterSchema, itemFrontmatterSchema } from './schema'
import { roomFrontmatterSchema, itemFrontmatterSchema, endingFrontmatterSchema } from './schema'
const WIKILINK = /^\[\[([^\]|]+)(?:\|[^\]]*)?\]\]$/
@@ -115,3 +115,19 @@ export function parseItem(raw: string, sourcePath: string): Item {
takeable: fm.takeable,
}
}
export interface ParsedEnding {
id: 'true' | 'wrong' | 'bad'
ending: { whenFlags: Record<string, string | boolean | number>; narration: string }
}
export function parseEnding(raw: string, _sourcePath: string): ParsedEnding {
const parsed = matter(raw)
// YAML parses bare `true` as boolean; coerce id to string before schema validation.
const data = { ...parsed.data, id: String(parsed.data.id) }
const fm = endingFrontmatterSchema.parse(data)
return {
id: fm.id,
ending: { whenFlags: fm.whenFlags, narration: parsed.content.trim() },
}
}