change: tap/swipe with offset

This commit is contained in:
lilong.129
2025-03-17 14:36:09 +08:00
parent b412fa193b
commit 3e7e9b0ef9
5 changed files with 27 additions and 12 deletions
+9 -8
View File
@@ -95,13 +95,14 @@ func (o *ActionOptions) Options() []ActionOption {
options = append(options, WithScope(
o.Scope[0], o.Scope[1], o.Scope[2], o.Scope[3]))
}
if len(o.Offset) == 2 {
if len(o.TapOffset) == 2 {
// for tap [x,y] offset
options = append(options, WithTapOffset(o.Offset[0], o.Offset[1]))
} else if len(o.Offset) == 4 {
options = append(options, WithTapOffset(o.TapOffset[0], o.TapOffset[1]))
}
if len(o.SwipeOffset) == 4 {
// for swipe [fromX, fromY, toX, toY] offset
options = append(options, WithSwipeOffset(
o.Offset[0], o.Offset[1], o.Offset[2], o.Offset[3]))
o.SwipeOffset[0], o.SwipeOffset[1], o.SwipeOffset[2], o.SwipeOffset[3]))
}
if len(o.OffsetRandomRange) == 2 {
options = append(options, WithOffsetRandomRange(
@@ -132,9 +133,9 @@ func (o *ActionOptions) Options() []ActionOption {
}
func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) {
if len(o.Offset) == 2 {
absX += float64(o.Offset[0])
absY += float64(o.Offset[1])
if len(o.TapOffset) == 2 {
absX += float64(o.TapOffset[0])
absY += float64(o.TapOffset[1])
}
absX += o.GenerateRandomOffset()
absY += o.GenerateRandomOffset()
@@ -276,7 +277,7 @@ func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
// swipe [fromX, fromY, toX, toY] with offset [offsetFromX, offsetFromY, offsetToX, offsetToY]
func WithSwipeOffset(offsetFromX, offsetFromY, offsetToX, offsetToY int) ActionOption {
return func(o *ActionOptions) {
o.Offset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY}
o.SwipeOffset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY}
}
}
+3 -2
View File
@@ -216,7 +216,8 @@ type ScreenFilterOptions struct {
AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"`
Regex bool `json:"regex,omitempty" yaml:"regex,omitempty"` // use regex to match text
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_offset,omitempty"` // tap with point offset
SwipeOffset []int `json:"swipe_offset,omitempty" yaml:"swipe_offset,omitempty"` // swipe with direction offset
OffsetRandomRange []int `json:"offset_random_range,omitempty" yaml:"offset_random_range,omitempty"` // set random range [min, max] for tap/swipe points
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element
MatchOne bool `json:"match_one,omitempty" yaml:"match_one,omitempty"`
@@ -242,7 +243,7 @@ func WithAbsScope(x1, y1, x2, y2 int) ActionOption {
// tap [x, y] with offset [offsetX, offsetY]
func WithTapOffset(offsetX, offsetY int) ActionOption {
return func(o *ActionOptions) {
o.Offset = []int{offsetX, offsetY}
o.TapOffset = []int{offsetX, offsetY}
}
}