2023-10-12 13:47:57 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 创建按钮实体
|
|
|
|
func NewButtonEntity(w ecs.World, data *repository.Button, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
|
|
|
uid := data.Id()
|
|
|
|
entry, ok := entityMap[uid]
|
|
|
|
if !ok {
|
|
|
|
var btnType ecs.IComponentType
|
|
|
|
switch data.GetBtnType() {
|
|
|
|
case proto.Button_NO_Reset_Press:
|
|
|
|
btnType = component.NoResetPressBtn
|
|
|
|
case proto.Button_NO_Reset_Up:
|
|
|
|
btnType = component.NoResetUpBtn
|
|
|
|
case proto.Button_Reset_Press:
|
|
|
|
btnType = component.ResetPressBtn
|
|
|
|
case proto.Button_Reset_Up:
|
|
|
|
btnType = component.ResetUpBtn
|
|
|
|
case proto.Button_Key_Knob:
|
2023-10-12 15:03:11 +08:00
|
|
|
btnType = component.KeyKnob
|
2023-10-12 13:47:57 +08:00
|
|
|
default:
|
|
|
|
btnType = component.UnknowBtn
|
|
|
|
}
|
2023-10-18 11:17:08 +08:00
|
|
|
entry = w.Entry(w.Create(component.ButtonTag, btnType, component.UidType, component.BitStateType))
|
2023-10-12 17:46:43 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2023-10-18 11:17:08 +08:00
|
|
|
// 带灯按钮
|
2023-10-18 14:08:10 +08:00
|
|
|
if data.HasLight() {
|
2023-11-02 13:21:14 +08:00
|
|
|
entry.AddComponent(component.SingleLightType, unsafe.Pointer(&component.SingleLight{Light: NewLightEntity(w)}))
|
2023-10-18 11:17:08 +08:00
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
entityMap[uid] = entry
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
|
|
|
// 创建蜂鸣器实体
|
2023-10-12 17:46:43 +08:00
|
|
|
func NewAlarmEntity(w ecs.World, alarm *repository.Alarm, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
|
|
|
uid := alarm.Id()
|
2023-10-12 13:47:57 +08:00
|
|
|
entry, ok := entityMap[uid]
|
|
|
|
if !ok {
|
2023-10-18 11:17:08 +08:00
|
|
|
entry = w.Entry(w.Create(component.AlarmTag, component.UidType, component.AlarmDriveType, component.BitStateType))
|
2023-10-12 17:46:43 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
2023-10-12 13:47:57 +08:00
|
|
|
entityMap[uid] = entry
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
2023-10-17 17:47:19 +08:00
|
|
|
// 创建IBP灯实体
|
|
|
|
func NewIBPLightEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
|
|
|
entry, ok := entityMap[uid]
|
|
|
|
if !ok {
|
2023-10-19 16:38:46 +08:00
|
|
|
entry = w.Entry(w.Create(component.LightTag, component.UidType, component.LightDriveType, component.BitStateType))
|
2023-10-17 17:47:19 +08:00
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
|
|
|
entityMap[uid] = entry
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
2023-10-20 13:13:44 +08:00
|
|
|
// 创建IBP钥匙实体
|
|
|
|
func NewIBPKeyEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
|
|
|
entry, ok := entityMap[uid]
|
|
|
|
if !ok {
|
|
|
|
entry = w.Entry(w.Create(component.KeyTag, component.UidType, component.GearStateType))
|
|
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
|
|
|
entityMap[uid] = entry
|
|
|
|
}
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
2023-10-12 13:47:57 +08:00
|
|
|
// 构建人员防护实体
|
2023-10-17 15:05:13 +08:00
|
|
|
func LoadSPKEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, worldData *component.WorldData) error {
|
|
|
|
entityMap := worldData.EntityMap
|
2023-10-12 13:47:57 +08:00
|
|
|
spk := &component.SpkElectronic{}
|
|
|
|
// 按钮组
|
2023-10-12 17:46:43 +08:00
|
|
|
for _, btn := range spkData.Buttons() {
|
2023-10-18 11:17:08 +08:00
|
|
|
e := NewButtonEntity(w, btn, entityMap)
|
2023-10-13 16:24:28 +08:00
|
|
|
switch btn.Code() {
|
2023-10-23 11:23:15 +08:00
|
|
|
case "X旁路":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSXPLA_BTN = e
|
2023-10-23 11:23:15 +08:00
|
|
|
case "S旁路":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSSPLA_BTN = e
|
2023-10-20 13:13:44 +08:00
|
|
|
case "人员防护试灯":
|
|
|
|
spk.SDA = e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 钥匙组
|
|
|
|
for _, key := range spkData.Keys() {
|
|
|
|
e := NewIBPKeyEntity(w, key.Id(), entityMap)
|
|
|
|
switch key.Code() {
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKS1":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSX1J_KEY = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKS3":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSX3J_KEY = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKS2":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSS2J_KEY = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKS4":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSS4J_KEY = e
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
// 继电器组
|
2023-10-12 17:46:43 +08:00
|
|
|
for _, relay := range spkData.Relays() {
|
2023-10-18 11:17:08 +08:00
|
|
|
e := NewRelayEntity(w, relay, entityMap)
|
2023-10-12 17:46:43 +08:00
|
|
|
switch relay.Code() {
|
|
|
|
case "SPKSX1J":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSX1J = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKSX3J":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSX3J = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKSS2J":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSS2J = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKSS4J":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSS4J = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKSXPLAJ":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSXPLAJ = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SPKSSPLAJ":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSSPLAJ = e
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
// 灯组
|
2023-10-17 17:47:19 +08:00
|
|
|
for _, light := range spkData.Lights() {
|
2023-10-18 11:17:08 +08:00
|
|
|
e := NewIBPLightEntity(w, light.Id(), entityMap)
|
2023-10-17 17:47:19 +08:00
|
|
|
switch light.Code() {
|
|
|
|
case "启用状态_SPKS1":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSX1D = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "启用状态_SPKS3":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSX3D = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "启用状态_SPKS2":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSS2D = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "启用状态_SPKS4":
|
2023-10-18 11:17:08 +08:00
|
|
|
spk.SPKSS4D = e
|
2023-10-17 17:47:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 17:46:43 +08:00
|
|
|
// 绑定组件
|
2023-10-12 13:47:57 +08:00
|
|
|
entry.AddComponent(component.SpkElectronicType, unsafe.Pointer(spk))
|
|
|
|
entry.AddComponent(component.SpkCollectStateType, unsafe.Pointer(&component.SpkCollectState{}))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 构建紧急关闭实体
|
2023-10-17 15:05:13 +08:00
|
|
|
func LoadEMPEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, worldData *component.WorldData) error {
|
|
|
|
entityMap := worldData.EntityMap
|
2023-10-12 13:47:57 +08:00
|
|
|
emp := &component.EmpElectronic{}
|
|
|
|
// 按钮组
|
2023-10-12 17:46:43 +08:00
|
|
|
for _, btn := range spkData.Buttons() {
|
2023-10-18 11:17:08 +08:00
|
|
|
e := NewButtonEntity(w, btn, entityMap)
|
2023-10-13 16:24:28 +08:00
|
|
|
switch btn.Code() {
|
2023-10-12 17:46:43 +08:00
|
|
|
case "EMP1":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMP1_BTN = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "EMP3":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMP3_BTN = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "EMP5":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMP5_BTN = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "EMP2":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMP2_BTN = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "EMP4":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMP4_BTN = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "EMP6":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMP6_BTN = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "X紧急关闭":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMPX_BTN = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "S紧急关闭":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.EMPS_BTN = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "X紧急关闭复原":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.XEMPFA_BTN = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "S紧急关闭复原":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.SEMPFA_BTN = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "切断警铃":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.QBA = e
|
2023-10-17 17:47:19 +08:00
|
|
|
case "信号试灯":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.SDA = e
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
// 继电器组
|
2023-10-12 17:46:43 +08:00
|
|
|
for _, relay := range spkData.Relays() {
|
2023-10-18 11:17:08 +08:00
|
|
|
e := NewRelayEntity(w, relay, entityMap)
|
2023-10-12 17:46:43 +08:00
|
|
|
switch relay.Code() {
|
|
|
|
case "XEMPJ":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.XEMPJ = e
|
2023-10-12 17:46:43 +08:00
|
|
|
case "SEMPJ":
|
2023-10-18 11:17:08 +08:00
|
|
|
emp.SEMPJ = e
|
2023-10-12 17:46:43 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
// 灯组
|
2023-10-17 17:47:19 +08:00
|
|
|
for _, light := range spkData.Lights() {
|
2023-10-18 11:17:08 +08:00
|
|
|
e := NewIBPLightEntity(w, light.Id(), entityMap)
|
2023-10-17 17:47:19 +08:00
|
|
|
switch light.Code() {
|
2023-10-20 14:36:04 +08:00
|
|
|
case "X紧急关闭":
|
2023-10-20 15:50:51 +08:00
|
|
|
emp.XEMPD = e
|
2023-10-20 14:36:04 +08:00
|
|
|
case "S紧急关闭":
|
2023-10-20 15:50:51 +08:00
|
|
|
emp.SEMPD = e
|
2023-10-17 17:47:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
// 蜂鸣器
|
2023-10-12 17:46:43 +08:00
|
|
|
for _, alarm := range spkData.Alarms() {
|
|
|
|
switch alarm.Code() {
|
2023-10-17 17:47:19 +08:00
|
|
|
case "报警电铃":
|
2023-10-12 17:46:43 +08:00
|
|
|
emp.Alarm = NewAlarmEntity(w, alarm, entityMap)
|
|
|
|
}
|
|
|
|
}
|
2023-10-12 13:47:57 +08:00
|
|
|
entry.AddComponent(component.EmpElectronicType, unsafe.Pointer(emp))
|
|
|
|
entry.AddComponent(component.EmpCollectStateType, unsafe.Pointer(&component.EmpCollectState{}))
|
|
|
|
return nil
|
|
|
|
}
|