114 lines
3.8 KiB
Go
114 lines
3.8 KiB
Go
|
package entity
|
||
|
|
||
|
import (
|
||
|
"unsafe"
|
||
|
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/component"
|
||
|
"joylink.club/rtsssimulation/repository"
|
||
|
"joylink.club/rtsssimulation/repository/model/proto"
|
||
|
)
|
||
|
|
||
|
// 创建IBP实体
|
||
|
func NewIBPEntity(w ecs.World, entityMap map[string]*ecs.Entry) {
|
||
|
entry := w.Entry(w.Create(component.IBP))
|
||
|
loadSPKEntity(w, entry, entityMap)
|
||
|
loadEMPEntity(w, entry, entityMap)
|
||
|
}
|
||
|
|
||
|
// 创建按钮实体
|
||
|
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:
|
||
|
btnType = component.KeyKnobBtn
|
||
|
default:
|
||
|
btnType = component.UnknowBtn
|
||
|
}
|
||
|
entry = w.Entry(w.Create(btnType, component.BitStateType))
|
||
|
entityMap[uid] = entry
|
||
|
}
|
||
|
return entry
|
||
|
}
|
||
|
|
||
|
// 创建蜂鸣器实体
|
||
|
func NewFMQEntity(w ecs.World, data *repository.Fmq, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
||
|
uid := data.Id()
|
||
|
entry, ok := entityMap[uid]
|
||
|
if !ok {
|
||
|
entry = w.Entry(w.Create(component.FMQDriveType, component.BitStateType))
|
||
|
entityMap[uid] = entry
|
||
|
}
|
||
|
return entry
|
||
|
}
|
||
|
|
||
|
// 构建人员防护实体
|
||
|
func loadSPKEntity(w ecs.World, entry *ecs.Entry, entityMap map[string]*ecs.Entry) error {
|
||
|
spk := &component.SpkElectronic{}
|
||
|
// 按钮组
|
||
|
spk.SPKSXPLA_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
spk.SPKSSPLA_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
spk.SPKSX1J_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
spk.SPKSX3J_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
spk.SPKSS2J_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
spk.SPKSS4J_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
spk.SDA = NewButtonEntity(w, nil, entityMap)
|
||
|
// 继电器组
|
||
|
spk.SPKSX1J = NewRelayEntity(w, nil, entityMap)
|
||
|
spk.SPKSX3J = NewRelayEntity(w, nil, entityMap)
|
||
|
spk.SPKSS2J = NewRelayEntity(w, nil, entityMap)
|
||
|
spk.SPKSS4J = NewRelayEntity(w, nil, entityMap)
|
||
|
spk.SPKSXPLAJ = NewRelayEntity(w, nil, entityMap)
|
||
|
spk.SPKSSPLAJ = NewRelayEntity(w, nil, entityMap)
|
||
|
// 灯组
|
||
|
spk.SPKSX1D = NewLightHEntity(w)
|
||
|
spk.SPKSX3D = NewLightHEntity(w)
|
||
|
spk.SPKSS2D = NewLightHEntity(w)
|
||
|
spk.SPKSS4D = NewLightHEntity(w)
|
||
|
spk.SPKSXPLAD = NewLightHEntity(w)
|
||
|
spk.SPKSSPLAD = NewLightHEntity(w)
|
||
|
entry.AddComponent(component.SpkElectronicType, unsafe.Pointer(spk))
|
||
|
entry.AddComponent(component.SpkCollectStateType, unsafe.Pointer(&component.SpkCollectState{}))
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// 构建紧急关闭实体
|
||
|
func loadEMPEntity(w ecs.World, entry *ecs.Entry, entityMap map[string]*ecs.Entry) error {
|
||
|
emp := &component.EmpElectronic{}
|
||
|
// 按钮组
|
||
|
emp.EMP1_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMP3_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMP5_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMPX_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMP2_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMP4_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMP6_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.EMPS_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.XEMPFA_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.SEMPFA_BTN = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.QBA = NewButtonEntity(w, nil, entityMap)
|
||
|
emp.SDA = NewButtonEntity(w, nil, entityMap)
|
||
|
// 继电器组
|
||
|
emp.XEMPJ = NewRelayEntity(w, nil, entityMap)
|
||
|
emp.SEMPJ = NewRelayEntity(w, nil, entityMap)
|
||
|
// 灯组
|
||
|
emp.XEMPD = NewLightHEntity(w)
|
||
|
emp.SEMPD = NewLightHEntity(w)
|
||
|
// 蜂鸣器
|
||
|
emp.FMQ = NewFMQEntity(w, nil, entityMap)
|
||
|
entry.AddComponent(component.EmpElectronicType, unsafe.Pointer(emp))
|
||
|
entry.AddComponent(component.EmpCollectStateType, unsafe.Pointer(&component.EmpCollectState{}))
|
||
|
return nil
|
||
|
}
|