rts-sim-module/sys/iscs_sys/iscs_bas_water_tank.go
2023-12-19 11:11:27 +08:00

56 lines
1.6 KiB
Go

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// WaterTankSystem 水池水箱
type WaterTankSystem struct {
query *ecs.Query
}
func NewWaterTankSystem() *WaterTankSystem {
return &WaterTankSystem{
query: ecs.NewQuery(filter.Contains(component.WaterTankType, component.UidType)),
}
}
func (s *WaterTankSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
waterTankId := component.UidType.Get(entry).Id
waterTank := component.WaterTankType.Get(entry)
waterTank.Level = s.calculateWaterLevel(w, waterTankId, waterTank.Value)
//
waterPumps := s.findWaterPumps(w, waterTankId)
for _, waterPump := range waterPumps {
//浮球型水泵,通过水箱水位等级来控制浮球开关从而控制水泵开关
if waterPump.HasComponent(component.FloatBallSwitchType) {
floatBall := component.FloatBallSwitchType.Get(waterPump)
switch waterTank.Level {
case component.WaterLevelNormal:
fallthrough
case component.WaterLevelLow:
floatBall.On = false
case component.WaterLevelHigh:
floatBall.On = true
}
}
//
}
})
}
// 根据水箱来获取水箱内的水泵实体
func (s *WaterTankSystem) findWaterPumps(w ecs.World, waterTankId string) (waterPumps []*ecs.Entry) {
//todo
panic("WaterTankSystem.findWaterPumps 方法未实现")
return waterPumps
}
// 根据水箱水深计算水箱水位等级
func (s *WaterTankSystem) calculateWaterLevel(w ecs.World, waterTankId string, waterTankVale int32) component.WaterLevel {
//todo
return component.WaterLevelNormal
}