From 8857a21efeb2d39f88d95eb8b8fa138740c49bcd Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 29 Sep 2021 14:37:52 -0400 Subject: [PATCH] Add an 'add attachment' button. --- lib/pages/creature-page/core.tsx | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/pages/creature-page/core.tsx b/lib/pages/creature-page/core.tsx index e81ba16..4340081 100644 --- a/lib/pages/creature-page/core.tsx +++ b/lib/pages/creature-page/core.tsx @@ -265,6 +265,21 @@ export const CREATURE_DESIGN_DEFAULTS: CreatureDesign = { }, }; +function getAvailableIndices( + attachmentsOfType: AttachedCreatureSymbol[], + numIndices: number +): number[] { + const available = new Set(range(numIndices)); + + for (let a of attachmentsOfType) { + for (let i of a.indices) { + available.delete(i); + } + } + + return Array.from(available); +} + function getImmutableIndices( attachmentsOfType: AttachedCreatureSymbol[], attachment: AttachedCreatureSymbol @@ -361,6 +376,20 @@ function AttachmentEditor({ attachments, }); }; + const addAttachment = (attachTo: AttachmentPointType, indices: number[]) => { + const attachment: AttachedCreatureSymbol = { + attachTo, + indices, + data: SvgVocabulary.items[0], + invertColors: false, + attachments: [], + nests: [], + }; + onChange({ + ...creature, + attachments: [...creature.attachments, attachment], + }); + }; return ( <> @@ -389,6 +418,10 @@ function AttachmentEditor({ style.color = "gray"; title = `Symbol defines a ${type} but cluster doesn't provide one`; } + const availableIndices = getAvailableIndices( + creatureAttachments, + points.length + ); const typeCap = capitalize(type); return (
@@ -430,6 +463,11 @@ function AttachmentEditor({
); })} + {availableIndices.length > 0 && ( + + )} ); })}