45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"github.com/yohamta/donburi"
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"joylink.club/rtsssimulation/sys/device_sys"
|
|
)
|
|
|
|
type TrackCircuitSys struct {
|
|
trainQuery *ecs.Query
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewTrackCircuitSys() *TrackCircuitSys {
|
|
return &TrackCircuitSys{
|
|
trainQuery: ecs.NewQuery(filter.Contains(component.UidType, component.TrainPositionInfoType)),
|
|
query: ecs.NewQuery(filter.Contains(entity.TrackCircuitBaseComponentTypeArr...)),
|
|
}
|
|
}
|
|
|
|
func (t *TrackCircuitSys) Update(world ecs.World) {
|
|
var withTrainSectionMap = make(map[string]bool)
|
|
t.trainQuery.Each(world, func(entry *donburi.Entry) {
|
|
trainPos := component.TrainPositionInfoType.Get(entry)
|
|
sections := device_sys.DoSearchTrainOccupiedSections(world, trainPos)
|
|
for _, sectionId := range sections {
|
|
withTrainSectionMap[sectionId] = true
|
|
}
|
|
})
|
|
t.query.Each(world, func(entry *ecs.Entry) {
|
|
if !entry.HasComponent(component.TrackCircuitType) {
|
|
return
|
|
}
|
|
gj := component.TrackCircuitType.Get(entry).GJ
|
|
if withTrainSectionMap[component.UidType.Get(entry).Id] {
|
|
component.RelayDriveType.Get(gj).Td = false
|
|
} else {
|
|
component.RelayDriveType.Get(gj).Td = true
|
|
}
|
|
})
|
|
}
|