rts-sim-module/sys/device_sys/interlock.go

43 lines
1.3 KiB
Go

package device_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type InterlockSys struct {
psdQuery *ecs.Query
mkxQuery *ecs.Query
}
func NewInterlockSys() *InterlockSys {
return &InterlockSys{
psdQuery: ecs.NewQuery(filter.Contains(component.PsdTag, component.UidType, component.PsdDriveCircuitType)),
mkxQuery: ecs.NewQuery(filter.Contains(component.MkxInfoType, component.MkxCollectionCircuitType)),
}
}
func (s *InterlockSys) Update(world ecs.World) {
psdEntryMap := make(map[string]*ecs.Entry)
s.psdQuery.Each(world, func(entry *ecs.Entry) {
psdEntryMap[component.UidType.Get(entry).Id] = entry
})
s.mkxQuery.Each(world, func(entry *ecs.Entry) {
mkxState := component.MkxCollectionCircuitType.Get(entry)
if mkxState.Pcb {
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PsdId]
psdDriveCircuit := component.PsdDriveCircuitType.Get(psdEntry)
psdDriveCircuit.GMJ = true
psdDriveCircuit.KMJ4 = false
psdDriveCircuit.KMJ8 = false
} else if mkxState.Pob {
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PsdId]
psdDriveCircuit := component.PsdDriveCircuitType.Get(psdEntry)
psdDriveCircuit.GMJ = false
psdDriveCircuit.KMJ4 = false
psdDriveCircuit.KMJ8 = true
}
})
}