rts-sim-module/system/tow_position_button_system.go
2023-08-22 17:21:21 +08:00

69 lines
1.8 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 (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
)
// 两档按钮/旋钮系统
type TowPositionButtonSystem struct {
}
var towPosButtonsQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
func NewTowPositionButtonSystem() *TowPositionButtonSystem {
return &TowPositionButtonSystem{}
}
// world 执行
func (me *TowPositionButtonSystem) Update(w ecs.World) {
}
// 档位变换过程中指令
// 该指令执行后,按钮处于未知状态
func FireTowPositionButtonMoving(w ecs.World, buttonId string) error {
entry := 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 := 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
}