rts-sim-module/sys/iscs_sys/iscs_pscada_power_souce.go
2024-01-05 15:21:29 +08:00

46 lines
1.2 KiB
Go

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
"time"
)
// PowerSourceSystem 国网
type PowerSourceSystem struct {
query *ecs.Query
}
func NewPowerSourceSystem() *PowerSourceSystem {
return &PowerSourceSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.ElectricitySourceType)),
}
}
func (s *PowerSourceSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
psId := component.UidType.Get(entry).Id
ps := component.ElectricitySourceType.Get(entry)
//
psModel := (wd.Repo.FindById(psId)).(*repository.PowerSource)
pipeId := psModel.PortA.Device().Id()
//
ps.Fresh = time.Now().UnixMilli()
ps.Sx = psModel.Sx
ps.Ac = psModel.Ac
ps.U = psModel.Voltage
//电源传递电力给母线
s.transPower(wd, pipeId, ps, psId)
})
}
func (s *PowerSourceSystem) transPower(wd *component.WorldData, pipeId string, ps *component.ElectricitySource, psId string) {
pipeEntry := wd.EntityMap[pipeId]
//
powerPipe := perfectPipeElectricity(pipeEntry)
powerPipe.TransPower(psId, ps)
}