rts-sim-module/entity/points.go
walker 7751d9d926 组件定义调整
道岔命名调整,道岔实体构建重构
2024-01-02 18:22:28 +08:00

37 lines
1.1 KiB
Go

package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/relation"
"joylink.club/rtsssimulation/modelrepo/model"
)
func NewPoints(w ecs.World, p model.Points) *ecs.Entry {
id := p.Uid().Id()
// 创建道岔实体
e := w.Entry(w.Create(component.UidType, component.TurnoutTag, component.PointsModelRelaType, component.PointsZzjRelaType,
component.PointsPositionType))
c := p.GetZzjCount()
if c <= 0 {
panic(fmt.Errorf("道岔转辙机数量必须大于0。id=%s, zzjCount=%d", id, c))
}
// 创建转辙机实体
entities := w.CreateMany(c, component.PointsZzjRelaType, component.PointsZzjKbqStateType, component.FixedPositionTransformType)
pzr := &relation.PointsZzjRela{
Points: e,
}
// 关系状态初始化
component.UidType.Set(e, &component.Uid{Id: id})
component.PointsModelRelaType.Set(e, &relation.PointsModelRela{M: p})
component.PointsZzjRelaType.Set(e, pzr)
for _, ez := range entities {
zzj := w.Entry(ez)
pzr.Zzjs = append(pzr.Zzjs, zzj)
component.PointsZzjRelaType.Set(zzj, pzr)
}
return e
}