信号机灯丝断丝故障接口

This commit is contained in:
walker 2024-01-18 13:09:36 +08:00
parent f90563f821
commit 896db9e6e9

View File

@ -2,6 +2,7 @@ package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
@ -44,6 +45,31 @@ func UpdateSignalLightFault(w ecs.World, signalId string, light component_proto.
return r.Err
}
// 更新信号机灯丝断丝故障
func UpdateSignalFaultDS(w ecs.World, uid string, light []component_proto.Light_Color) error {
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[uid]
if ok {
lights := component.SignalLightsType.Get(signalEntry)
// 先清除所有故障
for _, e := range lights.Lights {
e.RemoveComponent(component.LightFaultDsType)
}
// 设置故障
for _, light := range light {
lightEntry := component.SignalLightsType.Get(signalEntry).GetLightByColor(light)
if lightEntry == nil {
return ecs.NewErrResult(fmt.Errorf("信号机[%s]没有色灯[%d]", uid, light))
}
lightEntry.AddComponent(component.LightFaultDsType)
}
}
return ecs.NewOkEmptyResult()
})
return r.Err
}
// SignalLightDrive 当没有电路时,直接驱动信号机灯位上的灯
// ldLights : 需要亮的灯;当为空时则信号机所有色灯灭灯
func SignalLightDrive(w ecs.World, signalId string, ldLights ...component_proto.Light_Color) error {