道岔失表状态

This commit is contained in:
dong 2023-10-07 10:52:53 +08:00
parent 971929e867
commit 07174d8fc8
3 changed files with 46 additions and 16 deletions

View File

@ -327,6 +327,12 @@ export class TurnoutStates extends GraphicStateBase implements ITurnoutState {
set turning(turning: boolean) { set turning(turning: boolean) {
this.states.turning = turning; this.states.turning = turning;
} }
get split(): boolean {
return this.states.split;
}
set split(split: boolean) {
this.states.split = split;
}
get states(): state.SwitchState { get states(): state.SwitchState {
return this.getState<state.SwitchState>(); return this.getState<state.SwitchState>();
} }

View File

@ -60,6 +60,7 @@ export interface ITurnoutState extends GraphicState {
normal?: boolean; normal?: boolean;
reverse?: boolean; reverse?: boolean;
turning?: boolean; turning?: boolean;
split?: boolean;
} }
export const TurnoutConsts = { export const TurnoutConsts = {
@ -208,18 +209,18 @@ export class Turnout extends JlGraphic {
this.graphics.sections.forEach((sectionGraphic) => sectionGraphic.paint()); this.graphics.sections.forEach((sectionGraphic) => sectionGraphic.paint());
this.graphics.label.text = this.datas.code; this.graphics.label.text = this.datas.code;
if (this.states.turning) { if (this.states.split) {
this.initTurnoutTurning(); this.initTurnoutSplit();
} else { } else {
this.stopTurnoutTurning(); this.stopTurnoutSplit();
} }
} }
initTurnoutTurning() { initTurnoutSplit() {
// 道岔转动 // 道岔失表
const name = `${this.datas.id}_turnout_turning`; const name = `${this.datas.id}_turnout_split`;
let turnoutTurning = this.animation(name); let turnoutSplit = this.animation(name);
if (!turnoutTurning) { if (!turnoutSplit) {
turnoutTurning = GraphicAnimation.init({ turnoutSplit = GraphicAnimation.init({
name: name, name: name,
run: (dt: number) => { run: (dt: number) => {
this.deltaTime += dt; this.deltaTime += dt;
@ -227,15 +228,15 @@ export class Turnout extends JlGraphic {
this.graphics.fork.visible = this.deltaTime > 30; this.graphics.fork.visible = this.deltaTime > 30;
}, },
}); });
this.addAnimation(turnoutTurning); this.addAnimation(turnoutSplit);
} }
turnoutTurning.resume(); turnoutSplit.resume();
} }
stopTurnoutTurning() { stopTurnoutSplit() {
const name = `${this.datas.id}_turnout_turning`; const name = `${this.datas.id}_turnout_split`;
const turnoutTurning = this.animation(name); const turnoutSplit = this.animation(name);
if (turnoutTurning) { if (turnoutSplit) {
turnoutTurning.pause(); turnoutSplit.pause();
this.deltaTime = 0; this.deltaTime = 0;
} }
} }

View File

@ -221,6 +221,7 @@ export namespace state {
normal?: boolean; normal?: boolean;
reverse?: boolean; reverse?: boolean;
turning?: boolean; turning?: boolean;
split?: boolean;
}) { }) {
super(); super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls);
@ -237,6 +238,9 @@ export namespace state {
if ("turning" in data && data.turning != undefined) { if ("turning" in data && data.turning != undefined) {
this.turning = data.turning; this.turning = data.turning;
} }
if ("split" in data && data.split != undefined) {
this.split = data.split;
}
} }
} }
get id() { get id() {
@ -263,11 +267,18 @@ export namespace state {
set turning(value: boolean) { set turning(value: boolean) {
pb_1.Message.setField(this, 4, value); pb_1.Message.setField(this, 4, value);
} }
get split() {
return pb_1.Message.getFieldWithDefault(this, 5, false) as boolean;
}
set split(value: boolean) {
pb_1.Message.setField(this, 5, value);
}
static fromObject(data: { static fromObject(data: {
id?: string; id?: string;
normal?: boolean; normal?: boolean;
reverse?: boolean; reverse?: boolean;
turning?: boolean; turning?: boolean;
split?: boolean;
}): SwitchState { }): SwitchState {
const message = new SwitchState({}); const message = new SwitchState({});
if (data.id != null) { if (data.id != null) {
@ -282,6 +293,9 @@ export namespace state {
if (data.turning != null) { if (data.turning != null) {
message.turning = data.turning; message.turning = data.turning;
} }
if (data.split != null) {
message.split = data.split;
}
return message; return message;
} }
toObject() { toObject() {
@ -290,6 +304,7 @@ export namespace state {
normal?: boolean; normal?: boolean;
reverse?: boolean; reverse?: boolean;
turning?: boolean; turning?: boolean;
split?: boolean;
} = {}; } = {};
if (this.id != null) { if (this.id != null) {
data.id = this.id; data.id = this.id;
@ -303,6 +318,9 @@ export namespace state {
if (this.turning != null) { if (this.turning != null) {
data.turning = this.turning; data.turning = this.turning;
} }
if (this.split != null) {
data.split = this.split;
}
return data; return data;
} }
serialize(): Uint8Array; serialize(): Uint8Array;
@ -317,6 +335,8 @@ export namespace state {
writer.writeBool(3, this.reverse); writer.writeBool(3, this.reverse);
if (this.turning != false) if (this.turning != false)
writer.writeBool(4, this.turning); writer.writeBool(4, this.turning);
if (this.split != false)
writer.writeBool(5, this.split);
if (!w) if (!w)
return writer.getResultBuffer(); return writer.getResultBuffer();
} }
@ -338,6 +358,9 @@ export namespace state {
case 4: case 4:
message.turning = reader.readBool(); message.turning = reader.readBool();
break; break;
case 5:
message.split = reader.readBool();
break;
default: reader.skipField(); default: reader.skipField();
} }
} }