rts-sim-module/fi/turnout.go
walker d3a187e00f 添加创建仿真
完善仿真实体加载
2023-09-28 14:34:00 +08:00

66 lines
1.5 KiB
Go

package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// 道岔功能接口
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.Zdj9TwoElectronicType) { // 有电路,驱动继电器
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
dcj := component.RelayDriveType.Get(zdj9.TDC_DCJ)
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
ycj.Td = on
if dc {
dcj.Td = on
} else {
fcj.Td = on
}
} else { // 无电路,直接驱动转辙机
tz := component.TurnoutZzjType.Get(entry)
for _, zzj := range tz.ZzjList {
state := component.ZzjStateType.Get(zzj)
state.Td = on
if dc {
state.Dw = true
} else {
state.Dw = false
}
}
}
} else {
fmt.Println("未找到id=", id, "的道岔")
}
})
}
// 驱动道岔转辙机定操启动
func DriveTurnoutDCOn(w ecs.World, id string) {
driveTurnoutZzj(w, id, true, true)
}
// 驱动道岔转辙机定操停止
func DriveTurnoutDCOff(w ecs.World, id string) {
driveTurnoutZzj(w, id, true, false)
}
// 驱动道岔转辙机反操启动
func DriveTurnoutFCOn(w ecs.World, id string) {
driveTurnoutZzj(w, id, false, true)
}
// 驱动道岔转辙机反操停止
func DriveTurnoutFCOff(w ecs.World, id string) {
driveTurnoutZzj(w, id, false, false)
}