rts-sim-module/sys/circuit_sys/mkx.go

58 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type MkxSys struct {
query *ecs.Query
}
func NewMkxSys() *MkxSys {
return &MkxSys{
query: ecs.NewQuery(filter.Contains(component.MkxCircuitType, component.MkxCollectionCircuitType)),
}
}
func (p *MkxSys) Update(world ecs.World) {
p.query.Each(world, func(entry *ecs.Entry) {
circuit := component.MkxCircuitType.Get(entry)
p.exciteRelay(circuit.MkxplBtn, circuit.PcbList, circuit.Pcbj)
p.exciteRelay(circuit.MkxplBtn, circuit.PobList, circuit.Pobj)
if circuit.Pabj != nil { //北岗子没有PABJ而是PDBJ
p.exciteRelay(circuit.MkxplBtn, circuit.PabList, circuit.Pabj)
}
//联锁采集
collectionCircuit := component.MkxCollectionCircuitType.Get(entry)
pcb := component.BitStateType.Get(circuit.Pcbj).Val
collectionCircuit.PcbXh = pcb
pob := component.BitStateType.Get(circuit.Pobj).Val
collectionCircuit.PobXh = pob
if circuit.Pabj != nil { //北岗子没有PABJ而是PDBJ原因未知
pab := component.BitStateType.Get(circuit.Pabj).Val
collectionCircuit.PabXh = pab
}
})
}
func (p *MkxSys) exciteRelay(mkxplBtn *ecs.Entry, entries []*ecs.Entry, relay *ecs.Entry) {
if !component.BitStateType.Get(mkxplBtn).Val {
return
}
on := false
for _, entry := range entries {
btn := component.BitStateType.Get(entry)
if btn.Val {
on = true
break
}
}
if on {
component.RelayDriveType.Get(relay).Td = true
} else {
component.RelayDriveType.Get(relay).Td = false
}
}