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

83 lines
2.7 KiB
Go

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/entity"
"log/slog"
)
type CkmSys struct {
query *ecs.Query
}
func NewCkmSys() *CkmSys {
return &CkmSys{
query: ecs.NewQuery(filter.Contains(entity.CkmBaseComponentTypes...)),
}
}
func (p *CkmSys) Update(world ecs.World) {
worldData := entity.GetWorldData(world)
p.query.Each(world, func(entry *ecs.Entry) {
if !entry.HasComponent(component.CkmCircuitType) {
return
}
posCom := component.FixedPositionTransformType.Get(entry)
circuit := component.CkmCircuitType.Get(entry) //目前不考虑没有车库门电路的情况
//车库门PSL
if entry.HasComponent(component.CkmPslType) {
ckmPsl := component.CkmPslType.Get(entry)
component.RelayDriveType.Get(circuit.MPLJ).Td = component.BitStateType.Get(ckmPsl.MPLA).Val //门旁路
component.RelayDriveType.Get(circuit.MMSJ).Td = component.BitStateType.Get(ckmPsl.MMSA).Val //门模式
}
//门开/关继电器及状态
if posCom.Pos == consts.TwoPosMin {
component.RelayDriveType.Get(circuit.MGJ).Td = true
component.RelayDriveType.Get(circuit.MKJ).Td = false
} else {
component.RelayDriveType.Get(circuit.MGJ).Td = false
component.RelayDriveType.Get(circuit.MKJ).Td = true
}
////门故障继电器及状态
//component.RelayDriveType.Get(circuit.MGZJ).Td =
//开/关门继电器驱动状态
if component.BitStateType.Get(circuit.MMSJ).Val {
ckmPsl := component.CkmPslType.Get(entry)
component.RelayDriveType.Get(circuit.KMJ).Td = component.BitStateType.Get(ckmPsl.KMA).Val
component.RelayDriveType.Get(circuit.GMJ).Td = component.BitStateType.Get(ckmPsl.GMA).Val
} else {
kmBit, err := worldData.QueryQdBit(component.UidType.Get(circuit.KMJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.KMJ).Td = kmBit
} else {
slog.Error(err.Error())
}
gmBit, err := worldData.QueryQdBit(component.UidType.Get(circuit.GMJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.GMJ).Td = gmBit
} else {
slog.Error(err.Error())
}
}
//强制开门
if entry.HasComponent(component.CkmForceOpenTag) {
posCom.Pos = consts.TwoPosMax
posCom.Speed = 0
return
} else if entry.HasComponent(component.CkmForceCloseTag) {
posCom.Pos = consts.TwoPosMin
posCom.Speed = 0
return
}
//驱动
if component.BitStateType.Get(circuit.GMJ).Val {
posCom.Speed = -component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())
} else if component.BitStateType.Get(circuit.KMJ).Val {
posCom.Speed = component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())
}
})
}