rts-sim-module/system/emp_relay_system.go
2023-08-29 17:38:20 +08:00

39 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/umi"
)
// 紧急停车按钮继电器系统
type EmpRelaySystem struct {
relaySystem
// 紧急停车按钮查询
query *ecs.Query
}
func NewEmpRelaySystem() *EmpRelaySystem {
return &EmpRelaySystem{
relaySystem: relaySystem{relayQuery: make(map[string]*ecs.Query)},
query: ecs.NewQuery(filter.Contains(components.EmpStateComponent)),
}
}
// world 执行
func (me *EmpRelaySystem) Update(world ecs.World) {
me.query.Each(world, func(empEntry *ecs.Entry) {
//key-继电器作用名value-继电器实体
usageRelayMapper := make(map[string]*ecs.Entry)
//迭代关联的所有继电器
me.getDeviceRelayQuery(empEntry).Each(world, func(empRelayEntry *ecs.Entry) {
relayId := components.DeviceIdentityComponent.Get(empRelayEntry).Id
relayModel := (WorldModelStorage(world).FindById(relayId)).(umi.IRelayModel)
usageRelayMapper[relayModel.UsageName()] = empRelayEntry
})
//根据具体业务逻辑处理继电器
})
}