From 60eca82a834ea9daa6fe561290ff8ebe26a52a05 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 24 Oct 2023 17:58:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9IBP=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=AF=B7=E6=B1=82=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fi/ibp.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/fi/ibp.go b/fi/ibp.go index 3e27e95..f1abf3d 100644 --- a/fi/ibp.go +++ b/fi/ibp.go @@ -9,43 +9,49 @@ import ( ) // 按下按钮 -func PressDownButton(w ecs.World, id string) { - w.Execute(func() { +func PressDownButton(w ecs.World, id string) 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.Val = true } else { - fmt.Printf("未找到id=%s的按钮\n", id) + return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) } + return ecs.NewOkEmptyResult() }) + return result.Err } // 抬起拉起按钮 -func PressUpButton(w ecs.World, id string) { - w.Execute(func() { +func PressUpButton(w ecs.World, id string) 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.Val = false } else { - fmt.Printf("未找到id=%s的按钮\n", id) + return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) } + return ecs.NewOkEmptyResult() }) + return result.Err } // 修改钥匙挡位 -func SwitchKeyGear(w ecs.World, id string, gear int32) { - w.Execute(func() { +func SwitchKeyGear(w ecs.World, id string, gear int32) 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.Val = gear } else { - fmt.Printf("未找到id=%s的钥匙开关\n", id) + return ecs.NewErrResult(fmt.Errorf("未找到id=%s的钥匙开关", id)) } + return ecs.NewOkEmptyResult() }) + return result.Err }