rts-sim-module/system/balise_system.go
2023-08-17 17:39:57 +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.ComDeviceIdentity, components.ComBaliseState))
// 列车查询
var trainQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComTrainState))
// 应答器模拟系统
// 检测当有列车经过时,把报文发送给该列车
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.ComDeviceIdentity.Get(e).Id {
transponderEntry = e
}
})
//
if transponderEntry == nil {
return false
}
//
components.ComBaliseState.Get(transponderEntry).Content = message
//
return true
}