2023-08-16 17:17:20 +08:00
|
|
|
package system
|
|
|
|
|
2023-08-16 18:13:18 +08:00
|
|
|
import (
|
|
|
|
"github.com/yohamta/donburi/filter"
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/components"
|
2023-08-23 15:13:06 +08:00
|
|
|
"joylink.club/rtsssimulation/components/cstate"
|
2023-08-16 18:13:18 +08:00
|
|
|
)
|
2023-08-16 17:17:20 +08:00
|
|
|
|
2023-08-23 16:01:01 +08:00
|
|
|
var PsdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent))
|
2023-08-17 14:25:18 +08:00
|
|
|
|
2023-08-18 16:15:19 +08:00
|
|
|
const (
|
|
|
|
//屏蔽门完全关闭
|
|
|
|
PsdCellWholeCloseRate = 100
|
|
|
|
//屏蔽门完全打开
|
|
|
|
PsdCellWholeOpenRate = 0
|
|
|
|
)
|
|
|
|
|
2023-08-16 17:17:20 +08:00
|
|
|
type PsdSystem struct {
|
2023-08-22 11:00:14 +08:00
|
|
|
cellsQuery map[cstate.EntityTag]*ecs.Query
|
2023-08-16 17:17:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPsdSystem() *PsdSystem {
|
2023-08-22 11:00:14 +08:00
|
|
|
return &PsdSystem{cellsQuery: make(map[cstate.EntityTag]*ecs.Query)}
|
2023-08-16 17:17:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// world 执行
|
|
|
|
func (me *PsdSystem) Update(world ecs.World) {
|
2023-08-23 16:01:01 +08:00
|
|
|
PsdQuery.Each(world, func(psdEntry *ecs.Entry) {
|
2023-08-18 16:15:19 +08:00
|
|
|
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
|
|
|
|
psdCellQuery, ok := me.cellsQuery[psdTag]
|
2023-08-16 18:13:18 +08:00
|
|
|
if !ok {
|
2023-08-18 17:16:00 +08:00
|
|
|
psdCellQuery = ecs.NewQuery(filter.Contains(psdTag, components.PercentageDeviceComponent))
|
|
|
|
me.cellsQuery[psdTag] = psdCellQuery
|
2023-08-16 18:13:18 +08:00
|
|
|
}
|
2023-08-18 16:15:19 +08:00
|
|
|
//
|
|
|
|
var allCellClosed, allCellOpened bool = true, true
|
|
|
|
psdCellQuery.Each(world, func(psdCellEntry *ecs.Entry) {
|
|
|
|
psdCellRate := components.PercentageDeviceComponent.Get(psdCellEntry).Rate
|
|
|
|
if allCellClosed {
|
|
|
|
allCellClosed = psdCellRate == PsdCellWholeCloseRate
|
2023-08-16 18:13:18 +08:00
|
|
|
}
|
2023-08-18 16:15:19 +08:00
|
|
|
if allCellOpened {
|
|
|
|
allCellOpened = psdCellRate == PsdCellWholeOpenRate
|
2023-08-16 18:13:18 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
//
|
2023-08-18 16:15:19 +08:00
|
|
|
psdState := components.PsdStateComponent.Get(psdEntry)
|
|
|
|
psdState.AllClosed = allCellClosed
|
|
|
|
psdState.AllOpened = allCellOpened
|
2023-08-16 18:13:18 +08:00
|
|
|
})
|
|
|
|
}
|