Merge branch 'develop' of http://120.46.212.6:3000/joylink/rts-sim-testing-client into develop
This commit is contained in:
commit
2517ab5e8d
@ -10,10 +10,6 @@ import { state } from 'src/protos/device_state';
|
|||||||
import { GraphicInteractionPlugin, IGraphicScene, JlGraphic } from 'jl-graphic';
|
import { GraphicInteractionPlugin, IGraphicScene, JlGraphic } from 'jl-graphic';
|
||||||
import { type FederatedMouseEvent, DisplayObject } from 'pixi.js';
|
import { type FederatedMouseEvent, DisplayObject } from 'pixi.js';
|
||||||
import { useTccStore } from 'src/stores/tcc-store';
|
import { useTccStore } from 'src/stores/tcc-store';
|
||||||
import { useLineStore } from 'src/stores/line-store';
|
|
||||||
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 {
|
export class TccHandleData extends GraphicDataBase implements ITccHandleData {
|
||||||
constructor(data?: tccGraphicData.TccHandle) {
|
constructor(data?: tccGraphicData.TccHandle) {
|
||||||
@ -103,15 +99,15 @@ export class TccHandleInteraction extends GraphicInteractionPlugin<TccHandle> {
|
|||||||
g._tccHandle.eventMode = 'static';
|
g._tccHandle.eventMode = 'static';
|
||||||
g._tccHandle.cursor = 'Move';
|
g._tccHandle.cursor = 'Move';
|
||||||
g._tccHandle.onmousedown = (e) => {
|
g._tccHandle.onmousedown = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
this.onMouseDown(e);
|
this.onMouseDown(e);
|
||||||
};
|
};
|
||||||
g._tccHandle.onmouseup = (e) => {
|
g._tccHandle.onmouseup = (e) => {
|
||||||
this.onMouseUp(e);
|
e.stopPropagation();
|
||||||
|
this.onMouseUp();
|
||||||
};
|
};
|
||||||
g.onmousemove = (e) => {
|
g.onmousemove = (e) => {
|
||||||
this.onMouseMove(e);
|
e.stopPropagation();
|
||||||
};
|
|
||||||
g.onmouseleave = (e) => {
|
|
||||||
this.onMouseMove(e);
|
this.onMouseMove(e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -120,12 +116,13 @@ export class TccHandleInteraction extends GraphicInteractionPlugin<TccHandle> {
|
|||||||
g._tccHandle.onmousedown = null;
|
g._tccHandle.onmousedown = null;
|
||||||
g._tccHandle.onmouseup = null;
|
g._tccHandle.onmouseup = null;
|
||||||
g.onmousemove = null;
|
g.onmousemove = null;
|
||||||
g.onmouseleave = null;
|
|
||||||
}
|
}
|
||||||
onMouseDown(e: FederatedMouseEvent) {
|
onMouseDown(e: FederatedMouseEvent) {
|
||||||
const target = e.target as DisplayObject;
|
const target = e.target as DisplayObject;
|
||||||
const tccHandle = target.getGraphic<TccHandle>();
|
const tccHandle = target.getGraphic<TccHandle>();
|
||||||
if (!tccHandle) return;
|
if (!tccHandle) return;
|
||||||
|
useTccStore().tccHandleId = tccHandle.id;
|
||||||
|
useTccStore().mouseDownOnTccHandle = true;
|
||||||
this.isMouseDown = true;
|
this.isMouseDown = true;
|
||||||
this.mouseDownBeginPos = e.clientY;
|
this.mouseDownBeginPos = e.clientY;
|
||||||
this.mouseDownTccHandleBeginPos = tccHandle._tccHandle.y;
|
this.mouseDownTccHandleBeginPos = tccHandle._tccHandle.y;
|
||||||
@ -149,25 +146,8 @@ export class TccHandleInteraction extends GraphicInteractionPlugin<TccHandle> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseUp(e: FederatedMouseEvent) {
|
onMouseUp() {
|
||||||
this.isMouseDown = false;
|
this.isMouseDown = false;
|
||||||
const simulationId = useLineStore().simulationId;
|
useTccStore().mouseDownOnTccHandle = false;
|
||||||
const mapId = useLineStore().mapId;
|
|
||||||
const tccId = useTccStore().tccId;
|
|
||||||
const target = e.target as DisplayObject;
|
|
||||||
const tccHandle = target.getGraphic<TccHandle>();
|
|
||||||
if (!tccHandle || !simulationId || !mapId) return;
|
|
||||||
const handleVal = Math.floor(-(tccHandle._tccHandle.y / 144) * 100);
|
|
||||||
tccOperation({
|
|
||||||
simulationId,
|
|
||||||
trainId: tccId + '',
|
|
||||||
deviceId: tccHandle.id,
|
|
||||||
controlType: request.TrainControl.TrainControlType.HANDLER,
|
|
||||||
handler: {
|
|
||||||
val: handleVal,
|
|
||||||
},
|
|
||||||
}).catch((err) => {
|
|
||||||
errorNotify('操作失败', { message: err.origin.response.data.title });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ export enum KeyRotationMethod {
|
|||||||
export interface IKeyInteractionConfig {
|
export interface IKeyInteractionConfig {
|
||||||
gearPositionAmount?: number;
|
gearPositionAmount?: number;
|
||||||
keyRotationMethod: KeyRotationMethod;
|
keyRotationMethod: KeyRotationMethod;
|
||||||
doAfterChangeRotation: (g: JlGraphic, rotation: number) => void;
|
doAfterChangeRotation: () => void;
|
||||||
}
|
}
|
||||||
export abstract class KeyInteraction<
|
export abstract class KeyInteraction<
|
||||||
G extends JlGraphic
|
G extends JlGraphic
|
||||||
@ -105,6 +105,7 @@ export abstract class KeyInteraction<
|
|||||||
ratatingSprite: Sprite = new Sprite();
|
ratatingSprite: Sprite = new Sprite();
|
||||||
mouseDownBeginPos = new Point();
|
mouseDownBeginPos = new Point();
|
||||||
mouseDownBeginRotation = 0;
|
mouseDownBeginRotation = 0;
|
||||||
|
changeRotation = 0;
|
||||||
keyInteractionConfig: IKeyInteractionConfig;
|
keyInteractionConfig: IKeyInteractionConfig;
|
||||||
lastTimenRotation = 0;
|
lastTimenRotation = 0;
|
||||||
constructor(
|
constructor(
|
||||||
@ -122,11 +123,17 @@ export abstract class KeyInteraction<
|
|||||||
g.onmouseup = (e) => {
|
g.onmouseup = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.isMouseDown = false;
|
this.isMouseDown = false;
|
||||||
|
this.keyInteractionConfig.doAfterChangeRotation();
|
||||||
|
};
|
||||||
|
g.onmousedown = () => {
|
||||||
|
useTccStore().tccKeyDirId = g.id;
|
||||||
|
useTccStore().mouseDownOnTccKeyDir = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
totalUnbind(g: G): void {
|
totalUnbind(g: G): void {
|
||||||
g.onmousemove = null;
|
g.onmousemove = null;
|
||||||
g.onmouseup = null;
|
g.onmouseup = null;
|
||||||
|
g.onmousedown = null;
|
||||||
}
|
}
|
||||||
keyBind(g: Sprite): void {
|
keyBind(g: Sprite): void {
|
||||||
this.ratatingSprite = g;
|
this.ratatingSprite = g;
|
||||||
@ -147,6 +154,7 @@ export abstract class KeyInteraction<
|
|||||||
this.isMouseDown = true;
|
this.isMouseDown = true;
|
||||||
this.mouseDownBeginPos = this.app.toCanvasCoordinates(e.global);
|
this.mouseDownBeginPos = this.app.toCanvasCoordinates(e.global);
|
||||||
this.mouseDownBeginRotation = this.ratatingSprite.rotation;
|
this.mouseDownBeginRotation = this.ratatingSprite.rotation;
|
||||||
|
this.changeRotation = this.mouseDownBeginRotation;
|
||||||
this.lastTimenRotation = this.ratatingSprite.rotation;
|
this.lastTimenRotation = this.ratatingSprite.rotation;
|
||||||
}
|
}
|
||||||
onMousemove(e: FederatedMouseEvent) {
|
onMousemove(e: FederatedMouseEvent) {
|
||||||
@ -160,45 +168,46 @@ export abstract class KeyInteraction<
|
|||||||
g.position,
|
g.position,
|
||||||
mouseEndPos
|
mouseEndPos
|
||||||
);
|
);
|
||||||
let changeRotation = 0;
|
|
||||||
if (
|
if (
|
||||||
this.keyInteractionConfig.keyRotationMethod ==
|
this.keyInteractionConfig.keyRotationMethod ==
|
||||||
KeyRotationMethod.jumpChange
|
KeyRotationMethod.jumpChange
|
||||||
) {
|
) {
|
||||||
if (direction == 'ssz') {
|
if (direction == 'ssz') {
|
||||||
if (angle < 45) {
|
if (angle < 45) {
|
||||||
changeRotation = this.mouseDownBeginRotation;
|
this.changeRotation = this.mouseDownBeginRotation;
|
||||||
}
|
} else if (
|
||||||
if (
|
|
||||||
angle >= 45 &&
|
angle >= 45 &&
|
||||||
angle < 90 &&
|
angle < 90 &&
|
||||||
this.mouseDownBeginRotation !== Math.PI / 4
|
this.mouseDownBeginRotation !== Math.PI / 4
|
||||||
) {
|
) {
|
||||||
changeRotation = this.mouseDownBeginRotation + Math.PI / 4;
|
this.changeRotation = this.mouseDownBeginRotation + Math.PI / 4;
|
||||||
} else if (
|
} else if (
|
||||||
angle >= 90 &&
|
angle >= 90 &&
|
||||||
this.mouseDownBeginRotation == -Math.PI / 4
|
this.mouseDownBeginRotation == -Math.PI / 4
|
||||||
) {
|
) {
|
||||||
changeRotation = this.mouseDownBeginRotation + Math.PI / 2;
|
this.changeRotation = this.mouseDownBeginRotation + Math.PI / 2;
|
||||||
}
|
|
||||||
if (this.lastTimenRotation !== changeRotation) {
|
|
||||||
this.lastTimenRotation = changeRotation;
|
|
||||||
this.keyInteractionConfig.doAfterChangeRotation(g, changeRotation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (direction == 'nsz') {
|
if (direction == 'nsz') {
|
||||||
if (angle < 45) {
|
if (angle < 45) {
|
||||||
changeRotation = this.mouseDownBeginRotation;
|
this.changeRotation = this.mouseDownBeginRotation;
|
||||||
} else if (angle >= 45 && angle < 90) {
|
} else if (
|
||||||
changeRotation = this.mouseDownBeginRotation - Math.PI / 4;
|
angle >= 45 &&
|
||||||
} else if (angle >= 90 && changeRotation == Math.PI / 4) {
|
angle < 90 &&
|
||||||
changeRotation = this.mouseDownBeginRotation - Math.PI / 2;
|
this.mouseDownBeginRotation !== -Math.PI / 4
|
||||||
}
|
) {
|
||||||
if (this.lastTimenRotation !== changeRotation) {
|
this.changeRotation = this.mouseDownBeginRotation - Math.PI / 4;
|
||||||
this.lastTimenRotation = changeRotation;
|
} else if (
|
||||||
this.keyInteractionConfig.doAfterChangeRotation(g, changeRotation);
|
angle >= 90 &&
|
||||||
|
this.mouseDownBeginRotation == Math.PI / 4
|
||||||
|
) {
|
||||||
|
this.changeRotation = this.mouseDownBeginRotation - Math.PI / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.lastTimenRotation !== this.changeRotation) {
|
||||||
|
this.lastTimenRotation = this.changeRotation;
|
||||||
|
this.ratatingSprite.rotation = this.changeRotation;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (direction == 'ssz') {
|
if (direction == 'ssz') {
|
||||||
this.ratatingSprite.rotation =
|
this.ratatingSprite.rotation =
|
||||||
@ -218,8 +227,8 @@ export class TccKeyInteraction extends KeyInteraction<TccKey> {
|
|||||||
super(TccKeyInteraction.Name, app, {
|
super(TccKeyInteraction.Name, app, {
|
||||||
gearPositionAmount: 3,
|
gearPositionAmount: 3,
|
||||||
keyRotationMethod: KeyRotationMethod.jumpChange,
|
keyRotationMethod: KeyRotationMethod.jumpChange,
|
||||||
doAfterChangeRotation: (g: JlGraphic, rotation: number) => {
|
doAfterChangeRotation: () => {
|
||||||
this.changeState(g, rotation);
|
this.changeState();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -276,34 +285,8 @@ export class TccKeyInteraction extends KeyInteraction<TccKey> {
|
|||||||
errorNotify('操作失败', { message: err.origin.response.data.title });
|
errorNotify('操作失败', { message: err.origin.response.data.title });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
changeState(g: JlGraphic, rotation: number) {
|
changeState() {
|
||||||
let position = 0;
|
useTccStore().mouseDownOnTccKeyDir = false;
|
||||||
switch (rotation) {
|
|
||||||
case Math.PI / 4:
|
|
||||||
position = 0;
|
|
||||||
break;
|
|
||||||
case -Math.PI / 4:
|
|
||||||
position = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
position = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(g as TccKey).state.position = position;
|
|
||||||
const simulationId = useLineStore().simulationId;
|
|
||||||
const tccId = useTccStore().tccId;
|
|
||||||
if (!simulationId) return;
|
|
||||||
tccOperation({
|
|
||||||
simulationId,
|
|
||||||
trainId: tccId + '',
|
|
||||||
deviceId: g.id,
|
|
||||||
controlType: request.TrainControl.TrainControlType.DIRECTION_KEY_SWITCH,
|
|
||||||
dirKey: {
|
|
||||||
val: position,
|
|
||||||
},
|
|
||||||
}).catch((err) => {
|
|
||||||
errorNotify('操作失败', { message: err.origin.response.data.title });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,14 @@ export function initTccScene(lineApp: IGraphicApp, sceneName: string) {
|
|||||||
};
|
};
|
||||||
tccScene.canvas.onmouseup = () => {
|
tccScene.canvas.onmouseup = () => {
|
||||||
tccStore.canvasMouseDown = false;
|
tccStore.canvasMouseDown = false;
|
||||||
|
if (tccStore.mouseDownOnTccHandle) {
|
||||||
|
tccStore.onMouseUpFromTccHandle();
|
||||||
|
tccStore.mouseDownOnTccHandle = false;
|
||||||
|
}
|
||||||
|
if (tccStore.mouseDownOnTccKeyDir) {
|
||||||
|
tccStore.onMouseUpFromTccKeyDir();
|
||||||
|
tccStore.mouseDownOnTccKeyDir = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
lineApp.on('destroy', () => {
|
lineApp.on('destroy', () => {
|
||||||
tccScene.canvas.onmousedown = null;
|
tccScene.canvas.onmousedown = null;
|
||||||
|
@ -54,7 +54,7 @@ export class TccHandle extends JlGraphic {
|
|||||||
return this.getStates<ITccHandleState>();
|
return this.getStates<ITccHandleState>();
|
||||||
}
|
}
|
||||||
doRepaint(): void {
|
doRepaint(): void {
|
||||||
this._tccHandle.y = -Math.floor((this.state.gear * 144) / 100);
|
this._tccHandle.y = -(this.state.gear * 144) / 100;
|
||||||
this._tccHandle.texture = this.tccHandleTextures.tccHandle;
|
this._tccHandle.texture = this.tccHandleTextures.tccHandle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { initTccScene } from 'src/drawApp/tccScene';
|
import { initTccScene } from 'src/drawApp/tccScene';
|
||||||
import { getLineApp } from 'src/drawApp/lineApp';
|
import { getLineApp } from 'src/drawApp/lineApp';
|
||||||
|
import { useLineStore } from './line-store';
|
||||||
|
import { tccOperation } from 'src/api/Simulation';
|
||||||
|
import { errorNotify } from 'src/utils/CommonNotify';
|
||||||
|
import { request } from 'src/protos/request';
|
||||||
|
import { TccHandle } from 'src/graphics/tccHandle/TccHandle';
|
||||||
|
import { TccKey } from 'src/graphics/tccKey/TccKey';
|
||||||
|
|
||||||
export const useTccStore = defineStore('tcc', {
|
export const useTccStore = defineStore('tcc', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@ -8,6 +14,10 @@ export const useTccStore = defineStore('tcc', {
|
|||||||
tccId: 0,
|
tccId: 0,
|
||||||
isTccDialogOpen: false,
|
isTccDialogOpen: false,
|
||||||
canvasMouseDown: false,
|
canvasMouseDown: false,
|
||||||
|
mouseDownOnTccHandle: false,
|
||||||
|
tccHandleId: 0,
|
||||||
|
mouseDownOnTccKeyDir: false,
|
||||||
|
tccKeyDirId: 0,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
getTccScene() {
|
getTccScene() {
|
||||||
@ -30,5 +40,56 @@ export const useTccStore = defineStore('tcc', {
|
|||||||
this.trainControlMapId = 0;
|
this.trainControlMapId = 0;
|
||||||
this.isTccDialogOpen = false;
|
this.isTccDialogOpen = false;
|
||||||
},
|
},
|
||||||
|
onMouseUpFromTccHandle() {
|
||||||
|
const simulationId = useLineStore().simulationId;
|
||||||
|
const tccHandle = this.getTccScene().queryStore.queryById<TccHandle>(
|
||||||
|
this.tccHandleId
|
||||||
|
);
|
||||||
|
if (!simulationId) return;
|
||||||
|
const handleVal = Number(
|
||||||
|
(-(tccHandle._tccHandle.y / 144) * 100).toFixed()
|
||||||
|
);
|
||||||
|
tccOperation({
|
||||||
|
simulationId,
|
||||||
|
trainId: this.tccId + '',
|
||||||
|
deviceId: this.tccHandleId,
|
||||||
|
controlType: request.TrainControl.TrainControlType.HANDLER,
|
||||||
|
handler: {
|
||||||
|
val: handleVal,
|
||||||
|
},
|
||||||
|
}).catch((err) => {
|
||||||
|
errorNotify('操作失败', { message: err.origin.response.data.title });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onMouseUpFromTccKeyDir() {
|
||||||
|
const tccKeyDir = this.getTccScene().queryStore.queryById<TccKey>(
|
||||||
|
this.tccKeyDirId
|
||||||
|
);
|
||||||
|
let position = 0;
|
||||||
|
switch (tccKeyDir._tccKey.rotation) {
|
||||||
|
case Math.PI / 4:
|
||||||
|
position = 0;
|
||||||
|
break;
|
||||||
|
case -Math.PI / 4:
|
||||||
|
position = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
position = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const simulationId = useLineStore().simulationId;
|
||||||
|
if (!simulationId) return;
|
||||||
|
tccOperation({
|
||||||
|
simulationId,
|
||||||
|
trainId: this.tccId + '',
|
||||||
|
deviceId: this.tccKeyDirId,
|
||||||
|
controlType: request.TrainControl.TrainControlType.DIRECTION_KEY_SWITCH,
|
||||||
|
dirKey: {
|
||||||
|
val: position,
|
||||||
|
},
|
||||||
|
}).catch((err) => {
|
||||||
|
errorNotify('操作失败', { message: err.origin.response.data.title });
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user