rts-sim-module/fi/turnout.go
walker c56feb3bdf 道岔电路驱动系统实现
仿真单例组件定义(暂定)
仿真道岔相关实体构建(未完)
2023-09-27 18:39:18 +08:00

50 lines
1.2 KiB
Go

package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// 道岔功能接口
// 驱动道岔定操相关继电器
func DriveTurnoutDCRelay(w ecs.World, id string, 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)
ycj.Td = on
dcj.Td = on
}
} else {
fmt.Println("未找到id=", id, "的道岔")
}
})
}
// 驱动道岔反操相关继电器
func DriveTurnoutFCRelay(w ecs.World, id string, 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)
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
ycj.Td = on
fcj.Td = on
}
} else {
fmt.Println("未找到id=", id, "的道岔")
}
})
}