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

46 lines
1.1 KiB
Go

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.PsdCircuitType, component.PsdDriveCircuitType)),
}
}
func (p *MkxSys) Update(world ecs.World) {
p.query.Each(world, func(entry *ecs.Entry) {
circuit := component.MkxCircuitType.Get(entry)
p.exciteRelay(circuit.PcbList, circuit.Pcbj)
p.exciteRelay(circuit.PobList, circuit.Pobj)
p.exciteRelay(circuit.PabList, circuit.Pabj)
})
}
func (p *MkxSys) exciteRelay(entries []*ecs.Entry, relay *ecs.Entry) {
on := false
for _, pcbEntry := range entries {
pcb := component.MkxBoxType.Get(pcbEntry)
btn := component.BitStateType.Get(pcb.Btn)
mkxplBtn := component.BitStateType.Get(pcb.MkxplBtn)
if btn.Val && mkxplBtn.Val {
on = true
}
}
if on {
component.RelayDriveType.Get(relay).Td = true
component.BitStateType.Get(relay).Val = true
} else {
component.RelayDriveType.Get(relay).Td = false
component.BitStateType.Get(relay).Val = false
}
}