rts-sim-module/entity/ckm.go

48 lines
1.4 KiB
Go
Raw Normal View History

package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"unsafe"
)
var CkmBaseComponentTypes = []ecs.IComponentType{component.UidType, component.CkmTag, component.CkmStateType, component.FixedPositionTransformType}
func LoadCkm(w ecs.World) error {
data := GetWorldData(w)
for _, ckm := range data.Repo.CkmList() {
//创建基础entry
entry := w.Entry(w.Create(CkmBaseComponentTypes...))
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
}