2023-09-27 18:39:18 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2023-09-28 14:34:00 +08:00
|
|
|
"strings"
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
2023-09-28 14:34:00 +08:00
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-09-27 18:39:18 +08:00
|
|
|
)
|
|
|
|
|
2023-10-08 09:59:59 +08:00
|
|
|
// 创建继电器实体
|
2023-09-28 14:34:00 +08:00
|
|
|
func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
|
|
|
uid := relay.Id()
|
|
|
|
model := proto.Relay_Model_name[int32(relay.Model())]
|
2023-09-27 18:39:18 +08:00
|
|
|
entry, ok := entityMap[uid]
|
|
|
|
if !ok {
|
2023-10-09 14:24:53 +08:00
|
|
|
entry = w.Entry(w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType))
|
2023-10-07 15:19:03 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2023-10-08 09:59:59 +08:00
|
|
|
if strings.Contains(model, "Y") { // 有极继电器
|
2023-09-28 14:34:00 +08:00
|
|
|
entry.AddComponent(component.YjRelayTag)
|
2023-10-10 18:28:28 +08:00
|
|
|
} else if strings.Contains(model, "W") || strings.Contains(model, "Z") || strings.Contains(model, "P") { // 无极继电器
|
2023-09-28 14:34:00 +08:00
|
|
|
entry.AddComponent(component.WjRelayTag)
|
|
|
|
}
|
2023-10-08 09:59:59 +08:00
|
|
|
if strings.Contains(model, "H") { // 缓放继电器
|
2023-09-28 14:34:00 +08:00
|
|
|
entry.AddComponent(component.HfRelayTag)
|
|
|
|
}
|
2023-09-27 18:39:18 +08:00
|
|
|
entityMap[uid] = entry
|
2024-06-28 11:10:09 +08:00
|
|
|
//设置继电器初始状态
|
|
|
|
switch relay.DefaultPos() {
|
|
|
|
case proto.Relay_Pos_Q:
|
|
|
|
component.RelayDriveType.Get(entry).Td = true
|
|
|
|
case proto.Relay_Pos_H:
|
|
|
|
component.RelayDriveType.Get(entry).Td = false
|
|
|
|
}
|
2023-09-27 18:39:18 +08:00
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|