From 4adeaedd5a24e7e9267a050f30e804df3e791161 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Sun, 4 Feb 2024 18:22:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E6=B7=BB=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E6=95=B4=EF=BC=8C=E5=88=97=E8=BD=A6=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=88=A0=E9=99=A4=EF=BC=8C=E6=91=81=E9=92=AE=E6=97=81?= =?UTF-8?q?=E8=B7=AF=EF=BC=8C=E6=97=81=E8=B7=AF=E5=A4=8D=E4=BD=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/common.go | 6 ++++++ component/ibp.go | 1 + fi/ibp.go | 44 ++++++++++++++++++++++++++++++++++++++++++ sys/circuit_sys/ibp.go | 8 ++++++++ sys/circuit_sys/psd.go | 23 ++++++++++++++++------ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/component/common.go b/component/common.go index 127f155..61a89b4 100644 --- a/component/common.go +++ b/component/common.go @@ -16,6 +16,11 @@ var ( BitStateType = ecs.NewComponentType[BitState]() ) +type Bypass struct { + BypassEnable bool // 摁钮,钥匙 是否旁路 + OldVal bool //摁钮旁路旧值 +} + // 唯一ID组件 type Uid struct { Id string @@ -45,6 +50,7 @@ func CalculateTwoPositionAvgSpeed(t int, tick int) int32 { // 仅有两状态的组件 type BitState struct { + Bypass Val bool } diff --git a/component/ibp.go b/component/ibp.go index cea6c90..6017d39 100644 --- a/component/ibp.go +++ b/component/ibp.go @@ -45,6 +45,7 @@ var AlarmDriveType = ecs.NewComponentType[AlarmDrive]() // 挡位组件 type GearState struct { + Bypass Val int32 } diff --git a/fi/ibp.go b/fi/ibp.go index f1abf3d..d2fa9d2 100644 --- a/fi/ibp.go +++ b/fi/ibp.go @@ -2,6 +2,7 @@ package fi import ( "fmt" + "joylink.club/bj-rtsts-server/dto/request_proto" "joylink.club/ecs" "joylink.club/rtsssimulation/component" @@ -16,6 +17,7 @@ func PressDownButton(w ecs.World, id string) error { if ok { state := component.BitStateType.Get(entry) state.Val = true + } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) } @@ -32,6 +34,7 @@ func PressUpButton(w ecs.World, id string) error { if ok { state := component.BitStateType.Get(entry) state.Val = false + } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) } @@ -48,6 +51,7 @@ func SwitchKeyGear(w ecs.World, id string, gear int32) error { if ok { state := component.GearStateType.Get(entry) state.Val = gear + } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的钥匙开关", id)) } @@ -55,3 +59,43 @@ func SwitchKeyGear(w ecs.World, id string, gear int32) error { }) return result.Err } + +func SetBypassBtn(w ecs.World, id string, p request_proto.BypassOperationReq_Operation) error { + + result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { + wd := entity.GetWorldData(w) + entry, ok := wd.EntityMap[id] + if ok { + state := component.BitStateType.Get(entry) + state.Bypass.BypassEnable = convertBypassBoolVal(p) + state.Bypass.OldVal = state.Val + } else { + return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) + } + return ecs.NewOkEmptyResult() + }) + return result.Err +} +func SetBypassSwitchKey(w ecs.World, id string, p request_proto.BypassOperationReq_Operation) error { + result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { + wd := entity.GetWorldData(w) + entry, ok := wd.EntityMap[id] + if ok { + state := component.GearStateType.Get(entry) + state.BypassEnable = convertBypassBoolVal(p) + state.OldVal = state.Val == 0 + } else { + return ecs.NewErrResult(fmt.Errorf("未找到id=%s的钥匙开关", id)) + } + return ecs.NewOkEmptyResult() + }) + return result.Err +} + +func convertBypassBoolVal(p request_proto.BypassOperationReq_Operation) bool { + val := true + if p == request_proto.BypassOperationReq_bypass_reset { + val = false + } + return val +} diff --git a/sys/circuit_sys/ibp.go b/sys/circuit_sys/ibp.go index caaab97..374326c 100644 --- a/sys/circuit_sys/ibp.go +++ b/sys/circuit_sys/ibp.go @@ -113,12 +113,20 @@ func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) { // 获取按钮状态 func getIbpBtnVal(entry *ecs.Entry) bool { btn := component.BitStateType.Get(entry) + //旁路后返回之前的值 + if btn.BypassEnable { + return btn.OldVal + } return btn.Val } // 获取按钮状态 func getIbpKeyVal(entry *ecs.Entry) bool { btn := component.GearStateType.Get(entry) + //旁路后返回之前的值 + if btn.BypassEnable { + return btn.OldVal + } return btn.Val == 0 } diff --git a/sys/circuit_sys/psd.go b/sys/circuit_sys/psd.go index 86c666c..dfbe5c5 100644 --- a/sys/circuit_sys/psd.go +++ b/sys/circuit_sys/psd.go @@ -70,14 +70,25 @@ func (p *PsdSys) Update(world ecs.World) { var pabTd bool for _, mkxEntry := range pmc.MkxList { mkx := component.MkxType.Get(mkxEntry) - if mkx.PCB != nil && component.BitStateType.Get(mkx.PCB).Val { - pcbTd = true + pcb := component.BitStateType.Get(mkx.PCB) + if !pcb.BypassEnable { + if mkx.PCB != nil && pcb.Val { + pcbTd = true + } } - if mkx.POB != nil && component.BitStateType.Get(mkx.POB).Val { - pobTd = true + + pob := component.BitStateType.Get(mkx.POB) + if !pob.BypassEnable { + if mkx.POB != nil && pob.Val { + pobTd = true + } } - if mkx.PAB != nil && component.BitStateType.Get(mkx.PAB).Val { - pabTd = true + + pab := component.BitStateType.Get(mkx.PAB) + if !pab.BypassEnable { + if mkx.PAB != nil && pab.Val { + pabTd = true + } } } if pmc.PCBJ != nil {