Reorder code to make more sense.

pull/34/head
Atul Varma 2021-02-27 09:22:07 -05:00
rodzic 3ad6dd290f
commit 40d6120d5b
1 zmienionych plików z 34 dodań i 34 usunięć

Wyświetl plik

@ -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(
<CreatureSymbol
data={attachment}
key={children.length}
attachTo={kind}
indices={indices}
/>
);
}
}
return <CreatureSymbol data={root} children={children} />;
}
/**
* 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(
<CreatureSymbol
data={attachment}
key={children.length}
attachTo={kind}
indices={indices}
/>
);
}
}
return <CreatureSymbol data={root} children={children} />;
}
const EYE_CREATURE = (
<Eye>
<Lightning nestInside />