27 lines
673 B
Go
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
|
||
|
}
|