rts-sim-module/entity/ci_qc.go

43 lines
1.3 KiB
Go
Raw Normal View History

package entity
import (
"log/slog"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
func newCiQC(w ecs.World, data *component.WorldData) *ecs.Entry {
entry := w.Entry(w.Create(component.CiQcTableType, component.CiQcStateType))
data.CiQcEntities = append(data.CiQcEntities, entry)
return entry
}
// 加载联锁驱动、采集卡
func LoadCiQC(w ecs.World) error {
data := GetWorldData(w)
for _, csr := range data.Repo.CiQcList() {
// if len(csr.CjList) == 0 {
// return fmt.Errorf("加载联锁驱采卡实体失败,车站'%s'无采集码表数据", csr.StationId)
// }
// if len(csr.QdList) == 0 {
// return fmt.Errorf("加载联锁驱采卡实体失败,车站'%s'无驱动码表数据", csr.StationId)
// }
// 加载联锁驱采卡实体
if len(csr.CjList) == 0 || len(csr.QdList) == 0 {
slog.Warn("加载联锁驱采卡实体失败,无驱动/采集码表数据", "车站", csr.StationId)
continue
}
entry := newCiQC(w, data)
qctable := component.NewCiQcTable(csr.StationId, csr.QdList, csr.CjList)
err := qctable.BuildQcIndex()
if err != nil {
return err
}
component.CiQcTableType.Set(entry, qctable)
component.CiQcStateType.Set(entry, component.NewCiQcState(len(csr.QdList), len(csr.CjList)))
}
// TODO: 不同联锁驱动码位索引唯一检查
return nil
}