rt-graphic-component/components/GatedBox/GatedBox.js

67 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-01-02 14:36:10 +08:00
import { Graphics } from 'pixi.js';
import { JlGraphic, VectorText } from 'jl-graphic';
const gatedBoxConsts = {
codeFontSize: 12,
codeColor: 0xffffff,
bodyLineColor: 0xffffff,
bodyLineWidth: 4,
bodyRectLineColor: 0xffffff,
bodyRectLineWidth: 2,
bodyRectWidth: 20,
bodyRectHeight: 20,
bodyColor: 0x000000,
};
class GatedBox extends JlGraphic {
static Type = 'gatedBox';
codeGraph = new VectorText('');
rectBody = new Graphics();
lineBody = new Graphics();
textGraph = new VectorText('M');
constructor() {
super(GatedBox.Type);
this.addChild(this.codeGraph);
this.addChild(this.rectBody);
this.addChild(this.lineBody);
this.addChild(this.textGraph);
this.codeGraph.name = 'gated_box_code';
}
get datas() {
return this.getDatas();
}
doRepaint() {
const codeGraph = this.codeGraph;
codeGraph.text = this.datas.code;
codeGraph.style.fill = gatedBoxConsts.codeColor;
codeGraph.setVectorFontSize(gatedBoxConsts.codeFontSize);
const codeTransform = this.datas?.childTransforms?.find((item) => item.name === 'gated_box_code');
if (codeTransform) {
const position = codeTransform?.transform.position;
const rotation = codeTransform?.transform?.rotation;
codeGraph.position.set(position?.x, position?.y);
codeGraph.rotation = rotation || 0;
}
else {
codeGraph.position.set(20, 0);
}
codeGraph.anchor.set(0.5);
this.textGraph.style.fill = gatedBoxConsts.codeColor;
this.textGraph.setVectorFontSize(gatedBoxConsts.codeFontSize);
this.textGraph.anchor.set(0.5);
this.rectBody.clear();
this.rectBody.beginFill(gatedBoxConsts.bodyColor, 0);
this.rectBody.lineStyle(gatedBoxConsts.bodyRectLineWidth, gatedBoxConsts.bodyRectLineColor);
this.rectBody.drawRect(-gatedBoxConsts.bodyRectWidth / 2, -gatedBoxConsts.bodyRectHeight / 2, gatedBoxConsts.bodyRectWidth, gatedBoxConsts.bodyRectHeight);
this.rectBody.endFill();
this.lineBody.clear();
const lineY = this.datas.flip
? gatedBoxConsts.bodyRectHeight / 2
: -gatedBoxConsts.bodyRectHeight / 2;
this.lineBody.lineStyle(gatedBoxConsts.bodyLineWidth, gatedBoxConsts.bodyLineColor);
this.lineBody.moveTo(-gatedBoxConsts.bodyRectWidth / 2, lineY);
this.lineBody.lineTo(gatedBoxConsts.bodyRectWidth / 2, lineY);
}
}
export { GatedBox };