rts-sim-module/system/balise_system.go
2023-08-18 10:06:17 +08:00

49 lines
1.2 KiB
Go

package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/state"
)
// 应答器查询
var baliseQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.BaliseStateComponent))
// 列车查询
var trainQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TrainStateComponent))
// 应答器模拟系统
// 检测当有列车经过时,把报文发送给该列车
type BaliseSystem struct {
}
func NewTransponderSystem() *BaliseSystem {
return &BaliseSystem{}
}
// world 执行
func (me *BaliseSystem) Update(w ecs.World) {
}
//
// 发送消息到应答器
// 当要清空应答器中报文时,则message=nil
func SendMessageToTransponder(world ecs.World, transponderId string, message *state.BaliseContent) bool {
var transponderEntry *ecs.Entry = nil
baliseQuery.Each(world, func(e *ecs.Entry) {
if transponderId == components.DeviceIdentityComponent.Get(e).Id {
transponderEntry = e
}
})
//
if transponderEntry == nil {
return false
}
//
components.BaliseStateComponent.Get(transponderEntry).Content = message
//
return true
}