Factor out AttachmentTransform component.

pull/7/head
Atul Varma 2021-02-16 16:43:47 -05:00
rodzic 95800b880c
commit b2c073fa7c
1 zmienionych plików z 28 dodań i 10 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ import {
import { AttachmentPointType, PointWithNormal } from "../specs"; import { AttachmentPointType, PointWithNormal } from "../specs";
import { getAttachmentTransforms } from "../attach"; import { getAttachmentTransforms } from "../attach";
import { scalePointXY } from "../point"; import { scalePointXY } from "../point";
import { Point } from "../../vendor/bezier-js";
const SYMBOL_MAP = new Map( const SYMBOL_MAP = new Map(
SvgVocabulary.map((symbol) => [symbol.name, symbol]) SvgVocabulary.map((symbol) => [symbol.name, symbol])
@ -124,19 +125,36 @@ const CreatureSymbol: React.FC<CreatureSymbolProps> = (props) => {
}); });
return ( return (
<g transform={`translate(${t.translation.x} ${t.translation.y})`}> <AttachmentTransform
<g transformOrigin={ourAp.point}
transform-origin={`${ourAp.point.x} ${ourAp.point.y}`} translate={t.translation}
transform={`scale(${xFlip * ctx.attachmentScale} ${ scale={{ x: ctx.attachmentScale * xFlip, y: ctx.attachmentScale }}
ctx.attachmentScale rotate={xFlip * t.rotation + extraRot}
}) rotate(${xFlip * t.rotation + extraRot})`}
> >
{ourSymbol} {ourSymbol}
</g> </AttachmentTransform>
</g>
); );
}; };
type AttachmentTransformProps = {
transformOrigin: Point;
translate: Point;
scale: Point;
rotate: number;
children: JSX.Element;
};
const AttachmentTransform: React.FC<AttachmentTransformProps> = (props) => (
<g transform={`translate(${props.translate.x} ${props.translate.y})`}>
<g
transform-origin={`${props.transformOrigin.x} ${props.transformOrigin.y}`}
transform={`scale(${props.scale.x} ${props.scale.y}) rotate(${props.rotate})`}
>
{props.children}
</g>
</g>
);
function createCreatureSymbol( function createCreatureSymbol(
name: string name: string
): React.FC<Omit<CreatureSymbolProps, "data">> { ): React.FC<Omit<CreatureSymbolProps, "data">> {