Resolve which district and family we are authoring for, against the real world.
(handle, { district, family })
| 86 | |
| 87 | /** Resolve which district and family we are authoring for, against the real world. */ |
| 88 | async function resolveTarget(handle, { district, family }) { |
| 89 | const { user, districts } = await fetchWorld(handle, { api: DEFAULT_API }); |
| 90 | if (!districts.length) { |
| 91 | die( |
| 92 | `${user.name}'s world is empty or private. A private world returns nothing to an anonymous reader, which is what this is.` |
| 93 | ); |
| 94 | } |
| 95 | const target = district |
| 96 | ? districts.find((d) => d.niche === district) |
| 97 | : districts[0]; |
| 98 | if (!target) { |
| 99 | die( |
| 100 | `No district "${district}" in this world. Try one of: ${districts |
| 101 | .slice(0, 12) |
| 102 | .map((d) => d.niche) |
| 103 | .join(", ")}` |
| 104 | ); |
| 105 | } |
| 106 | const realm = realmOf(target.niche); |
| 107 | if (!realm) die(`"${target.niche}" is not a district the renderer knows.`); |
| 108 | |
| 109 | const open = unlockedFamilies(target.level); |
| 110 | const fam = |
| 111 | family ?? (open.includes("house") ? "house" : open[open.length - 1]); |
| 112 | if (!FAMILY_KINDS.includes(fam)) |
| 113 | die(`Unknown family "${fam}". Available: ${FAMILY_KINDS.join(", ")}`); |
| 114 | if (!open.includes(fam)) { |
| 115 | die( |
| 116 | `"${fam}" is not unlocked in ${target.niche} at level ${ |
| 117 | target.level |
| 118 | }. Unlocked here: ${open.join(", ")}` |
| 119 | ); |
| 120 | } |
| 121 | return { user, realm, ...target, family: fam, districts }; |
| 122 | } |
| 123 | |
| 124 | async function builderSource(realm, family) { |
| 125 | /* Filled in with the REALM's own material names. A starting file that says |
no test coverage detected