Add button to remove attachments
rodzic
146dfc9796
commit
b444787c04
|
@ -271,19 +271,30 @@ const CreaturePartEditor: React.FC<{
|
||||||
idPrefix: string;
|
idPrefix: string;
|
||||||
}> = ({ creature, onChange, idPrefix }) => {
|
}> = ({ creature, onChange, idPrefix }) => {
|
||||||
const specs = creature.data.specs || {};
|
const specs = creature.data.specs || {};
|
||||||
const updateAttachment = (
|
const getAttachmentIndex = (attachment: AttachedCreatureSymbol) => {
|
||||||
originalAttachment: AttachedCreatureSymbol,
|
const index = creature.attachments.indexOf(attachment);
|
||||||
attachUpdates: CreatureSymbol
|
|
||||||
) => {
|
|
||||||
const index = creature.attachments.indexOf(originalAttachment);
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Assertion failure, unable to find attachment in creature`
|
`Assertion failure, unable to find attachment in creature`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return index;
|
||||||
|
};
|
||||||
|
const deleteAttachment = (attachment: AttachedCreatureSymbol) => {
|
||||||
const attachments = creature.attachments.slice();
|
const attachments = creature.attachments.slice();
|
||||||
attachments[index] = {
|
attachments.splice(getAttachmentIndex(attachment), 1);
|
||||||
...attachments[index],
|
onChange({
|
||||||
|
...creature,
|
||||||
|
attachments,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const updateAttachment = (
|
||||||
|
originalAttachment: AttachedCreatureSymbol,
|
||||||
|
attachUpdates: CreatureSymbol
|
||||||
|
) => {
|
||||||
|
const attachments = creature.attachments.slice();
|
||||||
|
attachments[getAttachmentIndex(originalAttachment)] = {
|
||||||
|
...originalAttachment,
|
||||||
...attachUpdates,
|
...attachUpdates,
|
||||||
};
|
};
|
||||||
onChange({
|
onChange({
|
||||||
|
@ -359,6 +370,11 @@ const CreaturePartEditor: React.FC<{
|
||||||
value={attach.indices.join(", ")}
|
value={attach.indices.join(", ")}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="thingy">
|
||||||
|
<button onClick={deleteAttachment.bind(null, attach)}>
|
||||||
|
Remove this attachment
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<CreaturePartEditor
|
<CreaturePartEditor
|
||||||
creature={attach}
|
creature={attach}
|
||||||
onChange={updateAttachment.bind(null, attach)}
|
onChange={updateAttachment.bind(null, attach)}
|
||||||
|
|
Ładowanie…
Reference in New Issue