rts-sim-module/sys/iscs_sys/iscs_pscada_earthing_device.go

41 lines
1.1 KiB
Go
Raw Normal View History

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
)
type EarthingDeviceSystem struct {
query *ecs.Query
}
func NewEarthingDeviceSystem() *EarthingDeviceSystem {
return &EarthingDeviceSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.EarthingDeviceType)),
}
}
// Update 接地装置传递异常电能
func (s *EarthingDeviceSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
edId := component.UidType.Get(entry).Id
ed := component.EarthingDeviceType.Get(entry)
//
edModel := (wd.Repo.FindById(edId)).(*repository.EarthingDevice)
if edModel.PortA != nil {
edPipeEntry := wd.EntityMap[edModel.PortA.Device().Id()]
2024-01-05 11:30:39 +08:00
if !edPipeEntry.HasComponent(component.PipeElectricityType) {
edPipeEntry.AddComponent(component.PipeElectricityType)
}
edPipe := component.PipeElectricityType.Get(edPipeEntry)
ed.Voltage = edPipe.U
} else {
2024-01-05 11:30:39 +08:00
ed.Voltage = 0 //零电压
}
})
}