2024-03-08 17:11:53 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2024-04-02 14:09:41 +08:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-03-08 17:11:53 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
2024-04-02 14:09:41 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2024-03-08 17:11:53 +08:00
|
|
|
"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 {
|
2024-04-02 14:09:41 +08:00
|
|
|
circuit := &component.XcjCircuit{
|
|
|
|
TWJList: make([]*ecs.Entry, xcj.NumSegments),
|
|
|
|
CFJList: make([]*ecs.Entry, xcj.NumSegments),
|
|
|
|
}
|
2024-03-08 17:11:53 +08:00
|
|
|
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 "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 "JTJ":
|
|
|
|
circuit.JTJ = NewRelayEntity(w, relay, wd.EntityMap)
|
|
|
|
case "TGYXJ":
|
|
|
|
circuit.TGYXJ = NewRelayEntity(w, relay, wd.EntityMap)
|
2024-04-02 14:09:41 +08:00
|
|
|
default:
|
|
|
|
if strings.Contains(ec.Code(), "TWJ") {
|
|
|
|
index, err := strconv.Atoi(ec.Code()[3:])
|
|
|
|
if err != nil {
|
|
|
|
return errors.New(fmt.Sprintf("洗车机继电器[%s]编号异常", ec.Code()))
|
|
|
|
}
|
|
|
|
circuit.TWJList[index-1] = NewRelayEntity(w, relay, wd.EntityMap)
|
|
|
|
} else if strings.Contains(ec.Code(), "CFJ") {
|
|
|
|
index, err := strconv.Atoi(ec.Code()[3:])
|
|
|
|
if err != nil {
|
|
|
|
return errors.New(fmt.Sprintf("洗车机继电器[%s]编号异常", ec.Code()))
|
|
|
|
}
|
|
|
|
circuit.CFJList[index-1] = NewRelayEntity(w, relay, wd.EntityMap)
|
|
|
|
}
|
2024-03-08 17:11:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|