From 549eaeba358fbf8dacfb189fffd9a8250872ad2b Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 20 Oct 2023 13:51:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=B8=A6=E7=94=B5=E8=B7=AF=E7=9A=84?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/signal.go | 10 ++++++++++ fi/signal.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/component/signal.go b/component/signal.go index a1b28f1..cc70a66 100644 --- a/component/signal.go +++ b/component/signal.go @@ -43,6 +43,16 @@ func (sl *SignalLights) GetLightByColor(light component_proto.Light_Color) *ecs. return nil } +// HaveLightsByColor 判断信号机是否有这几个色灯 +func (sl *SignalLights) HaveLightsByColor(lights ...component_proto.Light_Color) bool { + for _, light := range lights { + if sl.GetLightByColor(light) == nil { + return false + } + } + return true +} + ////////////////////////////////////////////////////////////////// var ( diff --git a/fi/signal.go b/fi/signal.go index df53284..2c32851 100644 --- a/fi/signal.go +++ b/fi/signal.go @@ -43,3 +43,36 @@ func UpdateSignalLightFault(w ecs.World, signalId string, light component_proto. }) return r.Err } + +// SignalLightDrive 当没有电路时,直接驱动信号机灯位上的灯 +// ldLights : 需要亮的灯;当为空时则信号机所有色灯灭灯 +func SignalLightDrive(w ecs.World, signalId string, ldLights ...component_proto.Light_Color) error { + r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { + wd := entity.GetWorldData(w) + signalEntry, ok := wd.EntityMap[signalId] + if !ok { + return ecs.NewErrResult(fmt.Errorf("信号机[%s]不存实体", signalId)) + } + // + lights := component.SignalLightsType.Get(signalEntry) + //ldLights色灯亮 + if len(ldLights) > 0 { //色灯亮 + if !lights.HaveLightsByColor(ldLights...) { + return ecs.NewErrResult(fmt.Errorf("要点亮的这几个色灯不在信号机[%s]的灯位中", signalId)) + } + for _, mdLightEntry := range lights.Lights { + component.LightDriveType.Get(mdLightEntry).Td = false + } + for _, ldLight := range ldLights { + ldLightEntry := lights.GetLightByColor(ldLight) + component.LightDriveType.Get(ldLightEntry).Td = true + } + } else { //信号机所有色灯灭灯 + for _, mdLightEntry := range lights.Lights { + component.LightDriveType.Get(mdLightEntry).Td = false + } + } + return ecs.NewOkEmptyResult() + }) + return r.Err +}