Deal gracefully w/ symbols that lack attachment points.
rodzic
e89d613b38
commit
19ead8b833
|
@ -37,7 +37,7 @@ function getAttachmentPoint(
|
||||||
const points = specs[type];
|
const points = specs[type];
|
||||||
if (!(points && points.length > idx)) {
|
if (!(points && points.length > idx)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Symbol ${s.name} must have at least ${
|
`Expected symbol ${s.name} to have at least ${
|
||||||
idx + 1
|
idx + 1
|
||||||
} ${type} attachment point(s)!`
|
} ${type} attachment point(s)!`
|
||||||
);
|
);
|
||||||
|
@ -46,6 +46,20 @@ function getAttachmentPoint(
|
||||||
return points[idx];
|
return points[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeGetAttachmentPoint(
|
||||||
|
s: SvgSymbolData,
|
||||||
|
type: AttachmentPointType,
|
||||||
|
idx: number = 0
|
||||||
|
): PointWithNormal | null {
|
||||||
|
try {
|
||||||
|
return getAttachmentPoint(s, type, idx);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
type AttachmentChildren = JSX.Element | JSX.Element[];
|
type AttachmentChildren = JSX.Element | JSX.Element[];
|
||||||
|
|
||||||
type CreatureContextType = SvgSymbolContext & {
|
type CreatureContextType = SvgSymbolContext & {
|
||||||
|
@ -121,8 +135,12 @@ const CreatureSymbol: React.FC<CreatureSymbolProps> = (props) => {
|
||||||
const children: JSX.Element[] = [];
|
const children: JSX.Element[] = [];
|
||||||
|
|
||||||
for (let attachIndex of attachmentIndices) {
|
for (let attachIndex of attachmentIndices) {
|
||||||
const parentAp = getAttachmentPoint(parent, attachTo, attachIndex);
|
const parentAp = safeGetAttachmentPoint(parent, attachTo, attachIndex);
|
||||||
const ourAp = getAttachmentPoint(data, "tail");
|
const ourAp = safeGetAttachmentPoint(data, "tail");
|
||||||
|
|
||||||
|
if (!parentAp || !ourAp) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// If we're being attached as a tail, we want to actually rotate
|
// If we're being attached as a tail, we want to actually rotate
|
||||||
// the attachment an extra 180 degrees, as the tail attachment
|
// the attachment an extra 180 degrees, as the tail attachment
|
||||||
|
|
Ładowanie…
Reference in New Issue