rts-sim-module/fi/ibp.go

58 lines
1.4 KiB
Go
Raw Normal View History

2023-10-12 15:03:11 +08:00
package fi
import (
"fmt"
"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
}