package fi import ( "fmt" "joylink.club/bj-rtsts-server/dto/request_proto" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/entity" ) // 按下按钮 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 { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) } return ecs.NewOkEmptyResult() }) return result.Err } // 抬起拉起按钮 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 { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的按钮", id)) } return ecs.NewOkEmptyResult() }) return result.Err } // 修改钥匙挡位 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 { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的钥匙开关", id)) } return ecs.NewOkEmptyResult() }) return result.Err } 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 }