rts-sim-module/entity/light.go

67 lines
1.7 KiB
Go
Raw Normal View History

2023-10-11 13:22:14 +08:00
package entity
2023-10-11 13:38:33 +08:00
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
2023-10-11 13:22:14 +08:00
2023-10-11 13:38:33 +08:00
// NewLightEntity 创建无色灯实体
func NewLightEntity(w ecs.World) *ecs.Entry {
return w.Entry(w.Create(component.LightDriveType, component.BitStateType))
2023-10-11 13:22:14 +08:00
}
2023-10-11 13:46:34 +08:00
// 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
}
2023-10-12 11:00:56 +08:00
// NewLights 创建灯位列表(灯位顺序与lightTags一致)
2023-10-12 11:06:20 +08:00
func NewLights(w ecs.World, lightTags ...component.DsTag) []*ecs.Entry {
2023-10-12 11:00:56 +08:00
ls := make([]*ecs.Entry, 0, len(lightTags))
for _, lightTag := range lightTags {
lightEntry := NewLightEntity(w)
lightEntry.AddComponent(lightTag)
ls = append(ls, lightEntry)
}
return ls
}
2023-10-12 15:13:13 +08:00
// 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的值非灯实体")
}
}