67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
|
package fi
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/component"
|
||
|
"joylink.club/rtsssimulation/entity"
|
||
|
)
|
||
|
|
||
|
// 继电器功能接口
|
||
|
|
||
|
// 控制有极继电器励磁
|
||
|
// id - 继电器uid
|
||
|
// td - 是否通电励磁
|
||
|
// xq - 是否到吸起位置(有极继电器)
|
||
|
func driveYjRelay(w ecs.World, entry *ecs.Entry, td bool, xq bool) {
|
||
|
rd := component.RelayDriveType.Get(entry)
|
||
|
rd.Td = td
|
||
|
rd.Xq = xq
|
||
|
}
|
||
|
|
||
|
// 控制无极继电器励磁
|
||
|
// id - 继电器uid
|
||
|
// td - 是否通电励磁
|
||
|
// xq - 是否到吸起位置(有极继电器)
|
||
|
func driveWjRelay(w ecs.World, entry *ecs.Entry, td bool) {
|
||
|
rd := component.RelayDriveType.Get(entry)
|
||
|
rd.Td = true
|
||
|
}
|
||
|
|
||
|
// 驱动继电器到吸起位置
|
||
|
func DriveRelayUp(w ecs.World, id string) {
|
||
|
w.Execute(func() {
|
||
|
wd := entity.GetWorldData(w)
|
||
|
entry, ok := wd.EntityMap[id]
|
||
|
if ok {
|
||
|
if entry.HasComponent(component.YjRelayTag) {
|
||
|
driveYjRelay(w, entry, true, true)
|
||
|
} else {
|
||
|
driveWjRelay(w, entry, true)
|
||
|
}
|
||
|
} else {
|
||
|
fmt.Printf("未找到id=%s的继电器\n", id)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
// 驱动继电器到落下位置
|
||
|
func DriveRelayDown(w ecs.World, id string) {
|
||
|
w.Execute(func() {
|
||
|
w.Execute(func() {
|
||
|
wd := entity.GetWorldData(w)
|
||
|
entry, ok := wd.EntityMap[id]
|
||
|
if ok {
|
||
|
if entry.HasComponent(component.YjRelayTag) {
|
||
|
driveYjRelay(w, entry, true, false)
|
||
|
} else {
|
||
|
driveWjRelay(w, entry, false)
|
||
|
}
|
||
|
} else {
|
||
|
fmt.Printf("未找到id=%s的继电器\n", id)
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
}
|