57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package operate
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/yohamta/donburi/filter"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/components"
|
||
"joylink.club/rtsssimulation/system"
|
||
)
|
||
|
||
var towPosButtonsQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
|
||
|
||
// 档位变换过程中指令
|
||
// 该指令执行后,按钮处于未知状态
|
||
func FireTowPositionButtonMoving(w ecs.World, buttonId string) error {
|
||
entry := system.QueryEntityById(w, towPosButtonsQuery, buttonId)
|
||
if nil == entry {
|
||
return fmt.Errorf("两档位按钮[%s]实体不存在", buttonId)
|
||
}
|
||
//
|
||
state := components.TowPositionButtonStateComponent.Get(entry)
|
||
state.Pos1 = false
|
||
state.Pos2 = false
|
||
//
|
||
return nil
|
||
}
|
||
|
||
// 档位变换到达pos1指令
|
||
// 执行该指令后,按钮处于pos1稳定态
|
||
func FireTowPositionButtonArrivedPos1(w ecs.World, buttonId string) error {
|
||
return fireTowPositionButtonArrivedPos(w, buttonId, true)
|
||
}
|
||
|
||
// 档位变换到达pos2指令
|
||
// 执行该指令后,按钮处于pos2稳定态
|
||
func FireTowPositionButtonArrivedPos2(w ecs.World, buttonId string) error {
|
||
return fireTowPositionButtonArrivedPos(w, buttonId, false)
|
||
}
|
||
func fireTowPositionButtonArrivedPos(w ecs.World, buttonId string, arrivedPos1 bool) error {
|
||
entry := system.QueryEntityById(w, towPosButtonsQuery, buttonId)
|
||
if nil == entry {
|
||
return fmt.Errorf("两档位按钮[%s]实体不存在", buttonId)
|
||
}
|
||
//
|
||
state := components.TowPositionButtonStateComponent.Get(entry)
|
||
if arrivedPos1 {
|
||
state.Pos1 = true
|
||
state.Pos2 = false
|
||
} else {
|
||
state.Pos1 = false
|
||
state.Pos2 = true
|
||
}
|
||
//
|
||
return nil
|
||
}
|