44 lines
1.3 KiB
Go
44 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.PsdInfoType, 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.PsdInfoType.Get(entry).PlatformId] = entry
|
|
})
|
|
s.mkxQuery.Each(world, func(entry *ecs.Entry) {
|
|
mkxState := component.MkxCollectionCircuitType.Get(entry)
|
|
if mkxState.Pcb {
|
|
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PlatformId]
|
|
psdDriveCircuit := component.PsdDriveCircuitType.Get(psdEntry)
|
|
psdDriveCircuit.GMJ = true
|
|
psdDriveCircuit.KMJ4 = false
|
|
psdDriveCircuit.KMJ8 = false
|
|
}
|
|
if mkxState.Pob {
|
|
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PlatformId]
|
|
psdDriveCircuit := component.PsdDriveCircuitType.Get(psdEntry)
|
|
psdDriveCircuit.GMJ = false
|
|
psdDriveCircuit.KMJ4 = false
|
|
psdDriveCircuit.KMJ8 = true
|
|
}
|
|
})
|
|
}
|