package entity import ( "github.com/yohamta/donburi" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/repository" "unsafe" ) var CkmBaseComponentTypes = []ecs.IComponentType{component.UidType, component.CkmTag, component.FixedPositionTransformType} func LoadCkm(w ecs.World) error { data := GetWorldData(w) for _, ckm := range data.Repo.CkmList() { ckmEntry := buildBaseEntry(w, ckm, data) addCkmCircuit(w, ckm, ckmEntry, data) } for _, psl := range data.Repo.CkmPslList() { ckmEntry := data.EntityMap[psl.Ckm().Id()] addCkmPsl(w, psl, ckmEntry, data) } return nil } // 构建基础镜像 func buildBaseEntry(w ecs.World, ckm *repository.Ckm, data *component.WorldData) *donburi.Entry { //创建基础entry entry := w.Entry(w.Create(CkmBaseComponentTypes...)) component.UidType.SetValue(entry, component.Uid{Id: ckm.Id()}) data.EntityMap[ckm.Id()] = entry return entry } // 添加车库门电路 func addCkmCircuit(w ecs.World, ckm *repository.Ckm, ckmEntry *donburi.Entry, data *component.WorldData) { //加载电路 if len(ckm.ComponentGroups()) != 0 { circuit := &component.CkmCircuit{} ckmEntry.AddComponent(component.CkmCircuitType, unsafe.Pointer(circuit)) for _, group := range ckm.ComponentGroups() { for _, ec := range group.Components() { relay := ec.(*repository.Relay) switch ec.Code() { case "MKJ": circuit.MKJ = NewRelayEntity(w, relay, data.EntityMap) case "MGJ": circuit.MGJ = NewRelayEntity(w, relay, data.EntityMap) case "MGZJ": circuit.MGZJ = NewRelayEntity(w, relay, data.EntityMap) case "MPLJ": circuit.MPLJ = NewRelayEntity(w, relay, data.EntityMap) case "MMSJ": circuit.MMSJ = NewRelayEntity(w, relay, data.EntityMap) case "KMJ": circuit.KMJ = NewRelayEntity(w, relay, data.EntityMap) case "GMJ": circuit.GMJ = NewRelayEntity(w, relay, data.EntityMap) } } } } } // 添加车库门PSL func addCkmPsl(w ecs.World, psl *repository.CkmPsl, ckmEntry *ecs.Entry, data *component.WorldData) { ckmPsl := component.CkmPsl{ KMA: NewButtonEntity(w, psl.Kma(), data.EntityMap), GMA: NewButtonEntity(w, psl.Gma(), data.EntityMap), MPLA: NewButtonEntity(w, psl.Mpla(), data.EntityMap), MMSA: NewButtonEntity(w, psl.Mmsa(), data.EntityMap), } ckmEntry.AddComponent(component.CkmPslType, unsafe.Pointer(&ckmPsl)) }