101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"log/slog"
|
|
)
|
|
|
|
type XcjSys struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewXcjSys() *XcjSys {
|
|
return &XcjSys{query: ecs.NewQuery(filter.Contains(entity.XcjBaseComponentTypes...))}
|
|
}
|
|
|
|
func (x *XcjSys) Update(w ecs.World) {
|
|
wd := entity.GetWorldData(w)
|
|
x.query.Each(w, func(entry *ecs.Entry) {
|
|
if entry.HasComponent(component.XcjCircuitType) {
|
|
circuit := component.XcjCircuitType.Get(entry)
|
|
//处理联锁对继电器的驱动
|
|
handleDrive(wd, circuit)
|
|
//驱动继电器
|
|
x.drive(circuit)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (x *XcjSys) drive(circuit *component.XcjCircuit) {
|
|
if component.BitStateType.Get(circuit.XCJXJ).Val { //洗车就绪
|
|
if component.BitStateType.Get(circuit.XQJ).Val { //洗车请求
|
|
component.RelayDriveType.Get(circuit.XCYXJ).Td = true
|
|
component.RelayDriveType.Get(circuit.XCJXJ).Td = false
|
|
}
|
|
} else if component.BitStateType.Get(circuit.XCYXJ).Val { //洗车允许
|
|
if component.BitStateType.Get(circuit.TWJ1).Val {
|
|
component.RelayDriveType.Get(circuit.CFJ1).Td = true
|
|
}
|
|
if component.BitStateType.Get(circuit.TWJ2).Val {
|
|
component.RelayDriveType.Get(circuit.CFJ2).Td = true
|
|
}
|
|
if component.BitStateType.Get(circuit.TWJ3).Val {
|
|
component.RelayDriveType.Get(circuit.CFJ3).Td = true
|
|
}
|
|
if component.BitStateType.Get(circuit.TGQJ).Val {
|
|
component.RelayDriveType.Get(circuit.TGYXJ).Td = true
|
|
}
|
|
} else if component.BitStateType.Get(circuit.TGYXJ).Val { //通过允许
|
|
if !component.BitStateType.Get(circuit.XQJ).Val && !component.BitStateType.Get(circuit.TGQJ).Val {
|
|
component.RelayDriveType.Get(circuit.XCJXJ).Td = true
|
|
component.RelayDriveType.Get(circuit.XCYXJ).Td = false
|
|
component.RelayDriveType.Get(circuit.CFJ1).Td = false
|
|
component.RelayDriveType.Get(circuit.CFJ2).Td = false
|
|
component.RelayDriveType.Get(circuit.CFJ3).Td = false
|
|
component.RelayDriveType.Get(circuit.TGYXJ).Td = false
|
|
}
|
|
}
|
|
}
|
|
|
|
// 处理联锁对继电器的驱动
|
|
func handleDrive(wd *component.WorldData, circuit *component.XcjCircuit) {
|
|
XQJId := component.UidType.Get(circuit.XQJ).Id
|
|
XQJBit, err := wd.QueryQdBit(XQJId)
|
|
if err != nil {
|
|
slog.Error(err.Error())
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.XQJ).Td = XQJBit
|
|
}
|
|
TWJ1Id := component.UidType.Get(circuit.TWJ1).Id
|
|
TWJ1Bit, err := wd.QueryQdBit(TWJ1Id)
|
|
if err != nil {
|
|
slog.Error(err.Error())
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.TWJ1).Td = TWJ1Bit
|
|
}
|
|
TWJ2Id := component.UidType.Get(circuit.TWJ2).Id
|
|
TWJ2Bit, err := wd.QueryQdBit(TWJ2Id)
|
|
if err != nil {
|
|
slog.Error(err.Error())
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.TWJ2).Td = TWJ2Bit
|
|
}
|
|
TWJ3Id := component.UidType.Get(circuit.TWJ3).Id
|
|
TWJ3Bit, err := wd.QueryQdBit(TWJ3Id)
|
|
if err != nil {
|
|
slog.Error(err.Error())
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.TWJ3).Td = TWJ3Bit
|
|
}
|
|
TGQJId := component.UidType.Get(circuit.TGQJ).Id
|
|
TGQJBit, err := wd.QueryQdBit(TGQJId)
|
|
if err != nil {
|
|
slog.Error(err.Error())
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.TGQJ).Td = TGQJBit
|
|
}
|
|
}
|