package entity import ( "joylink.club/ecs" "joylink.club/rtsssimulation/component" ) // NewLightEntity 创建无色灯实体 func NewLightEntity(w ecs.World) *ecs.Entry { return w.Entry(w.Create(component.LightDriveType, component.BitStateType)) } // NewLightLEntity 创建绿色灯实体 func NewLightLEntity(w ecs.World) *ecs.Entry { e := NewLightEntity(w) e.AddComponent(component.LdTag) return e } // NewLightHEntity 创建红色灯实体 func NewLightHEntity(w ecs.World) *ecs.Entry { e := NewLightEntity(w) e.AddComponent(component.HdTag) return e } // NewLightUEntity 创建黄色灯实体 func NewLightUEntity(w ecs.World) *ecs.Entry { e := NewLightEntity(w) e.AddComponent(component.UdTag) return e } // NewLightBEntity 创建白色灯实体 func NewLightBEntity(w ecs.World) *ecs.Entry { e := NewLightEntity(w) e.AddComponent(component.BdTag) return e } // NewLightAEntity 创建蓝色灯实体 func NewLightAEntity(w ecs.World) *ecs.Entry { e := NewLightEntity(w) e.AddComponent(component.AdTag) return e } // NewLights 创建灯位列表(灯位顺序与lightTags一致) func NewLights(w ecs.World, lightTags ...component.DsTag) []*ecs.Entry { ls := make([]*ecs.Entry, 0, len(lightTags)) for _, lightTag := range lightTags { lightEntry := NewLightEntity(w) lightEntry.AddComponent(lightTag) ls = append(ls, lightEntry) } return ls } // NewLight 创建灯位,并打标 func NewLight(w ecs.World, lightTags ...component.DsTag) *ecs.Entry { lightEntry := NewLightEntity(w) for _, lightTag := range lightTags { lightEntry.AddComponent(lightTag) } return lightEntry } // IsLightFd 灯是否被封(如Signal 3xh3 红绿黄三显示封绿灯) func IsLightFd(lightEntry *ecs.Entry) bool { if lightEntry.HasComponent(component.LightDriveType) && lightEntry.HasComponent(component.BitStateType) { return lightEntry.HasComponent(component.FdTag) } else { panic("IsLightFd 参数lightEntry的值非灯实体") } }