From 3d8e203e9d3388af7be267efa82666e7bc7f4874 Mon Sep 17 00:00:00 2001 From: fan Date: Fri, 16 Jun 2023 14:08:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=95=9C=E5=83=8F=E4=BB=A3=E7=A0=81=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/CommonGraphics.ts | 52 +++++------------------------ src/graphics/signal/LampMainBody.ts | 15 +++++++-- src/graphics/signal/Signal.ts | 26 +++++++++++---- 3 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/graphics/CommonGraphics.ts b/src/graphics/CommonGraphics.ts index 94e8990..7db7344 100644 --- a/src/graphics/CommonGraphics.ts +++ b/src/graphics/CommonGraphics.ts @@ -1,9 +1,5 @@ -import { Graphics, Point } from 'pixi.js'; -// calculateMirrorPoint -import { - calculateDistanceFromPointToLine, - calculateMirrorPointBasedOnAxis, -} from 'src/jl-graphic'; +import { Graphics } from 'pixi.js'; +import { calculateMirrorPoint } from 'src/jl-graphic'; /** * * @param polygon @@ -49,45 +45,13 @@ export function drawArrow( y: y - lineWidth / 2, }; if (mirror) { - const throughPoint = new Point(trianglAcme.x, trianglAcme.y !== 0 ? 0 : 1); - triangleP1 = calculateMirrorPointBasedOnAxis( - trianglAcme, - throughPoint, - triangleP1, - calculateDistanceFromPointToLine(trianglAcme, throughPoint, triangleP1) - ); - triangleP2 = calculateMirrorPointBasedOnAxis( - trianglAcme, - throughPoint, - triangleP2, - calculateDistanceFromPointToLine(trianglAcme, throughPoint, triangleP2) - ); - lineP1 = calculateMirrorPointBasedOnAxis( - trianglAcme, - throughPoint, - lineP1, - calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP1) - ); - lineP2 = calculateMirrorPointBasedOnAxis( - trianglAcme, - throughPoint, - lineP2, - calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP2) - ); - lineP3 = calculateMirrorPointBasedOnAxis( - trianglAcme, - throughPoint, - lineP3, - calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP3) - ); - lineP4 = calculateMirrorPointBasedOnAxis( - trianglAcme, - throughPoint, - lineP4, - calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP4) - ); + triangleP1 = calculateMirrorPoint(trianglAcme, triangleP1); + triangleP2 = calculateMirrorPoint(trianglAcme, triangleP2); + lineP1 = calculateMirrorPoint(trianglAcme, lineP1); + lineP2 = calculateMirrorPoint(trianglAcme, lineP2); + lineP3 = calculateMirrorPoint(trianglAcme, lineP3); + lineP4 = calculateMirrorPoint(trianglAcme, lineP4); } - console.log(triangleP1, triangleP2, lineP1, lineP2, lineP3, lineP4); polygon.drawPolygon( trianglAcme.x, trianglAcme.y, diff --git a/src/graphics/signal/LampMainBody.ts b/src/graphics/signal/LampMainBody.ts index aab570f..b73541f 100644 --- a/src/graphics/signal/LampMainBody.ts +++ b/src/graphics/signal/LampMainBody.ts @@ -1,5 +1,6 @@ import { Container } from '@pixi/display'; -import { Graphics } from 'pixi.js'; +import { Graphics, Point } from 'pixi.js'; +import { calculateMirrorPoint } from 'src/jl-graphic'; import { Lamp } from './Lamp'; export enum LampEnum { @@ -28,12 +29,16 @@ export class LampMainBody extends Container { this.lampNum = lampNum; this.removeChildren(0); this.lampPost = new Graphics(); + let lpp = new Point(lampConsts.levelLampPostLength, 0); + if (mirror) { + lpp = calculateMirrorPoint(new Point(0, 0), lpp); + } this.lampPost .lineStyle(lampConsts.postLineWidth, LampEnum.lampPostColor) .moveTo(0, -lampConsts.verticalLampPostLength / 2) .lineTo(0, lampConsts.verticalLampPostLength / 2) .moveTo(0, 0) - .lineTo(lampConsts.levelLampPostLength * (mirror ? -1 : 1), 0); + .lineTo(lpp.x, lpp.y); this.addChild(this.lampPost); this.lamps = []; @@ -41,7 +46,11 @@ export class LampMainBody extends Container { const lamp = new Lamp(); const radiusX = (1 + i * 2) * lampConsts.lampRadius + lampConsts.levelLampPostLength; - lamp.paint(radiusX * (mirror ? -1 : 1), 0); + let lrp = new Point(radiusX, 0); + if (mirror) { + lrp = calculateMirrorPoint(new Point(0, 0), lrp); + } + lamp.paint(lrp.x, lrp.y); this.addChild(lamp); this.lamps.push(lamp); } diff --git a/src/graphics/signal/Signal.ts b/src/graphics/signal/Signal.ts index cc22e1c..c8820af 100644 --- a/src/graphics/signal/Signal.ts +++ b/src/graphics/signal/Signal.ts @@ -1,10 +1,11 @@ -import { Graphics } from 'pixi.js'; +import { Graphics, Point } from 'pixi.js'; import { GraphicData, JlGraphic, JlGraphicTemplate, VectorText, } from 'src/jl-graphic'; +import { calculateMirrorPoint } from 'src/jl-graphic'; import { LampMainBody } from './LampMainBody'; import { drawArrow } from '../CommonGraphics'; @@ -31,6 +32,7 @@ const signalConsts = { fleetModeLength: 33, fleetModeRadius: 10, fleetModeLineWidth: 6, + humanControlRadius: 10, }; export class Signal extends JlGraphic { static Type = 'signal'; @@ -58,10 +60,15 @@ export class Signal extends JlGraphic { this.humanControl.clear(); this.humanControl.beginFill(SignalColorEnum.humanControlColor, 1); if (this.humanControl.drawRegularPolygon) { + let hmp = new Point(-signalConsts.humanControlRadius, 0); + if (mirror) { + hmp = calculateMirrorPoint(new Point(0, 0), hmp); + } + console.log(hmp, 'hmp'); this.humanControl.drawRegularPolygon( - mirror ? 10 : -10, - 0, - 10, + hmp.x, + hmp.y, + signalConsts.humanControlRadius, 3, (Math.PI / 2) * (mirror ? -1 : 1) ); @@ -69,10 +76,17 @@ export class Signal extends JlGraphic { this.humanControl.endFill(); this.fleetMode.clear(); this.fleetMode.beginFill(SignalColorEnum.fleetModeColor, 1); + let lmp = new Point( + this.lampMainBody.width + signalConsts.fleetModeLength, + 0 + ); + if (mirror) { + lmp = calculateMirrorPoint(new Point(0, 0), lmp); + } + console.log(lmp, 'hmp'); drawArrow( this.fleetMode, - (this.lampMainBody.width + signalConsts.fleetModeLength) * - (mirror ? -1 : 1), + lmp.x, 0, signalConsts.fleetModeLength, signalConsts.fleetModeRadius,