驾驶台手柄0位范围扩大,在范围内自动吸附到0位

This commit is contained in:
joylink_zhaoerwei 2024-08-29 17:27:47 +08:00
parent f61ee0610c
commit e39774e4bc
2 changed files with 22 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import Tcc_Handle_JSON from './tcc-handle-data.json';
import { Assets, Sprite, Spritesheet, Texture } from 'pixi.js'; import { Assets, Sprite, Spritesheet, Texture } from 'pixi.js';
export const zeroOffset = 9;
interface TccHandleTextures { interface TccHandleTextures {
tccHandle: Texture; tccHandle: Texture;
handleBackground: Texture; handleBackground: Texture;
@ -54,7 +55,14 @@ export class TccHandle extends JlGraphic {
return this.getStates<ITccHandleState>(); return this.getStates<ITccHandleState>();
} }
doRepaint(): void { doRepaint(): void {
this._tccHandle.y = -(this.state.gear * 144) / 100; const pos = -(this.state.gear * (144 - zeroOffset)) / 100;
if (pos > 0) {
this._tccHandle.y = pos + zeroOffset;
} else if (pos < 0) {
this._tccHandle.y = pos - zeroOffset;
} else {
this._tccHandle.y = 0;
}
this._tccHandle.texture = this.tccHandleTextures.tccHandle; this._tccHandle.texture = this.tccHandleTextures.tccHandle;
} }
} }

View File

@ -5,7 +5,7 @@ import { useLineStore } from './line-store';
import { tccOperation } from 'src/api/Simulation'; import { tccOperation } from 'src/api/Simulation';
import { errorNotify } from 'src/utils/CommonNotify'; import { errorNotify } from 'src/utils/CommonNotify';
import { request } from 'src/protos/request'; import { request } from 'src/protos/request';
import { TccHandle } from 'src/graphics/tccHandle/TccHandle'; import { TccHandle, zeroOffset } from 'src/graphics/tccHandle/TccHandle';
import { TccKey } from 'src/graphics/tccKey/TccKey'; import { TccKey } from 'src/graphics/tccKey/TccKey';
import { IGraphicApp } from 'jl-graphic'; import { IGraphicApp } from 'jl-graphic';
@ -47,8 +47,19 @@ export const useTccStore = defineStore('tcc', {
.getScene(`tcc${this.tccId}`) .getScene(`tcc${this.tccId}`)
.queryStore.queryById<TccHandle>(this.tccHandleId); .queryStore.queryById<TccHandle>(this.tccHandleId);
if (!simulationId) return; if (!simulationId) return;
let transFormHandleVal = 0;
if (
tccHandle._tccHandle.y >= -zeroOffset &&
tccHandle._tccHandle.y <= zeroOffset
) {
tccHandle._tccHandle.y = 0;
} else if (tccHandle._tccHandle.y < -zeroOffset) {
transFormHandleVal = tccHandle._tccHandle.y + zeroOffset;
} else {
transFormHandleVal = tccHandle._tccHandle.y - zeroOffset;
}
const handleVal = Number( const handleVal = Number(
(-(tccHandle._tccHandle.y / 144) * 100).toFixed() (-(transFormHandleVal / (144 - zeroOffset)) * 100).toFixed()
); );
tccOperation({ tccOperation({
simulationId, simulationId,