rts-sim-module/entity/elec.go

32 lines
1.1 KiB
Go
Raw Normal View History

package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/relation"
"joylink.club/rtsssimulation/component/singleton"
"joylink.club/rtsssimulation/modelrepo/model"
)
// 电子元件相关实体创建
// 创建断相保护器实体
func NewDbq(w ecs.World, dbq model.Dbq) *ecs.Entry {
uid := dbq.Uid().Id()
re := w.Entry(w.Create(component.DBQTag, component.UidType, component.DbqModelRelaType, component.DbqStateType, component.CounterType))
component.UidType.Set(re, &component.Uid{Id: uid})
component.DbqModelRelaType.Set(re, &relation.DbqModelRela{M: dbq})
singleton.GetEntityUidIndex(w).Add(uid, re)
return re
}
// 创建继电器实体
func NewRelay(w ecs.World, r model.Relay) *ecs.Entry {
uid := r.Uid().Id()
re := w.Entry(w.Create(component.RelayTag, component.UidType, component.RelayModelRelaType, component.RelayStateType))
component.UidType.Set(re, &component.Uid{Id: uid})
component.RelayModelRelaType.Set(re, &relation.RelayModelRela{M: r})
singleton.GetEntityUidIndex(w).Add(uid, re)
return re
}