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

52 lines
1.5 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"
"time"
)
2024-01-05 11:30:39 +08:00
// PowerSourceSystem 国网
type PowerSourceSystem struct {
query *ecs.Query
}
func NewPowerSourceSystem() *PowerSourceSystem {
return &PowerSourceSystem{
2024-01-05 11:30:39 +08:00
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
2024-01-05 11:30:39 +08:00
ps := component.ElectricitySourceType.Get(entry)
//
psModel := (wd.Repo.FindById(psId)).(*repository.PowerSource)
pipeId := psModel.PortA.Device().Id()
2024-01-05 11:30:39 +08:00
//
ps.Fresh = time.Now().UnixMilli()
ps.Sx = psModel.Sx
ps.Ac = psModel.Ac
ps.U = psModel.Voltage
//电源传递电力给母线
2024-01-05 11:30:39 +08:00
s.transPower(wd, pipeId, ps, psId)
})
}
2024-01-05 11:30:39 +08:00
func (s *PowerSourceSystem) transPower(wd *component.WorldData, pipeId string, ps *component.ElectricitySource, psId string) {
pipeEntry := wd.EntityMap[pipeId]
if !pipeEntry.HasComponent(component.PipeElectricityType) {
pipeEntry.AddComponent(component.PipeElectricityType)
component.PipeElectricityType.Set(pipeEntry, component.NewPipeElectricity())
}
pipe := component.PipeType.Get(pipeEntry)
pipe.Matter = component.PmtElectricity
//
powerPipe := component.PipeElectricityType.Get(pipeEntry)
powerPipe.TransPower(psId, ps)
}