35 lines
986 B
Go
35 lines
986 B
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"
|
||
|
)
|
||
|
|
||
|
type PowerSourceSystem struct {
|
||
|
query *ecs.Query
|
||
|
}
|
||
|
|
||
|
func NewPowerSourceSystem() *PowerSourceSystem {
|
||
|
return &PowerSourceSystem{
|
||
|
query: ecs.NewQuery(filter.Contains(component.UidType, component.PowerSourceType)),
|
||
|
}
|
||
|
}
|
||
|
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.PowerSourceType.Get(entry)
|
||
|
//
|
||
|
psModel := (wd.Repo.FindById(psId)).(*repository.PowerSource)
|
||
|
pipeId := psModel.PortA.Device().Id()
|
||
|
//电源传递电力给母线
|
||
|
pipeEntry := wd.EntityMap[pipeId]
|
||
|
powerPipe := component.PowerPipeType.Get(pipeEntry)
|
||
|
powerPipe.TransPower(psId, &component.ElePower{Ac: ps.Ac, Voltage: ps.Voltage, Fresh: time.Now().UnixMilli()})
|
||
|
})
|
||
|
}
|