rts-sim-module/system/balise_system.go

49 lines
1.2 KiB
Go
Raw Normal View History

2023-08-17 17:39:57 +08:00
package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/state"
)
// 应答器查询
2023-08-18 10:06:17 +08:00
var baliseQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.BaliseStateComponent))
2023-08-17 17:39:57 +08:00
// 列车查询
2023-08-18 10:06:17 +08:00
var trainQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TrainStateComponent))
2023-08-17 17:39:57 +08:00
// 应答器模拟系统
// 检测当有列车经过时,把报文发送给该列车
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) {
2023-08-18 10:06:17 +08:00
if transponderId == components.DeviceIdentityComponent.Get(e).Id {
2023-08-17 17:39:57 +08:00
transponderEntry = e
}
})
//
if transponderEntry == nil {
return false
}
//
2023-08-18 10:06:17 +08:00
components.BaliseStateComponent.Get(transponderEntry).Content = message
2023-08-17 17:39:57 +08:00
//
return true
}