diff --git a/fi/signal.go b/fi/signal.go index 2c32851..47cba7f 100644 --- a/fi/signal.go +++ b/fi/signal.go @@ -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 {