From 8f02542257ce0d8d031220894dafff8e60e8b1c4 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 3 Apr 2024 09:35:07 +0800 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 2ab1396e33d328aea6532129560d1495d4f46153 Author: joylink_zhaoerwei Date: Wed Apr 3 09:32:00 2024 +0800 列车驾驶台交互 --- src/api/Simulation.ts | 53 +++-------- src/configs/UrlManage.ts | 2 +- src/drawApp/graphics/TccButtonInteraction.ts | 22 ++--- src/drawApp/graphics/TccHandleInteraction.ts | 19 ++-- src/drawApp/graphics/TccKeyInteraction.ts | 94 ++++++++++---------- src/graphics/tccHandle/TccHandle.ts | 2 +- src/protos/request.ts | 16 ++-- 7 files changed, 87 insertions(+), 121 deletions(-) diff --git a/src/api/Simulation.ts b/src/api/Simulation.ts index cc845ab..a988806 100644 --- a/src/api/Simulation.ts +++ b/src/api/Simulation.ts @@ -184,51 +184,18 @@ export async function ibpKeyOperation(params: IbpKeyOperationParams) { return await api.post(`${UriBase}/ibp/key/operation`, params); } -export interface TccButtonOperationParams { - buttonId: number; - down: boolean; - mapId: number; +export interface TccOperationParams { simulationId: string; - tccId: number; + trainId: string; + deviceId: number; + controlType: request.TrainControl.TrainControlType; + button?: object; + driverKey?: object; + dirKey?: object; + handler?: object; } -export async function tccButtonOperation(params: TccButtonOperationParams) { - return await api.post(`${UriBase}/tcc/btn/operation`, params); -} - -export interface TccKeyOperationParams { - simulationId: string; - mapId: number; - tccId: number; - val: boolean; - keyId: number; -} - -export async function tccKeyOperation(params: TccKeyOperationParams) { - return await api.post(`${UriBase}/tcc/key/operation`, params); -} - -export interface TccKeyDirOperationParams { - simulationId: string; - mapId: number; - tccId: number; - val: number; - keyId: number; -} - -export async function tccKeyDirOperation(params: TccKeyDirOperationParams) { - return await api.post(`${UriBase}/tcc/key/operation`, params); -} - -export interface TccHandleOperationParams { - simulationId: string; - mapId: number; - tccId: number; - val: number; - handleId: number; -} - -export async function tccHandleOperation(params: TccHandleOperationParams) { - return await api.post(`${UriBase}/tcc/handle/operation`, params); +export async function tccOperation(params: TccOperationParams) { + return await api.post(`${UriBase}/train/control`, params); } export function checkMapData(data: { mapProto: string }) { diff --git a/src/configs/UrlManage.ts b/src/configs/UrlManage.ts index 6a575cd..d22c5bd 100644 --- a/src/configs/UrlManage.ts +++ b/src/configs/UrlManage.ts @@ -9,7 +9,7 @@ function getHost(): string { // return '192.168.3.7:9091'; // return '192.168.3.47:9091'; // return '192.168.3.37:9091'; - return '192.168.33.207:9091'; // 张骞 + //return '192.168.33.207:9091'; // 张骞 // return '192.168.33.93:9091'; // return '192.168.3.37:9091'; //卫志宏 // return 'test.joylink.club/bjrtsts-service'; // 测试 diff --git a/src/drawApp/graphics/TccButtonInteraction.ts b/src/drawApp/graphics/TccButtonInteraction.ts index 191ef9a..54ccd08 100644 --- a/src/drawApp/graphics/TccButtonInteraction.ts +++ b/src/drawApp/graphics/TccButtonInteraction.ts @@ -11,8 +11,9 @@ import { ITccButtonState, TccButton, } from 'src/graphics/tccButton/TccButton'; -import { tccButtonOperation } from 'src/api/Simulation'; +import { tccOperation } from 'src/api/Simulation'; import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; export class TccButtonData extends GraphicDataBase implements ITccButtonData { constructor(data?: tccGraphicData.TccButton) { @@ -115,21 +116,20 @@ export class TccButtonOperateInteraction extends GraphicInteractionPlugin(); - if (!tccButton || !simulationId || !mapId) return; - tccButton.states.down = !tccButton.states.down; - tccButton.doRepaint(); - /* tccButtonOperation({ + if (!tccButton || !simulationId) return; + tccOperation({ simulationId, - mapId, - buttonId: tccButton.id, - tccId, - down: !tccButton.states.down, + trainId: tccId + '', + deviceId: tccButton.id, + controlType: request.TrainControl.TrainControlType.EMERGENT_BUTTON, + button: { + active: !tccButton.states.down, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } } diff --git a/src/drawApp/graphics/TccHandleInteraction.ts b/src/drawApp/graphics/TccHandleInteraction.ts index 9f60ad3..812429e 100644 --- a/src/drawApp/graphics/TccHandleInteraction.ts +++ b/src/drawApp/graphics/TccHandleInteraction.ts @@ -11,8 +11,9 @@ import { GraphicInteractionPlugin, IGraphicScene, JlGraphic } from 'jl-graphic'; import { type FederatedMouseEvent, DisplayObject } from 'pixi.js'; import { useTccStore } from 'src/stores/tcc-store'; import { useLineStore } from 'src/stores/line-store'; -import { tccHandleOperation } from 'src/api/Simulation'; +import { tccOperation } from 'src/api/Simulation'; import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; export class TccHandleData extends GraphicDataBase implements ITccHandleData { constructor(data?: tccGraphicData.TccHandle) { @@ -156,15 +157,17 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { const target = e.target as DisplayObject; const tccHandle = target.getGraphic(); if (!tccHandle || !simulationId || !mapId) return; - tccHandle.doRepaint(); - /* tccHandleOperation({ + const handleVal = Math.floor(-(tccHandle._tccHandle.y / 144) * 100); + tccOperation({ simulationId, - mapId, - handleId: tccHandle.id, - tccId, - val: tccHandle._tccHandle.y, + trainId: tccId + '', + deviceId: tccHandle.id, + controlType: request.TrainControl.TrainControlType.HANDLER, + handler: { + val: handleVal, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } } diff --git a/src/drawApp/graphics/TccKeyInteraction.ts b/src/drawApp/graphics/TccKeyInteraction.ts index 75a16aa..32e6059 100644 --- a/src/drawApp/graphics/TccKeyInteraction.ts +++ b/src/drawApp/graphics/TccKeyInteraction.ts @@ -11,10 +11,10 @@ import { Sprite, } from 'pixi.js'; import { useTccStore } from 'src/stores/tcc-store'; -import { threadId } from 'worker_threads'; import { useLineStore } from 'src/stores/line-store'; -import { tccKeyDirOperation, tccKeyOperation } from 'src/api/Simulation'; +import { tccOperation } from 'src/api/Simulation'; import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; export class TccKeyData extends GraphicDataBase implements ITccKeyData { constructor(data?: tccGraphicData.TccKey) { @@ -97,7 +97,6 @@ export interface IKeyInteractionConfig { gearPositionAmount?: number; keyRotationMethod: KeyRotationMethod; doAfterChangeRotation: (g: JlGraphic, rotation: number) => void; - doFinish: () => void; } export abstract class KeyInteraction< G extends JlGraphic @@ -107,6 +106,7 @@ export abstract class KeyInteraction< mouseDownBeginPos = new Point(); mouseDownBeginRotation = 0; keyInteractionConfig: IKeyInteractionConfig; + lastTimenRotation = 0; constructor( name: string, app: IGraphicScene, @@ -122,7 +122,6 @@ export abstract class KeyInteraction< g.onmouseup = (e) => { e.stopPropagation(); this.isMouseDown = false; - this.keyInteractionConfig.doFinish(); }; } totalUnbind(g: G): void { @@ -148,6 +147,7 @@ export abstract class KeyInteraction< this.isMouseDown = true; this.mouseDownBeginPos = this.app.toCanvasCoordinates(e.global); this.mouseDownBeginRotation = this.ratatingSprite.rotation; + this.lastTimenRotation = this.ratatingSprite.rotation; } onMousemove(e: FederatedMouseEvent) { const target = e.target as DisplayObject; @@ -160,46 +160,44 @@ export abstract class KeyInteraction< g.position, mouseEndPos ); + let changeRotation = 0; if ( this.keyInteractionConfig.keyRotationMethod == KeyRotationMethod.jumpChange ) { if (direction == 'ssz') { if (angle < 45) { - this.ratatingSprite.rotation = this.mouseDownBeginRotation; + changeRotation = this.mouseDownBeginRotation; } - if (angle >= 45 && angle < 90) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation + Math.PI / 4; + if ( + angle >= 45 && + angle < 90 && + this.mouseDownBeginRotation !== Math.PI / 4 + ) { + changeRotation = this.mouseDownBeginRotation + Math.PI / 4; } else if ( angle >= 90 && this.mouseDownBeginRotation == -Math.PI / 4 ) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation + Math.PI / 2; + changeRotation = this.mouseDownBeginRotation + Math.PI / 2; + } + if (this.lastTimenRotation !== changeRotation) { + this.lastTimenRotation = changeRotation; + this.keyInteractionConfig.doAfterChangeRotation(g, changeRotation); } - this.keyInteractionConfig.doAfterChangeRotation( - g, - this.ratatingSprite.rotation - ); } if (direction == 'nsz') { if (angle < 45) { - this.ratatingSprite.rotation = this.mouseDownBeginRotation; + changeRotation = this.mouseDownBeginRotation; } else if (angle >= 45 && angle < 90) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation - Math.PI / 4; - } else if ( - angle >= 90 && - this.mouseDownBeginRotation == Math.PI / 4 - ) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation - Math.PI / 2; + changeRotation = this.mouseDownBeginRotation - Math.PI / 4; + } else if (angle >= 90 && changeRotation == Math.PI / 4) { + changeRotation = this.mouseDownBeginRotation - Math.PI / 2; + } + if (this.lastTimenRotation !== changeRotation) { + this.lastTimenRotation = changeRotation; + this.keyInteractionConfig.doAfterChangeRotation(g, changeRotation); } - this.keyInteractionConfig.doAfterChangeRotation( - g, - this.ratatingSprite.rotation - ); } } else { if (direction == 'ssz') { @@ -223,9 +221,6 @@ export class TccKeyInteraction extends KeyInteraction { doAfterChangeRotation: (g: JlGraphic, rotation: number) => { this.changeState(g, rotation); }, - doFinish: () => { - this.onFinish(); - }, }); } static init(app: IGraphicScene) { @@ -266,17 +261,20 @@ export class TccKeyInteraction extends KeyInteraction { const target = e.target as DisplayObject; const tccKey = target.getGraphic(); if (!tccKey || !simulationId || !mapId) return; - tccKey.state.position = tccKey?.state.position == 0 ? 1 : 0; - tccKey.doRepaint(); - /* tccKeyOperation({ + const state = tccKey?.state.position == 0 ? true : false; + const driverKeyType = tccKey?.datas.code == '司控器钥匙1' ? 0 : 1; + tccOperation({ simulationId, - mapId, - keyId: tccKey.id, - tccId, - val: !tccKey.state.position, + trainId: tccId + '', + deviceId: tccKey.id, + controlType: request.TrainControl.TrainControlType.DRIVER_KEY_SWITCH, + driverKey: { + val: state, + dt: driverKeyType, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } changeState(g: JlGraphic, rotation: number) { let position = 0; @@ -292,22 +290,20 @@ export class TccKeyInteraction extends KeyInteraction { break; } (g as TccKey).state.position = position; - g.doRepaint(); - } - onFinish() { const simulationId = useLineStore().simulationId; - const mapId = useLineStore().mapId; const tccId = useTccStore().tccId; - if (!simulationId || !mapId) return; - /* tccKeyDirOperation({ + if (!simulationId) return; + tccOperation({ simulationId, - mapId, - keyId: g.id, - tccId, - val: (g as TccKey).state.position, + trainId: tccId + '', + deviceId: g.id, + controlType: request.TrainControl.TrainControlType.DIRECTION_KEY_SWITCH, + dirKey: { + val: position, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } } diff --git a/src/graphics/tccHandle/TccHandle.ts b/src/graphics/tccHandle/TccHandle.ts index 258d0fc..c346e01 100644 --- a/src/graphics/tccHandle/TccHandle.ts +++ b/src/graphics/tccHandle/TccHandle.ts @@ -54,7 +54,7 @@ export class TccHandle extends JlGraphic { return this.getStates(); } doRepaint(): void { - this._tccHandle.rotation = (-Math.PI / 2) * this.state.gear; + this._tccHandle.y = -Math.floor((this.state.gear * 144) / 100); this._tccHandle.texture = this.tccHandleTextures.tccHandle; } } diff --git a/src/protos/request.ts b/src/protos/request.ts index 5a70d21..09c9241 100644 --- a/src/protos/request.ts +++ b/src/protos/request.ts @@ -1422,7 +1422,7 @@ export namespace request { #one_of_decls: number[][] = []; constructor(data?: any[] | { simulationId?: string; - trainId?: number; + trainId?: string; deviceId?: number; controlType?: TrainControl.TrainControlType; button?: TrainControl.EmergentButton; @@ -1466,9 +1466,9 @@ export namespace request { pb_1.Message.setField(this, 1, value); } get trainId() { - return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; } - set trainId(value: number) { + set trainId(value: string) { pb_1.Message.setField(this, 2, value); } get deviceId() { @@ -1521,7 +1521,7 @@ export namespace request { } static fromObject(data: { simulationId?: string; - trainId?: number; + trainId?: string; deviceId?: number; controlType?: TrainControl.TrainControlType; button?: ReturnType; @@ -1559,7 +1559,7 @@ export namespace request { toObject() { const data: { simulationId?: string; - trainId?: number; + trainId?: string; deviceId?: number; controlType?: TrainControl.TrainControlType; button?: ReturnType; @@ -1599,8 +1599,8 @@ export namespace request { const writer = w || new pb_1.BinaryWriter(); if (this.simulationId.length) writer.writeString(1, this.simulationId); - if (this.trainId != 0) - writer.writeUint32(2, this.trainId); + if (this.trainId.length) + writer.writeString(2, this.trainId); if (this.deviceId != 0) writer.writeUint32(3, this.deviceId); if (this.controlType != TrainControl.TrainControlType.EMERGENT_BUTTON) @@ -1626,7 +1626,7 @@ export namespace request { message.simulationId = reader.readString(); break; case 2: - message.trainId = reader.readUint32(); + message.trainId = reader.readString(); break; case 3: message.deviceId = reader.readUint32();