From 40d6120d5bde716e4ce7632ea4dde620ec865704 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Sat, 27 Feb 2021 09:22:07 -0500 Subject: [PATCH] Reorder code to make more sense. --- lib/pages/creature-page.tsx | 68 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/pages/creature-page.tsx b/lib/pages/creature-page.tsx index b6d6564..f4e7f88 100644 --- a/lib/pages/creature-page.tsx +++ b/lib/pages/creature-page.tsx @@ -36,6 +36,40 @@ function getSymbol(name: string): SvgSymbolData { return symbol; } +/** + * Randomly creates a symbol with the given number of + * types of attachments. The symbol itself, and where the + * attachments are attached, are chosen randomly. + */ +function getSymbolWithAttachments( + numAttachmentKinds: number, + rng: Random +): JSX.Element { + const children: JSX.Element[] = []; + const root = rng.choice(SvgVocabulary); + if (root.specs) { + const attachmentKinds = rng.uniqueChoices( + Array.from(iterAttachmentPoints(root.specs)) + .filter((point) => point.type !== "anchor") + .map((point) => point.type), + numAttachmentKinds + ); + for (let kind of attachmentKinds) { + const attachment = rng.choice(SvgVocabulary); + const indices = range(root.specs[kind]?.length ?? 0); + children.push( + + ); + } + } + return ; +} + /** * A creature symbol that comes with default (but overrideable) symbol data. * This makes it easy to use the symbol in JSX, but also easy to dynamically @@ -76,40 +110,6 @@ const Tail = createCreatureSymbol("tail"); const Lightning = createCreatureSymbol("lightning"); -/** - * Randomly creates a symbol with the given number of - * types of attachments. The symbol itself, and where the - * attachments are attached, are chosen randomly. - */ -function getSymbolWithAttachments( - numAttachmentKinds: number, - rng: Random -): JSX.Element { - const children: JSX.Element[] = []; - const root = rng.choice(SvgVocabulary); - if (root.specs) { - const attachmentKinds = rng.uniqueChoices( - Array.from(iterAttachmentPoints(root.specs)) - .filter((point) => point.type !== "anchor") - .map((point) => point.type), - numAttachmentKinds - ); - for (let kind of attachmentKinds) { - const attachment = rng.choice(SvgVocabulary); - const indices = range(root.specs[kind]?.length ?? 0); - children.push( - - ); - } - } - return ; -} - const EYE_CREATURE = (