Allow attachment indices to be changed.
rodzic
52ddb05dd8
commit
b20cfd5080
|
@ -16,6 +16,7 @@ import {
|
||||||
AttachmentPointType,
|
AttachmentPointType,
|
||||||
ATTACHMENT_POINT_TYPES,
|
ATTACHMENT_POINT_TYPES,
|
||||||
iterAttachmentPoints,
|
iterAttachmentPoints,
|
||||||
|
PointWithNormal,
|
||||||
} from "../../specs";
|
} from "../../specs";
|
||||||
import { Random } from "../../random";
|
import { Random } from "../../random";
|
||||||
import { capitalize, range } from "../../util";
|
import { capitalize, range } from "../../util";
|
||||||
|
@ -266,25 +267,56 @@ export const CREATURE_DESIGN_DEFAULTS: CreatureDesign = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const AttachmentIndicesWidget: React.FC<{
|
const AttachmentIndicesWidget: React.FC<{
|
||||||
type: AttachmentPointType;
|
label: string;
|
||||||
creature: CreatureSymbol;
|
points: PointWithNormal[];
|
||||||
|
attachmentsOfType: AttachedCreatureSymbol[];
|
||||||
attachment: AttachedCreatureSymbol;
|
attachment: AttachedCreatureSymbol;
|
||||||
onChange: (attachment: AttachedCreatureSymbol) => void;
|
onChange: (attachment: AttachedCreatureSymbol) => void;
|
||||||
idPrefix: string;
|
}> = ({ attachment, ...props }) => {
|
||||||
}> = (props) => {
|
const allIndices = range(props.points.length);
|
||||||
const id = `${props.idPrefix}_indices`;
|
const immutableIndices = new Set<number>();
|
||||||
const typeCap = capitalize(props.type);
|
const toggleIndex = (i: number) => {
|
||||||
|
const indices = attachment.indices.slice();
|
||||||
|
const idx = indices.indexOf(i);
|
||||||
|
if (idx === -1) {
|
||||||
|
indices.push(i);
|
||||||
|
} else {
|
||||||
|
indices.splice(idx, 1);
|
||||||
|
}
|
||||||
|
props.onChange({ ...attachment, indices });
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let a of props.attachmentsOfType) {
|
||||||
|
if (a !== attachment) {
|
||||||
|
for (let idx of a.indices) {
|
||||||
|
// This index is taken up by another attachment.
|
||||||
|
immutableIndices.add(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachment.indices.length === 1) {
|
||||||
|
// This attachment is only for one index, don't let it be unselected.
|
||||||
|
immutableIndices.add(attachment.indices[0]);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-widget">
|
<>
|
||||||
<label htmlFor={id}>{typeCap} attachment point indices:</label>
|
<div>{props.label}</div>
|
||||||
<input
|
<div>
|
||||||
id={id}
|
{allIndices.map((i) => {
|
||||||
type="text"
|
return (
|
||||||
disabled
|
<Checkbox
|
||||||
value={props.attachment.indices.join(", ")}
|
key={i}
|
||||||
/>
|
label={i.toString()}
|
||||||
</div>
|
onChange={() => toggleIndex(i)}
|
||||||
|
disabled={immutableIndices.has(i)}
|
||||||
|
value={attachment.indices.includes(i)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -385,10 +417,10 @@ function CreaturePartEditor<T extends CreatureSymbol>({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AttachmentIndicesWidget
|
<AttachmentIndicesWidget
|
||||||
type={type}
|
label={`${typeCap} attachment point indices:`}
|
||||||
creature={creature}
|
points={points}
|
||||||
|
attachmentsOfType={creatureAttachments}
|
||||||
attachment={attach}
|
attachment={attach}
|
||||||
idPrefix={atIdPrefix}
|
|
||||||
onChange={updateAttachment.bind(null, attach)}
|
onChange={updateAttachment.bind(null, attach)}
|
||||||
/>
|
/>
|
||||||
<div className="thingy">
|
<div className="thingy">
|
||||||
|
|
Ładowanie…
Reference in New Issue