From 896db9e6e9af6e816feecde3580be7e13dba576c Mon Sep 17 00:00:00 2001 From: walker Date: Thu, 18 Jan 2024 13:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA=E7=81=AF=E4=B8=9D?= =?UTF-8?q?=E6=96=AD=E4=B8=9D=E6=95=85=E9=9A=9C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fi/signal.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 {