列车添加参数调整,列车全部删除,摁钮旁路,旁路复位功能

This commit is contained in:
tiger_zhou 2024-02-04 18:22:52 +08:00
parent b54224351f
commit 4adeaedd5a
5 changed files with 76 additions and 6 deletions

View File

@ -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
}

View File

@ -45,6 +45,7 @@ var AlarmDriveType = ecs.NewComponentType[AlarmDrive]()
// 挡位组件
type GearState struct {
Bypass
Val int32
}

View File

@ -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
}

View File

@ -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
}

View File

@ -70,16 +70,27 @@ 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 {
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 {
}
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 {
}
pab := component.BitStateType.Get(mkx.PAB)
if !pab.BypassEnable {
if mkx.PAB != nil && pab.Val {
pabTd = true
}
}
}
if pmc.PCBJ != nil {
component.RelayDriveType.Get(pmc.PCBJ).Td = pcbTd
psc.MkxGM = component.BitStateType.Get(pmc.PCBJ).Val