40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package system
|
|
|
|
import (
|
|
"github.com/yohamta/donburi/filter"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/components"
|
|
)
|
|
|
|
// 百分比设备系统
|
|
type PercentageSystem struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewPercentageSystem() *PercentageSystem {
|
|
return &PercentageSystem{query: ecs.NewQuery(filter.Contains(components.PercentageDeviceComponent, components.PercentageDeviceOperatingComponent))}
|
|
}
|
|
|
|
// world 执行
|
|
func (me *PercentageSystem) Update(world ecs.World) {
|
|
me.query.Each(world, func(e *ecs.Entry) {
|
|
operation := components.PercentageDeviceOperatingComponent.Get(e)
|
|
if operation.RemainingDistance <= 0 {
|
|
operation.RemainingDistance = 0
|
|
e.RemoveComponent(components.PercentageDeviceOperatingComponent)
|
|
} else {
|
|
operation.RemainingDistance -= int64(world.Tick())
|
|
if operation.RemainingDistance < 0 {
|
|
operation.RemainingDistance = 0
|
|
}
|
|
}
|
|
//
|
|
rateDevice := components.PercentageDeviceComponent.Get(e)
|
|
if operation.ToH { //百分比变大
|
|
rateDevice.Rate = int32(float64(100) * (float64(operation.InitDistance+operation.SumDistance-operation.RemainingDistance) / float64(operation.LhDistance)))
|
|
} else {
|
|
rateDevice.Rate = 100 - int32(float64(100)*(float64(operation.InitDistance+operation.SumDistance-operation.RemainingDistance)/float64(operation.LhDistance)))
|
|
}
|
|
})
|
|
}
|