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

31 lines
854 B
Go

package entity
import (
"strings"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
)
// 创建继电器实体(有uid)
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())]
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType)
if strings.Contains(model, "Y") {
entry.AddComponent(component.YjRelayTag)
} else if strings.Contains(model, "W") {
entry.AddComponent(component.WjRelayTag)
}
if strings.Contains(model, "H") {
entry.AddComponent(component.HfRelayTag)
}
entityMap[uid] = entry
}
return entry
}