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"
|
2024-01-10 14:17:11 +08:00
|
|
|
"joylink.club/rtsssimulation/component/component_data"
|
2023-11-23 13:17:09 +08:00
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
)
|
2023-11-23 11:17:40 +08:00
|
|
|
|
2024-02-06 09:30:57 +08:00
|
|
|
var BaliseBaseComponentTypeArr = []ecs.IComponentType{component.UidType, component.BaliseFixedTelegramType,
|
|
|
|
component.LinkPositionType, component.KmType, component.BaliseWorkStateType}
|
|
|
|
|
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)
|
2024-01-10 14:17:11 +08:00
|
|
|
balises := data.Repo.ResponderList()
|
2023-11-23 13:17:09 +08:00
|
|
|
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
|
|
|
}
|
2024-02-06 09:30:57 +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 {
|
2024-02-06 09:30:57 +08:00
|
|
|
entry = w.Entry(w.Create(BaliseBaseComponentTypeArr...))
|
2023-11-23 13:17:09 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2024-02-06 09:30:57 +08:00
|
|
|
component.BaliseWorkStateType.SetValue(entry, component.BaliseWorkState{Work: true})
|
|
|
|
component.BaliseFixedTelegramType.Set(entry, &component.BaliseTelegram{
|
2024-01-22 11:06:16 +08:00
|
|
|
Telegram: td.FixedTelegram(),
|
|
|
|
UserTelegram: td.FixedUserTelegram(),
|
|
|
|
})
|
2024-01-24 17:45:15 +08:00
|
|
|
if proto.Transponder_IB == td.BaliseType() || proto.Transponder_VB == td.BaliseType() {
|
|
|
|
entry.AddComponent(component.BaliseVariableTelegramType)
|
|
|
|
}
|
2024-07-31 17:08:53 +08:00
|
|
|
linkPosition := td.LinkPosition()
|
2024-01-10 14:17:11 +08:00
|
|
|
component.LinkPositionType.SetValue(entry, component_data.LinkPosition{
|
2024-07-31 17:08:53 +08:00
|
|
|
LinkId: linkPosition.Link().Id(),
|
|
|
|
Offset: linkPosition.Offset(),
|
2024-01-10 14:06:00 +08:00
|
|
|
})
|
|
|
|
component.KmType.Set(entry, td.Km())
|
2023-11-23 13:17:09 +08:00
|
|
|
worldData.EntityMap[uid] = entry
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|