package fi import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component/component_proto" "joylink.club/rtsssimulation/entity" ) // UpdateSignalLightFault 设置信号机灯故障 // // light : 灯泡 // faultType :故障类型 // set : true-设置故障,false-取消故障 func UpdateSignalLightFault(w ecs.World, signalId string, light component_proto.Light_Color, faultType component_proto.Signal_Fault, set bool) error { r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(w) signalEntry, ok := wd.EntityMap[signalId] if ok { switch faultType { case component_proto.Signal_DS: //断丝故障 { lightEntry := component.SignalLightsType.Get(signalEntry).GetLightByColor(light) if lightEntry == nil { return ecs.NewErrResult(fmt.Errorf("信号机[%s]没有色灯[%d]", signalId, light)) } if set { if !lightEntry.HasComponent(component.LightFaultDsType) { lightEntry.AddComponent(component.LightFaultDsType) } } else { if lightEntry.HasComponent(component.LightFaultDsType) { lightEntry.RemoveComponent(component.LightFaultDsType) } } } default: return ecs.NewErrResult(fmt.Errorf("信号机[%s]不支持该故障类型[%s]", signalId, faultType)) } } return ecs.NewOkEmptyResult() }) return r.Err }