rts-sim-module/fi/ibp.go

102 lines
2.7 KiB
Go
Raw Normal View History

2023-10-12 15:03:11 +08:00
package fi
import (
"fmt"
//"joylink.club/bj-rtsts-server/dto/request_proto"
2023-10-12 15:03:11 +08:00
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// 按下按钮
2023-10-24 17:58:28 +08:00
func PressDownButton(w ecs.World, id string) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
2023-10-12 15:03:11 +08:00
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry)
2023-10-23 13:30:08 +08:00
state.Val = true
2023-10-12 15:03:11 +08:00
} else {
2023-10-24 17:58:28 +08:00
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id))
2023-10-12 15:03:11 +08:00
}
2023-10-24 17:58:28 +08:00
return ecs.NewOkEmptyResult()
2023-10-12 15:03:11 +08:00
})
2023-10-24 17:58:28 +08:00
return result.Err
2023-10-12 15:03:11 +08:00
}
// 抬起拉起按钮
2023-10-24 17:58:28 +08:00
func PressUpButton(w ecs.World, id string) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
2023-10-12 15:03:11 +08:00
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry)
2023-10-23 13:30:08 +08:00
state.Val = false
2023-10-12 15:03:11 +08:00
} else {
2023-10-24 17:58:28 +08:00
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id))
2023-10-12 15:03:11 +08:00
}
2023-10-24 17:58:28 +08:00
return ecs.NewOkEmptyResult()
2023-10-12 15:03:11 +08:00
})
2023-10-24 17:58:28 +08:00
return result.Err
2023-10-12 15:03:11 +08:00
}
2023-10-20 13:20:05 +08:00
// 修改钥匙挡位
2023-10-24 17:58:28 +08:00
func SwitchKeyGear(w ecs.World, id string, gear int32) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
2023-10-12 15:03:11 +08:00
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
2023-10-20 13:20:05 +08:00
state := component.GearStateType.Get(entry)
state.Val = gear
2023-10-12 15:03:11 +08:00
} else {
2023-10-24 17:58:28 +08:00
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的钥匙开关", id))
2023-10-12 15:03:11 +08:00
}
2023-10-24 17:58:28 +08:00
return ecs.NewOkEmptyResult()
2023-10-12 15:03:11 +08:00
})
2023-10-24 17:58:28 +08:00
return result.Err
2023-10-12 15:03:11 +08:00
}
//func SetBypassBtn(w ecs.World, id string, p request_proto.BypassOperationReq_Operation) error {
//
// result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
// wd := entity.GetWorldData(w)
// entry, ok := wd.EntityMap[id]
// if ok {
// state := component.BitStateType.Get(entry)
// state.Bypass.BypassEnable = convertBypassBoolVal(p)
// state.Bypass.OldVal = state.Val
// } else {
// return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id))
// }
// return ecs.NewOkEmptyResult()
// })
// return result.Err
//}
//func SetBypassSwitchKey(w ecs.World, id string, p request_proto.BypassOperationReq_Operation) error {
// result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
// wd := entity.GetWorldData(w)
// entry, ok := wd.EntityMap[id]
// if ok {
// state := component.GearStateType.Get(entry)
// state.BypassEnable = convertBypassBoolVal(p)
// state.OldVal = state.Val == 0
// } else {
// return ecs.NewErrResult(fmt.Errorf("未找到id=%s的钥匙开关", id))
// }
// return ecs.NewOkEmptyResult()
// })
// return result.Err
//}
//
//func convertBypassBoolVal(p request_proto.BypassOperationReq_Operation) bool {
// val := true
// if p == request_proto.BypassOperationReq_bypass_reset {
// val = false
// }
// return val
//}