不带电路的信号机
This commit is contained in:
parent
41a7f7a585
commit
549eaeba35
@ -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 (
|
||||
|
33
fi/signal.go
33
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user