2023-10-12 17:55:40 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-12 17:55:40 +08:00
|
|
|
circuit := &component.PsdCircuit{}
|
|
|
|
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)
|
|
|
|
case "4XKMJ", "4SKMJ":
|
|
|
|
circuit.KMJ4 = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "8XKMJ", "8SKMJ":
|
|
|
|
circuit.KMJ8 = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "XMGJ", "SMGJ":
|
|
|
|
circuit.MGJ = NewRelayEntity(world, relay, entryMap)
|
|
|
|
case "XMPLJ", "SMPLJ":
|
|
|
|
circuit.MPLJ = NewRelayEntity(world, relay, entryMap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-10-19 17:09:47 +08:00
|
|
|
entry = world.Entry(world.Create(component.PsdTag, component.UidType, component.PsdInfoType, component.PsdStateType,
|
2023-10-20 16:12:42 +08:00
|
|
|
component.PsdDriveCircuitType, component.PsdCollectionCircuitType, component.PsdMotorType))
|
2023-10-19 17:09:47 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: psd.Id()})
|
|
|
|
component.PsdInfoType.SetValue(entry, component.PsdInfo{PlatformId: psd.PlatformId()})
|
2023-10-13 18:20:15 +08:00
|
|
|
psdMotor := world.Entry(world.Create(component.PsdMotorStateType))
|
2023-10-19 17:09:47 +08:00
|
|
|
component.PsdMotorType.Set(entry, psdMotor)
|
|
|
|
worldData.EntityMap[psd.Id()] = entry
|
2023-10-12 17:55:40 +08:00
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|