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-08 09:59:59 +08:00
|
|
|
} else if strings.Contains(model, "W") { // 无极继电器
|
2023-09-28 14:34:00 +08:00
|
|
|
entry.AddComponent(component.WjRelayTag)
|
2023-10-08 09:59:59 +08:00
|
|
|
} else if strings.Contains(model, "P") { // 偏极继电器
|
2023-10-07 14:47:14 +08:00
|
|
|
entry.AddComponent(component.WjRelayTag)
|
|
|
|
entry.AddComponent(component.PjRelayTag)
|
2023-09-28 14:34:00 +08:00
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|