rts-sim-module/entity/iscs_bas.go

182 lines
5.8 KiB
Go
Raw Normal View History

package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_data"
2023-12-27 11:28:34 +08:00
"joylink.club/rtsssimulation/consts"
2023-12-25 17:31:35 +08:00
"joylink.club/rtsssimulation/repository/model/proto"
)
2023-12-25 17:31:35 +08:00
// NewWireCabinetEntity 创建线柜实体
func NewWireCabinetEntity(w ecs.World, id string) *ecs.Entry {
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))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
2023-12-25 17:31:35 +08:00
// NewNetworkSwitchEntity 创建网络交换机实体
func NewNetworkSwitchEntity(w ecs.World, id string) *ecs.Entry {
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))
component.UidType.SetValue(e, component.Uid{Id: id})
2023-12-25 17:31:35 +08:00
component.NetworkSwitchType.Set(e, &component.NetworkSwitch{Normal: true})
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 {
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)
}
//
component.UidType.SetValue(e, component.Uid{Id: id})
2023-12-25 17:31:35 +08:00
component.AirPavilionType.Set(e, &component.AirPavilion{Normal: true})
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 {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
2023-12-29 17:48:57 +08:00
e = w.Entry(w.Create(component.UidType, component.ValveType, component.ValveControllerType, component.FixedPositionTransformType, component.DeviceExceptionType))
component.UidType.SetValue(e, component.Uid{Id: id})
2023-12-27 11:28:34 +08:00
//默认全关位置
component.FixedPositionTransformType.Set(e, &component.FixedPositionTransform{FixedPositionTransform: component_data.FixedPositionTransform{Pos: consts.TwoPosMin}})
2023-12-27 11:28:34 +08:00
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)
}
//
wd.EntityMap[id] = e
}
return e
}
2023-12-25 17:31:35 +08:00
// NewGasMixingChamberEntity 创建混合室静压箱实体
func NewGasMixingChamberEntity(w ecs.World, id string) *ecs.Entry {
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))
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-25 17:31:35 +08:00
func newAirConditioningEntity(w ecs.World, id string, tag *ecs.ComponentType[struct{}]) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
2023-12-29 17:00:26 +08:00
e = w.Entry(w.Create(component.UidType, component.MotorType, component.AirConditioningType, component.DeviceExceptionType, tag))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
2023-12-25 17:31:35 +08:00
// NewPurificationDeviceEntity 创建净化装置实体
func NewPurificationDeviceEntity(w ecs.World, id string) *ecs.Entry {
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))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
2023-12-25 17:31:35 +08:00
// NewAirCurtainEntity 创建空气幕实体
func NewAirCurtainEntity(w ecs.World, id string) *ecs.Entry {
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))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
2023-12-25 17:31:35 +08:00
// NewGasEnvironmentEntity 创建气体环境实体
func NewGasEnvironmentEntity(w ecs.World, id string) *ecs.Entry {
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))
component.UidType.SetValue(e, component.Uid{Id: id})
wd.EntityMap[id] = e
}
return e
}
2023-12-25 17:31:35 +08:00
// NewFanEntity 创建风机实体
func NewFanEntity(w ecs.World, id string, fanType proto.Fan_Type) *ecs.Entry {
wd := GetWorldData(w)
e, ok := wd.EntityMap[id]
if !ok {
2023-12-27 18:11:27 +08:00
e = w.Entry(w.Create(component.UidType, component.MotorType, component.FluidDriverType, component.DeviceExceptionType))
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)
}
}
//
wd.EntityMap[id] = e
}
return e
}