49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package system
|
|
|
|
import (
|
|
"github.com/yohamta/donburi/filter"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/components"
|
|
)
|
|
|
|
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
|
|
|
|
const (
|
|
//道岔定位
|
|
SwitchNormalRate int32 = 0
|
|
//道岔反位
|
|
SwitchReverseRate int32 = 100
|
|
)
|
|
|
|
// 道岔系统操作
|
|
type SwitchSystem struct {
|
|
}
|
|
|
|
func NewSwitchSystem() *SwitchSystem {
|
|
return &SwitchSystem{}
|
|
}
|
|
|
|
// world 执行
|
|
func (me *SwitchSystem) Update(w ecs.World) {
|
|
SwitchQuery.Each(w, func(e *ecs.Entry) {
|
|
switchRate := components.PercentageDeviceComponent.Get(e)
|
|
switchRelay := components.SwitchRelayStateComponent.Get(e)
|
|
if switchRate.Rate <= 0 {
|
|
switchRelay.DcJ = false
|
|
switchRelay.DbJ = true
|
|
}
|
|
if switchRate.Rate >= 100 {
|
|
switchRelay.FcJ = false
|
|
switchRelay.FbJ = true
|
|
}
|
|
//过了操作时限,定操反操继电器自动复位
|
|
if !e.HasComponent(components.PercentageDeviceOperatingComponent) {
|
|
switchRelay.DcJ = false
|
|
switchRelay.FcJ = false
|
|
} else {
|
|
switchRelay.DbJ = false
|
|
switchRelay.FbJ = false
|
|
}
|
|
})
|
|
}
|