This commit is contained in:
xzb 2023-11-23 15:12:16 +08:00
parent 8fdc707a97
commit 1d016f6fab
2 changed files with 10 additions and 1 deletions

View File

@ -13,3 +13,12 @@ func NewTrainEntity(w ecs.World, trainId string) *ecs.Entry {
data.EntityMap[trainId] = te
return te
}
func NewTrainWithBtmEntity(w ecs.World, trainId string) *ecs.Entry {
data := GetWorldData(w)
te := w.Entry(w.Create(component.UidType, component.TrainPositionInfoType, component.TrainBtmType))
component.UidType.SetValue(te, component.Uid{Id: trainId})
component.TrainPositionInfoType.Set(te, &component.TrainPositionInfo{})
component.TrainBtmType.Set(te, &component.TrainBtm{})
data.EntityMap[trainId] = te
return te
}

View File

@ -13,7 +13,7 @@ func AddTrainToWorld(w ecs.World, trainId string) error {
wd := entity.GetWorldData(w)
_, find := wd.EntityMap[trainId]
if !find {
entity.NewTrainEntity(w, trainId)
entity.NewTrainWithBtmEntity(w, trainId)
}
return ecs.NewOkEmptyResult()
})