2023-12-11 17:16:51 +08:00
|
|
|
package entity
|
2023-12-11 18:09:28 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
2023-12-27 11:28:34 +08:00
|
|
|
"joylink.club/rtsssimulation/component/component_proto"
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
2023-12-25 17:31:35 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-12-11 18:09:28 +08:00
|
|
|
)
|
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewWireCabinetEntity 创建线柜实体
|
|
|
|
func NewWireCabinetEntity(w ecs.World, id string) *ecs.Entry {
|
2023-12-12 13:23:51 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.WireCabinetType, component.DeviceExceptionType))
|
2023-12-12 13:23:51 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
2023-12-11 18:09:28 +08:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewNetworkSwitchEntity 创建网络交换机实体
|
|
|
|
func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry {
|
2023-12-13 14:54:23 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.NetworkSwitchType, component.DeviceExceptionType))
|
2023-12-13 14:54:23 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
2023-12-25 17:31:35 +08:00
|
|
|
component.NetworkSwitchType.Set(e, &component.NetworkSwitch{Normal: true})
|
2023-12-13 14:54:23 +08:00
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewAirPavilionEntity 创建风亭实体
|
|
|
|
func NewAirPavilionEntity(w ecs.World, id string, apType proto.AirPavilion_Type) *ecs.Entry {
|
2023-12-13 14:54:23 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.AirPavilionType))
|
2023-12-25 17:31:35 +08:00
|
|
|
//
|
|
|
|
switch apType {
|
|
|
|
case proto.AirPavilion_ExhaustPavilion:
|
|
|
|
e.AddComponent(component.ExhaustPavilionTag)
|
|
|
|
case proto.AirPavilion_AirSupplyPavilion:
|
|
|
|
e.AddComponent(component.AirSupplyPavilionTag)
|
|
|
|
}
|
|
|
|
//
|
2023-12-13 14:54:23 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
2023-12-25 17:31:35 +08:00
|
|
|
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
|
2023-12-13 14:54:23 +08:00
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewValveEntity 创建阀门实体
|
|
|
|
func NewValveEntity(w ecs.World, id string, valveType proto.Valve_Type) *ecs.Entry {
|
2023-12-13 14:54:23 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-27 11:28:34 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.ValveType, component.ValveControllerType, component.TwoPositionTransformType, component.DeviceExceptionType))
|
2023-12-13 14:54:23 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
2023-12-27 11:28:34 +08:00
|
|
|
//默认全关位置
|
|
|
|
component.TwoPositionTransformType.Set(e, &component.TwoPositionTransform{TwoPositionTransform: component_proto.TwoPositionTransform{Pos: consts.TwoPosMin}})
|
|
|
|
component.ValveControllerType.Set(e, &component.ValveController{TargetOpenRate: 0})
|
2023-12-25 17:31:35 +08:00
|
|
|
//
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
//
|
2023-12-13 14:54:23 +08:00
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewGasMixingChamberEntity 创建混合室静压箱实体
|
|
|
|
func NewGasMixingChamberEntity(w ecs.World, id string) *ecs.Entry {
|
2023-12-13 14:54:23 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.GasMixingChamberType))
|
2023-12-13 14:54:23 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewCombinationAirConditionerEntity 创建组合式空调实体
|
|
|
|
func NewCombinationAirConditionerEntity(w ecs.World, id string) *ecs.Entry {
|
|
|
|
return newAirConditioningEntity(w, id, component.CombinationAirConditionerTag)
|
2023-12-13 14:54:23 +08:00
|
|
|
}
|
2023-12-25 17:31:35 +08:00
|
|
|
func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[struct{}]) *ecs.Entry {
|
2023-12-13 15:21:16 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.AirConditioningType, component.DeviceExceptionType, tag))
|
2023-12-13 15:21:16 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
2023-12-13 16:01:20 +08:00
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewPurificationDeviceEntity 创建净化装置实体
|
|
|
|
func NewPurificationDeviceEntity(w ecs.World, id string) *ecs.Entry {
|
2023-12-13 16:01:20 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.PurificationDeviceType, component.DeviceExceptionType))
|
2023-12-13 16:01:20 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
2023-12-13 16:10:18 +08:00
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewAirCurtainEntity 创建空气幕实体
|
|
|
|
func NewAirCurtainEntity(w ecs.World, id string) *ecs.Entry {
|
2023-12-13 16:10:18 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.AirCurtainType, component.DeviceExceptionType))
|
2023-12-13 16:10:18 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
2023-12-13 17:01:19 +08:00
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewGasEnvironmentEntity 创建气体环境实体
|
|
|
|
func NewGasEnvironmentEntity(w ecs.World, id string) *ecs.Entry {
|
2023-12-13 17:01:19 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 14:45:41 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.GasEnvironmentType))
|
2023-12-13 17:01:19 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
2023-12-13 17:27:26 +08:00
|
|
|
|
2023-12-25 17:31:35 +08:00
|
|
|
// NewFanEntity 创建风机实体
|
|
|
|
func NewFanEntity(w ecs.World, id string, fanType proto.Fan_Type) *ecs.Entry {
|
2023-12-13 17:27:26 +08:00
|
|
|
wd := GetWorldData(w)
|
|
|
|
e, ok := wd.EntityMap[id]
|
|
|
|
if !ok {
|
2023-12-26 17:52:28 +08:00
|
|
|
e = w.Entry(w.Create(component.UidType, component.MotorType, component.DeviceExceptionType))
|
2023-12-13 17:27:26 +08:00
|
|
|
component.UidType.SetValue(e, component.Uid{Id: id})
|
2023-12-26 17:52:28 +08:00
|
|
|
component.MotorType.Set(e, &component.Motor{Speed: 0, Forward: true, Ms: component.MsOff})
|
2023-12-25 17:31:35 +08:00
|
|
|
//
|
|
|
|
switch fanType {
|
|
|
|
case proto.Fan_CommonFan:
|
|
|
|
{
|
|
|
|
e.AddComponent(component.CommonFanTag)
|
|
|
|
}
|
|
|
|
case proto.Fan_FcBypassFan:
|
|
|
|
{
|
2023-12-26 17:52:28 +08:00
|
|
|
e.AddComponent(component.MotorFcType)
|
2023-12-25 17:31:35 +08:00
|
|
|
e.AddComponent(component.FanBypassUnitType)
|
|
|
|
e.AddComponent(component.FcBypassFanTag)
|
|
|
|
}
|
|
|
|
case proto.Fan_SoftStartFan:
|
|
|
|
{
|
|
|
|
e.AddComponent(component.SoftStartFanTag)
|
|
|
|
}
|
|
|
|
case proto.Fan_HighLowSpeedFan:
|
|
|
|
{
|
|
|
|
e.AddComponent(component.FanHighLowSpeedModeType)
|
|
|
|
e.AddComponent(component.HighLowSpeedFanTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
2023-12-13 17:27:26 +08:00
|
|
|
wd.EntityMap[id] = e
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|