46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package device_sys
|
|
|
|
import (
|
|
"github.com/yohamta/donburi/filter"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/consts"
|
|
)
|
|
|
|
// 断相保护器
|
|
type DBQSys struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewDBQSys() *DBQSys {
|
|
return &DBQSys{
|
|
query: ecs.NewQuery(filter.Contains(component.DBQTag, component.DBQType)),
|
|
}
|
|
}
|
|
|
|
func (q *DBQSys) Update(w ecs.World) {
|
|
q.query.Each(w, func(entry *ecs.Entry) {
|
|
// 电路是否通电
|
|
dbq := component.DBQType.Get(entry)
|
|
if dbq.Td && !dbq.Dzkg { // 通电但开关未开,启动
|
|
dbq.Dzkg = true
|
|
if entry.HasComponent(component.CounterType) {
|
|
// 定时器启动
|
|
counter := component.CounterType.Get(entry)
|
|
counter.Val = 0
|
|
counter.Step = w.Tick()
|
|
}
|
|
} else if dbq.Td && dbq.Dzkg { // 已经启动,判定延时切断
|
|
if entry.HasComponent(component.CounterType) {
|
|
// 判断定时器是否超时,如果超时,断开电子开关
|
|
counter := component.CounterType.Get(entry)
|
|
if counter.Val >= consts.DBQTimeout {
|
|
dbq.Dzkg = false
|
|
}
|
|
}
|
|
} else if !dbq.Td && dbq.Dzkg { // 无电,断开电子开关
|
|
dbq.Dzkg = false
|
|
}
|
|
})
|
|
}
|