2024-03-07 17:40:51 +08:00
|
|
|
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{
|
2024-03-18 11:09:28 +08:00
|
|
|
query: ecs.NewQuery(filter.Contains(entity.CkmBaseComponentTypes...)),
|
2024-03-07 17:40:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *CkmSys) Update(world ecs.World) {
|
|
|
|
worldData := entity.GetWorldData(world)
|
|
|
|
p.query.Each(world, func(entry *ecs.Entry) {
|
2024-04-01 13:31:37 +08:00
|
|
|
if !entry.HasComponent(component.CkmCircuitType) {
|
|
|
|
return
|
|
|
|
}
|
2024-03-07 17:40:51 +08:00
|
|
|
posCom := component.FixedPositionTransformType.Get(entry)
|
2024-03-26 13:12:16 +08:00
|
|
|
circuit := component.CkmCircuitType.Get(entry) //目前不考虑没有车库门电路的情况
|
|
|
|
//车库门PSL
|
|
|
|
if entry.HasComponent(component.CkmPslType) {
|
|
|
|
ckmPsl := component.CkmPslType.Get(entry)
|
2024-03-27 17:11:04 +08:00
|
|
|
component.RelayDriveType.Get(circuit.MPLJ).Td = component.BitStateType.Get(ckmPsl.MPLA).Val //门旁路
|
|
|
|
component.RelayDriveType.Get(circuit.MMSJ).Td = component.BitStateType.Get(ckmPsl.MMSA).Val //门模式
|
2024-03-26 13:12:16 +08:00
|
|
|
}
|
|
|
|
//门开/关继电器及状态
|
|
|
|
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
|
|
|
|
}
|
2024-03-29 16:46:30 +08:00
|
|
|
////门故障继电器及状态
|
|
|
|
//component.RelayDriveType.Get(circuit.MGZJ).Td =
|
2024-03-26 13:12:16 +08:00
|
|
|
//开/关门继电器驱动状态
|
2024-03-27 17:11:04 +08:00
|
|
|
if component.BitStateType.Get(circuit.MMSJ).Val {
|
2024-03-27 14:15:34 +08:00
|
|
|
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 {
|
2024-03-07 17:40:51 +08:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
2024-04-07 13:38:30 +08:00
|
|
|
//强制开门
|
|
|
|
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
|
|
|
|
}
|
2024-03-07 17:40:51 +08:00
|
|
|
//驱动
|
2024-03-26 16:48:36 +08:00
|
|
|
if component.BitStateType.Get(circuit.GMJ).Val {
|
2024-03-07 17:40:51 +08:00
|
|
|
posCom.Speed = -component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())
|
2024-03-26 16:48:36 +08:00
|
|
|
} else if component.BitStateType.Get(circuit.KMJ).Val {
|
2024-03-07 17:40:51 +08:00
|
|
|
posCom.Speed = component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|