43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
|
package operate
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/yohamta/donburi/filter"
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/components"
|
||
|
"joylink.club/rtsssimulation/system"
|
||
|
)
|
||
|
|
||
|
// 紧急停车按钮查询
|
||
|
var empQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.EmpStateComponent))
|
||
|
|
||
|
func findEmpEntry(world ecs.World, empId string) (*ecs.Entry, error) {
|
||
|
empEntry := system.QueryEntityById(world, empQuery, empId)
|
||
|
if empEntry == nil {
|
||
|
return nil, fmt.Errorf("紧急停车按钮[%s]实体不存在", empId)
|
||
|
} else {
|
||
|
return empEntry, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 激活紧急停车按钮
|
||
|
func FireEmpPressed(world ecs.World, empId string) error {
|
||
|
entry, err := findEmpEntry(world, empId)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
components.EmpStateComponent.Get(entry).Pressed = true
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// 复位紧急停车按钮
|
||
|
func FireEmpReset(world ecs.World, empId string) error {
|
||
|
entry, err := findEmpEntry(world, empId)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
components.EmpStateComponent.Get(entry).Pressed = false
|
||
|
return nil
|
||
|
}
|