rts-sim-module/entity/xcj.go

58 lines
1.8 KiB
Go
Raw Normal View History

package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"unsafe"
)
var XcjBaseComponentTypes = []ecs.IComponentType{component.UidType, component.XcjTag}
func LoadXcj(w ecs.World) error {
wd := GetWorldData(w)
for _, xcj := range wd.Repo.XcjList() {
//创建基础entry
entry := w.Entry(w.Create(XcjBaseComponentTypes...))
component.UidType.SetValue(entry, component.Uid{Id: xcj.Id()})
wd.EntityMap[xcj.Id()] = entry
//加载电路
if len(xcj.ComponentGroups()) != 0 {
circuit := &component.XcjCircuit{}
entry.AddComponent(component.XcjCircuitType, unsafe.Pointer(circuit))
for _, group := range xcj.ComponentGroups() {
for _, ec := range group.Components() {
relay := ec.(*repository.Relay)
switch ec.Code() {
case "XQJ":
circuit.XQJ = NewRelayEntity(w, relay, wd.EntityMap)
case "TWJ1":
circuit.TWJ1 = NewRelayEntity(w, relay, wd.EntityMap)
case "TWJ2":
circuit.TWJ2 = NewRelayEntity(w, relay, wd.EntityMap)
case "TWJ3":
circuit.TWJ3 = NewRelayEntity(w, relay, wd.EntityMap)
case "TGQJ":
circuit.TGQJ = NewRelayEntity(w, relay, wd.EntityMap)
case "XCJXJ":
circuit.XCJXJ = NewRelayEntity(w, relay, wd.EntityMap)
case "XCYXJ":
circuit.XCYXJ = NewRelayEntity(w, relay, wd.EntityMap)
case "CFJ1":
circuit.CFJ1 = NewRelayEntity(w, relay, wd.EntityMap)
case "CFJ2":
circuit.CFJ2 = NewRelayEntity(w, relay, wd.EntityMap)
case "CFJ3":
circuit.CFJ3 = NewRelayEntity(w, relay, wd.EntityMap)
case "JTJ":
circuit.JTJ = NewRelayEntity(w, relay, wd.EntityMap)
case "TGYXJ":
circuit.TGYXJ = NewRelayEntity(w, relay, wd.EntityMap)
}
}
}
}
}
return nil
}