rts-sim-module/entity/balise.go

42 lines
1.2 KiB
Go
Raw Normal View History

2023-11-23 11:17:40 +08:00
package entity
2023-11-23 13:17:09 +08:00
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
)
2023-11-23 11:17:40 +08:00
// LoadBalises 加载应答器实体
func LoadBalises(w ecs.World) error {
2023-11-23 13:17:09 +08:00
data := GetWorldData(w)
balises := data.Repo.ResponderList()
for _, b := range balises {
be := newBaliseEntity(w, b, data)
switch b.TransponderType() {
case proto.Transponder_FB:
be.AddComponent(component.BaliseFB)
case proto.Transponder_WB:
be.AddComponent(component.BaliseWB)
case proto.Transponder_DB:
be.AddComponent(component.BaliseDB)
case proto.Transponder_VB:
be.AddComponent(component.BaliseVB)
case proto.Transponder_IB:
be.AddComponent(component.BaliseIB)
}
}
2023-11-23 11:19:39 +08:00
return nil
2023-11-23 11:17:40 +08:00
}
2023-11-23 13:17:09 +08:00
func newBaliseEntity(w ecs.World, td *repository.Transponder, worldData *component.WorldData) *ecs.Entry {
uid := td.Id()
entry, ok := worldData.EntityMap[uid]
if !ok {
entry = w.Entry(w.Create(component.UidType, component.BaliseStateType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
component.BaliseStateType.Set(entry, &component.BaliseState{})
worldData.EntityMap[uid] = entry
}
return entry
}