<aside> ✏️
Blockly 클래스들을 이용한 Block 커스텀하기! 시리즈
<aside> ✏️
목차
</aside>
Blockly.zelos.ConstantProvider
를 상속받고 이전처럼 다시 notch값을 constructor 이후 덮어쓰는 방식으로 처음에는 구현을 했다.RenderInfo
, Drawer
, Renderer
부분 모든 곳에 다 커스텀 constantProvider를 적용 시켜보았는데, 결국 실패하였다.공식문서를 정말정말정말 잘 보자..!!!
make~~~
로 시작하는 메소드를 다시 호출하면서 constant
값들을 동적으로 다시 할당해준다는 것을 알았다. make~~~
로 시작하는 메소드들에서 동적으로 할당해주는 constant 값들을 제외하면, 나머지는 constructor 에서 다시 설정해주면 되었다. override makeNotch() {
const width = this.NOTCH_WIDTH;
const height = this.NOTCH_HEIGHT;
const innerWidth = width / 3;
const curveWidth = innerWidth / 3;
const halfHeight = height / 2;
const quarterHeight = halfHeight / 2;
/**
* Make the main path for the notch.
*
* @param dir Direction multiplier to apply to horizontal offsets along the
* path. Either 1 or -1.
* @returns A path fragment describing a notch.
*/
function makeMainPath(dir: number): string {
return (
svgPaths.curve('c', [
svgPaths.point((dir * curveWidth) / 2, 0),
svgPaths.point((dir * curveWidth * 3) / 4, quarterHeight / 2),
svgPaths.point(dir * curveWidth, quarterHeight),
]) +
svgPaths.line([svgPaths.point(dir * curveWidth, halfHeight)]) +
svgPaths.curve('c', [
svgPaths.point((dir * curveWidth) / 4, quarterHeight / 2),
svgPaths.point((dir * curveWidth) / 2, quarterHeight),
svgPaths.point(dir * curveWidth, quarterHeight),
]) +
svgPaths.lineOnAxis('h', dir * innerWidth) +
svgPaths.curve('c', [
svgPaths.point((dir * curveWidth) / 2, 0),
svgPaths.point((dir * curveWidth * 3) / 4, -(quarterHeight / 2)),
svgPaths.point(dir * curveWidth, -quarterHeight),
]) +
svgPaths.line([svgPaths.point(dir * curveWidth, -halfHeight)]) +
svgPaths.curve('c', [
svgPaths.point((dir * curveWidth) / 4, -(quarterHeight / 2)),
svgPaths.point((dir * curveWidth) / 2, -quarterHeight),
svgPaths.point(dir * curveWidth, -quarterHeight),
])
);
}
const pathLeft = makeMainPath(1);
const pathRight = makeMainPath(-1);
return {
type: this.SHAPES.NOTCH,
width,
height,
pathLeft,
pathRight,
};
}
⇒ 이 말은 즉슨, 나는 이곳에서 notch값을 설정해주면 되는 것이었다 !