2024-03-07 17:40:51 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2024-03-08 17:11:53 +08:00
|
|
|
var CkmBaseComponentTypes = []ecs.IComponentType{component.UidType, component.CkmTag, component.CkmStateType, component.FixedPositionTransformType}
|
2024-03-07 17:40:51 +08:00
|
|
|
|
|
|
|
func LoadCkm(w ecs.World) error {
|
|
|
|
data := GetWorldData(w)
|
|
|
|
for _, ckm := range data.Repo.CkmList() {
|
|
|
|
//创建基础entry
|
2024-03-08 17:11:53 +08:00
|
|
|
entry := w.Entry(w.Create(CkmBaseComponentTypes...))
|
2024-03-07 17:40:51 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: ckm.Id()})
|
|
|
|
data.EntityMap[ckm.Id()] = entry
|
|
|
|
//加载电路
|
|
|
|
if len(ckm.ComponentGroups()) != 0 {
|
|
|
|
circuit := &component.CkmCircuit{}
|
|
|
|
entry.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|