2023-08-23 16:01:01 +08:00
|
|
|
|
package operate
|
2023-08-22 17:21:21 +08:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/yohamta/donburi/filter"
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/components"
|
2023-08-23 16:01:01 +08:00
|
|
|
|
"joylink.club/rtsssimulation/system"
|
2023-08-22 17:21:21 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var towPosButtonsQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
|
|
|
|
|
|
|
|
|
|
// 档位变换过程中指令
|
|
|
|
|
// 该指令执行后,按钮处于未知状态
|
|
|
|
|
func FireTowPositionButtonMoving(w ecs.World, buttonId string) error {
|
2023-08-23 16:01:01 +08:00
|
|
|
|
entry := system.QueryEntityById(w, towPosButtonsQuery, buttonId)
|
2023-08-22 17:21:21 +08:00
|
|
|
|
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 {
|
2023-08-23 16:01:01 +08:00
|
|
|
|
entry := system.QueryEntityById(w, towPosButtonsQuery, buttonId)
|
2023-08-22 17:21:21 +08:00
|
|
|
|
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
|
|
|
|
|
}
|