2023-10-12 17:55:40 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2023-12-29 17:48:57 +08:00
|
|
|
"strconv"
|
|
|
|
|
2023-10-12 17:55:40 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
)
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
var PsdBaseComponentTypeArr = []ecs.IComponentType{component.PsdTag, component.UidType,
|
|
|
|
component.PsdStateType, component.AsdListType, component.PscType}
|
2023-11-03 10:41:47 +08:00
|
|
|
var AsdBaseComponentTypeArr = []ecs.IComponentType{component.AsdTag, component.UidType,
|
2023-12-29 17:48:57 +08:00
|
|
|
component.AsdMotorStateType, component.FixedPositionTransformType, component.AsdStateType}
|
2023-11-01 16:52:03 +08:00
|
|
|
|
2023-10-12 17:55:40 +08:00
|
|
|
func LoadPsd(w ecs.World) error {
|
|
|
|
data := GetWorldData(w)
|
|
|
|
psds := data.Repo.PsdList()
|
|
|
|
for _, psd := range psds {
|
2023-10-19 17:09:47 +08:00
|
|
|
entry := NewPsdEntry(w, psd, data)
|
2023-10-12 17:55:40 +08:00
|
|
|
loadPsdCircuit(w, entry, psd, data.EntityMap)
|
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
pmcMap := make(map[string]*ecs.Entry)
|
|
|
|
for _, mkx := range data.Repo.MkxList() {
|
|
|
|
entry := NewMkxEntry(w, data, mkx)
|
|
|
|
loadPlatformMkxCircuit(w, data.EntityMap, pmcMap, mkx, entry, data.EntityMap[mkx.Psd().Id()])
|
|
|
|
}
|
2023-10-12 17:55:40 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
func loadPlatformMkxCircuit(world ecs.World, entryMap map[string]*ecs.Entry, pmcMap map[string]*ecs.Entry,
|
|
|
|
mkx *repository.Mkx, mkxEntry *ecs.Entry, psdEntry *ecs.Entry) {
|
|
|
|
platformMkx, ok := pmcMap[mkx.Psd().Id()]
|
|
|
|
if !ok {
|
|
|
|
platformMkx = NewPlatformMkxEntry(world, entryMap, mkx)
|
|
|
|
pmcMap[mkx.Psd().Id()] = platformMkx
|
|
|
|
}
|
|
|
|
platformMkxCircuit := component.PlatformMkxCircuitType.Get(platformMkx)
|
|
|
|
platformMkxCircuit.MkxList = append(platformMkxCircuit.MkxList, mkxEntry)
|
|
|
|
psdEntry.AddComponent(component.PlatformMkxCircuitType)
|
|
|
|
component.PlatformMkxCircuitType.Set(psdEntry, platformMkxCircuit)
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:55:40 +08:00
|
|
|
func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entryMap map[string]*ecs.Entry) {
|
2023-10-20 16:12:42 +08:00
|
|
|
if len(psd.ComponentGroups()) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2023-12-08 16:46:49 +08:00
|
|
|
circuit := &component.PsdCircuit{KMJMap: make(map[int32]*ecs.Entry)}
|
2023-10-12 17:55:40 +08:00
|
|
|
for _, group := range psd.ComponentGroups() {
|
|
|
|
for _, ec := range group.Components() {
|
|
|
|
relay := ec.(*repository.Relay)
|
|
|
|
switch ec.Code() {
|
|
|
|
case "XGMJ", "SGMJ":
|
|
|
|
circuit.GMJ = NewRelayEntity(world, relay, entryMap)
|
2023-12-08 17:43:20 +08:00
|
|
|
case "XKMJ", "SKMJ":
|
|
|
|
circuit.KMJMap[0] = NewRelayEntity(world, relay, entryMap)
|
2023-10-12 17:55:40 +08:00
|
|
|
case "4XKMJ", "4SKMJ":
|
2023-12-08 16:46:49 +08:00
|
|
|
circuit.KMJMap[4] = NewRelayEntity(world, relay, entryMap)
|
2023-10-12 17:55:40 +08:00
|
|
|
case "8XKMJ", "8SKMJ":
|
2023-12-08 16:46:49 +08:00
|
|
|
circuit.KMJMap[8] = NewRelayEntity(world, relay, entryMap)
|
2023-10-12 17:55:40 +08:00
|
|
|
case "XMGJ", "SMGJ":
|
|
|
|
circuit.MGJ = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "XMPLJ", "SMPLJ":
|
|
|
|
circuit.MPLJ = NewRelayEntity(world, relay, entryMap)
|
2023-11-09 10:53:18 +08:00
|
|
|
case "SQDTCJ", "XQDTCJ":
|
|
|
|
circuit.QDTCJ = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "STZTCJ", "XTZTCJ":
|
|
|
|
circuit.TZTCJ = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "SZAWJ", "XZAWJ":
|
|
|
|
circuit.ZAWJ = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "SJXTCPLJ", "XJXTCPLJ":
|
|
|
|
circuit.JXTCPLJ = NewRelayEntity(world, relay, entryMap)
|
2023-11-07 14:30:07 +08:00
|
|
|
default:
|
|
|
|
circuit.UnusedJ = append(circuit.UnusedJ, NewRelayEntity(world, relay, entryMap))
|
2023-10-12 17:55:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
entry.AddComponent(component.PsdCircuitType)
|
2023-10-12 17:55:40 +08:00
|
|
|
component.PsdCircuitType.Set(entry, circuit)
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:09:47 +08:00
|
|
|
func NewPsdEntry(world ecs.World, psd *repository.Psd, worldData *component.WorldData) *ecs.Entry {
|
|
|
|
entry, ok := worldData.EntityMap[psd.Id()]
|
2023-10-12 17:55:40 +08:00
|
|
|
if !ok {
|
2023-11-01 16:52:03 +08:00
|
|
|
entry = world.Entry(world.Create(PsdBaseComponentTypeArr...))
|
2023-10-19 17:09:47 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: psd.Id()})
|
|
|
|
worldData.EntityMap[psd.Id()] = entry
|
2023-11-03 10:41:47 +08:00
|
|
|
asdList := &component.AsdList{List: make([]*ecs.Entry, psd.AsdAmount(), psd.AsdAmount())}
|
|
|
|
for i := int32(0); i < psd.AsdAmount(); i++ {
|
|
|
|
asdList.List[i] = NewAsdEntry(world, worldData, psd.Id(), int(i))
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
|
|
|
component.AsdListType.Set(entry, asdList)
|
2023-12-08 17:13:50 +08:00
|
|
|
component.PscType.Set(entry, &component.Psc{InterlockKmGroup: make(map[int32]bool)})
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAsdEntry(world ecs.World, worldData *component.WorldData, psdId string, asdIndex int) *ecs.Entry {
|
2023-11-03 10:41:47 +08:00
|
|
|
entry := world.Entry(world.Create(AsdBaseComponentTypeArr...))
|
2023-11-01 16:52:03 +08:00
|
|
|
uid := psdId + "_" + strconv.Itoa(asdIndex)
|
|
|
|
worldData.EntityMap[uid] = entry
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMkxEntry(world ecs.World, worldData *component.WorldData, mkx *repository.Mkx) *ecs.Entry {
|
|
|
|
entry := world.Entry(world.Create(component.UidType, component.MkxType))
|
|
|
|
worldData.EntityMap[mkx.Id()] = entry
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: mkx.Id()})
|
|
|
|
mkxComponent := &component.Mkx{}
|
|
|
|
component.MkxType.Set(entry, mkxComponent)
|
|
|
|
if pcb := mkx.Pcb(); pcb != nil {
|
|
|
|
mkxComponent.PCB = NewButtonEntity(world, pcb, worldData.EntityMap)
|
|
|
|
}
|
|
|
|
if pob := mkx.Pob(); pob != nil {
|
|
|
|
mkxComponent.POB = NewButtonEntity(world, pob, worldData.EntityMap)
|
|
|
|
}
|
|
|
|
if pab := mkx.Pab(); pab != nil {
|
|
|
|
mkxComponent.PAB = NewButtonEntity(world, pab, worldData.EntityMap)
|
|
|
|
}
|
|
|
|
if mpl := mkx.Mpl(); mpl != nil {
|
|
|
|
mkxComponent.MPL = NewButtonEntity(world, mpl, worldData.EntityMap)
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPlatformMkxEntry(world ecs.World, entryMap map[string]*ecs.Entry, mkx *repository.Mkx) *ecs.Entry {
|
|
|
|
entry := world.Entry(world.Create(component.PlatformMkxCircuitType))
|
|
|
|
circuit := &component.PlatformMkxCircuit{}
|
|
|
|
if pcbj := mkx.Pcbj(); pcbj != nil {
|
|
|
|
circuit.PCBJ = NewRelayEntity(world, pcbj, entryMap)
|
|
|
|
}
|
|
|
|
if pobj := mkx.Pobj(); pobj != nil {
|
|
|
|
circuit.POBJ = NewRelayEntity(world, pobj, entryMap)
|
|
|
|
}
|
|
|
|
if pabj := mkx.Pabj(); pabj != nil {
|
|
|
|
circuit.PABJ = NewRelayEntity(world, pabj, entryMap)
|
2023-10-12 17:55:40 +08:00
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
component.PlatformMkxCircuitType.Set(entry, circuit)
|
2023-10-12 17:55:40 +08:00
|
|
|
return entry
|
|
|
|
}
|