33 lines
829 B
Go
33 lines
829 B
Go
package device_sys
|
||
|
||
import (
|
||
"joylink.club/ecs"
|
||
"joylink.club/ecs/filter"
|
||
"joylink.club/rtsssimulation/component"
|
||
)
|
||
|
||
// LightSys 灯控制系统
|
||
type LightSys struct {
|
||
query *ecs.Query
|
||
}
|
||
|
||
func NewLightSys() *LightSys {
|
||
return &LightSys{query: ecs.NewQuery(filter.Contains(component.LightDriveType, component.BitStateType))}
|
||
}
|
||
|
||
func (ls *LightSys) Update(w ecs.World) {
|
||
ls.query.Each(w, func(entry *ecs.Entry) {
|
||
//灯驱动
|
||
drive := component.LightDriveType.Get(entry)
|
||
//灯当前状态,true-灯丝有电流,false-灯丝没有电流
|
||
state := component.BitStateType.Get(entry)
|
||
//驱动灯亮或灭
|
||
state.Val = drive.Td && !ls.calculateFault(entry)
|
||
})
|
||
}
|
||
func (ls *LightSys) calculateFault(entry *ecs.Entry) bool {
|
||
//断丝故障
|
||
haveFault := entry.HasComponent(component.LightFaultDsType)
|
||
return haveFault
|
||
}
|