178 lines
5.4 KiB
Go
178 lines
5.4 KiB
Go
package entity
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
)
|
|
|
|
// NewWireCabinetEntity 创建线柜实体
|
|
func NewWireCabinetEntity(w ecs.World, id string) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.WireCabinetType, component.DeviceExceptionType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewNetworkSwitchEntity 创建网络交换机实体
|
|
func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.NetworkSwitchType, component.DeviceExceptionType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
component.NetworkSwitchType.Set(e, &component.NetworkSwitch{Normal: true})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewAirPavilionEntity 创建风亭实体
|
|
func NewAirPavilionEntity(w ecs.World, id string, apType proto.AirPavilion_Type) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.AirPavilionType))
|
|
//
|
|
switch apType {
|
|
case proto.AirPavilion_ExhaustPavilion:
|
|
e.AddComponent(component.ExhaustPavilionTag)
|
|
case proto.AirPavilion_AirSupplyPavilion:
|
|
e.AddComponent(component.AirSupplyPavilionTag)
|
|
}
|
|
//
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewValveEntity 创建阀门实体
|
|
func NewValveEntity(w ecs.World, id string, valveType proto.Valve_Type) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.ValveType, component.DeviceExceptionType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
component.ValveType.Set(e, &component.Valve{OpenRate: 100, Closed: false, Opened: true, Moving: false})
|
|
//
|
|
switch valveType {
|
|
case proto.Valve_ElectricControlValve:
|
|
e.AddComponent(component.ElectricControlValveTag)
|
|
case proto.Valve_ElectricAirValve:
|
|
e.AddComponent(component.ElectricAirValveTag)
|
|
case proto.Valve_CombinationAirValve:
|
|
e.AddComponent(component.CombinationAirValveTag)
|
|
case proto.Valve_ElectricButterflyValve:
|
|
e.AddComponent(component.ElectricButterflyValveTag)
|
|
}
|
|
//
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewGasMixingChamberEntity 创建混合室静压箱实体
|
|
func NewGasMixingChamberEntity(w ecs.World, id string) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.GasMixingChamberType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewCombinationAirConditionerEntity 创建组合式空调实体
|
|
func NewCombinationAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
|
return newAirConditioningEntity(w, id, component.CombinationAirConditionerTag)
|
|
}
|
|
func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[struct{}]) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.AirConditioningType, component.DeviceExceptionType, tag))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewPurificationDeviceEntity 创建净化装置实体
|
|
func NewPurificationDeviceEntity(w ecs.World, id string) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.PurificationDeviceType, component.DeviceExceptionType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewAirCurtainEntity 创建空气幕实体
|
|
func NewAirCurtainEntity(w ecs.World, id string) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.AirCurtainType, component.DeviceExceptionType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewGasEnvironmentEntity 创建气体环境实体
|
|
func NewGasEnvironmentEntity(w ecs.World, id string) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.GasEnvironmentType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|
|
|
|
// NewFanEntity 创建风机实体
|
|
func NewFanEntity(w ecs.World, id string, fanType proto.Fan_Type) *ecs.Entry {
|
|
wd := GetWorldData(w)
|
|
e, ok := wd.EntityMap[id]
|
|
if !ok {
|
|
e := w.Entry(w.Create(component.UidType, component.FanDeviceType, component.DeviceExceptionType))
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
//
|
|
switch fanType {
|
|
case proto.Fan_CommonFan:
|
|
{
|
|
e.AddComponent(component.CommonFanTag)
|
|
}
|
|
case proto.Fan_FcBypassFan:
|
|
{
|
|
e.AddComponent(component.FanFcUnitType)
|
|
e.AddComponent(component.FanBypassUnitType)
|
|
e.AddComponent(component.FcBypassFanTag)
|
|
}
|
|
case proto.Fan_SoftStartFan:
|
|
{
|
|
e.AddComponent(component.FanSoftStartUnitType)
|
|
e.AddComponent(component.SoftStartFanTag)
|
|
}
|
|
case proto.Fan_HighLowSpeedFan:
|
|
{
|
|
e.AddComponent(component.FanHighLowSpeedModeType)
|
|
e.AddComponent(component.HighLowSpeedFanTag)
|
|
}
|
|
}
|
|
//
|
|
wd.EntityMap[id] = e
|
|
}
|
|
return e
|
|
}
|