53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
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 {
|
|
entry := NewPsdEntry(w, psd.Id(), data)
|
|
loadPsdCircuit(w, entry, psd, data.EntityMap)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entryMap map[string]*ecs.Entry) {
|
|
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)
|
|
}
|
|
|
|
func NewPsdEntry(world ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
|
|
entry, ok := worldData.EntityMap[uid]
|
|
if !ok {
|
|
psd := world.Entry(world.Create(component.PsdTag, component.UidType, component.PsdStateType,
|
|
component.PsdCircuitType, component.PsdDriveCircuitType, component.PsdCollectionCircuitType, component.PsdMotorType))
|
|
component.UidType.SetValue(psd, component.Uid{Id: uid})
|
|
psdMotor := world.Entry(world.Create(component.PsdMotorStateType))
|
|
component.PsdMotorType.Set(psd, psdMotor)
|
|
worldData.EntityMap[uid] = psd
|
|
}
|
|
return entry
|
|
}
|