rts-sim-module/system/switch_system.go

49 lines
1.1 KiB
Go
Raw Normal View History

2023-08-14 18:06:26 +08:00
package system
import (
2023-08-18 14:40:13 +08:00
"github.com/yohamta/donburi/filter"
2023-08-14 18:06:26 +08:00
"joylink.club/ecs"
2023-08-18 14:40:13 +08:00
"joylink.club/rtsssimulation/components"
)
2023-08-23 16:01:01 +08:00
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
2023-08-18 14:40:13 +08:00
const (
//道岔定位
SwitchNormalRate int32 = 0
//道岔反位
SwitchReverseRate int32 = 100
2023-08-14 18:06:26 +08:00
)
// 道岔系统操作
type SwitchSystem struct {
}
func NewSwitchSystem() *SwitchSystem {
2023-08-16 15:00:24 +08:00
return &SwitchSystem{}
2023-08-14 18:06:26 +08:00
}
// world 执行
func (me *SwitchSystem) Update(w ecs.World) {
2023-08-23 16:01:01 +08:00
SwitchQuery.Each(w, func(e *ecs.Entry) {
2023-08-18 14:40:13 +08:00
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
}
})
2023-08-14 18:06:26 +08:00
}