Add an 'add attachment' button.
rodzic
202259a533
commit
8857a21efe
|
@ -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(
|
function getImmutableIndices(
|
||||||
attachmentsOfType: AttachedCreatureSymbol[],
|
attachmentsOfType: AttachedCreatureSymbol[],
|
||||||
attachment: AttachedCreatureSymbol
|
attachment: AttachedCreatureSymbol
|
||||||
|
@ -361,6 +376,20 @@ function AttachmentEditor<T extends CreatureSymbol>({
|
||||||
attachments,
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -389,6 +418,10 @@ function AttachmentEditor<T extends CreatureSymbol>({
|
||||||
style.color = "gray";
|
style.color = "gray";
|
||||||
title = `Symbol defines a ${type} but cluster doesn't provide one`;
|
title = `Symbol defines a ${type} but cluster doesn't provide one`;
|
||||||
}
|
}
|
||||||
|
const availableIndices = getAvailableIndices(
|
||||||
|
creatureAttachments,
|
||||||
|
points.length
|
||||||
|
);
|
||||||
const typeCap = capitalize(type);
|
const typeCap = capitalize(type);
|
||||||
return (
|
return (
|
||||||
<div key={type}>
|
<div key={type}>
|
||||||
|
@ -430,6 +463,11 @@ function AttachmentEditor<T extends CreatureSymbol>({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
{availableIndices.length > 0 && (
|
||||||
|
<button onClick={() => addAttachment(type, availableIndices)}>
|
||||||
|
Add {type} attachment
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
Ładowanie…
Reference in New Issue