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

27 lines
673 B
Go

package entity
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
// 创建继电器实体(无uid)
func NewRelayEntity(w ecs.World, comps ...*donburi.IComponentType) *ecs.Entry {
entry := w.Create(component.RelayTag, component.RelayDriveType)
for _, comp := range comps {
entry.AddComponent(*comp)
}
return entry
}
// 创建继电器实体(有uid)
func NewRelayEntityWithUid(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType)
entityMap[uid] = entry
}
return entry
}