Skip to content

Commit f47aba9

Browse files
committed
chore: deleted fornow package
1 parent 4e8aa39 commit f47aba9

4 files changed

Lines changed: 112 additions & 108 deletions

File tree

cmd/hexecute/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/ThatOtherAndrew/Hexecute/internal/config"
1212
"github.com/ThatOtherAndrew/Hexecute/internal/draw"
13-
"github.com/ThatOtherAndrew/Hexecute/internal/fornow"
13+
"github.com/ThatOtherAndrew/Hexecute/internal/execute"
1414
gestures "github.com/ThatOtherAndrew/Hexecute/internal/gesture"
1515
"github.com/ThatOtherAndrew/Hexecute/internal/models"
1616
"github.com/ThatOtherAndrew/Hexecute/internal/opengl"
@@ -190,17 +190,17 @@ func main() {
190190
}
191191
} else if !app.LearnMode && len(app.Points) > 0 {
192192
x, y := window.GetCursorPos()
193-
fornow := fornow.New(app)
194-
fornow.RecognizeAndExecute(window, float32(x), float32(y))
193+
exec := execute.New(app)
194+
exec.RecognizeAndExecute(window, float32(x), float32(y))
195195
app.Points = nil
196196
}
197197
}
198198
wasPressed = isPressed
199199

200200
if app.IsDrawing {
201201
x, y := window.GetCursorPos()
202-
fornow := fornow.New(app)
203-
fornow.AddPoint(float32(x), float32(y))
202+
gesture := gestures.New(app)
203+
gesture.AddPoint(float32(x), float32(y))
204204

205205
spawn := spawn.New(app)
206206
spawn.SpawnCursorSparkles(float32(x), float32(y))

internal/execute/execute.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package execute
22

33
import (
4+
"log"
45
"os/exec"
56
"syscall"
7+
"time"
8+
9+
"github.com/ThatOtherAndrew/Hexecute/internal/models"
10+
"github.com/ThatOtherAndrew/Hexecute/internal/spawn"
11+
"github.com/ThatOtherAndrew/Hexecute/internal/stroke"
12+
"github.com/ThatOtherAndrew/Hexecute/pkg/wayland"
613
)
714

15+
type App struct {
16+
app *models.App
17+
}
18+
19+
func New(app *models.App) *App {
20+
return &App{app: app}
21+
}
22+
823
func Command(command string) error {
924
if command == "" {
1025
return nil
@@ -20,3 +35,44 @@ func Command(command string) error {
2035

2136
return cmd.Start()
2237
}
38+
39+
func (a *App) RecognizeAndExecute(window *wayland.WaylandWindow, x, y float32) {
40+
if len(a.app.Points) < 5 {
41+
log.Println("Gesture too short, ignoring")
42+
return
43+
}
44+
45+
processed := stroke.ProcessStroke(a.app.Points)
46+
47+
bestMatch := -1
48+
bestScore := 0.0
49+
50+
for i, gesture := range a.app.SavedGestures {
51+
match, score := stroke.UnistrokeRecognise(processed, gesture.Templates)
52+
log.Printf("Gesture %d (%s): template %d, score %.3f", i, gesture.Command, match, score)
53+
54+
if score > bestScore {
55+
bestScore = score
56+
bestMatch = i
57+
}
58+
}
59+
60+
if bestMatch >= 0 && bestScore > 0.6 {
61+
command := a.app.SavedGestures[bestMatch].Command
62+
log.Printf("Matched gesture: %s (score: %.3f)", command, bestScore)
63+
64+
if err := Command(command); err != nil {
65+
log.Printf("Failed to execute command: %v", err)
66+
} else {
67+
log.Printf("Executed: %s", command)
68+
}
69+
70+
a.app.IsExiting = true
71+
a.app.ExitStartTime = time.Now()
72+
window.DisableInput()
73+
spawn := spawn.New(a.app)
74+
spawn.SpawnExitWisps(x, y)
75+
} else {
76+
log.Printf("No confident match (best score: %.3f)", bestScore)
77+
}
78+
}

internal/fornow/fornow.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

internal/gesture/gesture.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ package gestures
22

33
import (
44
"encoding/json"
5+
"math"
6+
"math/rand/v2"
57
"os"
8+
"time"
69

710
"github.com/ThatOtherAndrew/Hexecute/internal/config"
811
"github.com/ThatOtherAndrew/Hexecute/internal/models"
912
)
1013

14+
type App struct {
15+
app *models.App
16+
}
17+
18+
func New(app *models.App) *App {
19+
return &App{app: app}
20+
}
21+
1122
func LoadGestures() ([]models.GestureConfig, error) {
1223
configFile, err := config.GetPath()
1324
if err != nil {
@@ -67,3 +78,43 @@ func SaveGesture(command string, templates [][]models.Point) error {
6778

6879
return os.WriteFile(configFile, data, 0644)
6980
}
81+
82+
func (a *App) AddPoint(x, y float32) {
83+
newPoint := models.Point{X: x, Y: y, BornTime: time.Now()}
84+
85+
shouldAdd := false
86+
if len(a.app.Points) == 0 {
87+
shouldAdd = true
88+
} else {
89+
lastPoint := a.app.Points[len(a.app.Points)-1]
90+
dx := newPoint.X - lastPoint.X
91+
dy := newPoint.Y - lastPoint.Y
92+
if dx*dx+dy*dy > 4 {
93+
shouldAdd = true
94+
95+
for range 3 {
96+
angle := rand.Float64() * 2 * math.Pi
97+
speed := rand.Float32()*50 + 20
98+
a.app.Particles = append(a.app.Particles, models.Particle{
99+
X: x + (rand.Float32()-0.5)*10,
100+
Y: y + (rand.Float32()-0.5)*10,
101+
VX: float32(math.Cos(angle)) * speed,
102+
VY: float32(math.Sin(angle)) * speed,
103+
Life: 1.0,
104+
MaxLife: 1.0,
105+
Size: rand.Float32()*15 + 10,
106+
Hue: rand.Float32(),
107+
})
108+
}
109+
}
110+
}
111+
112+
const MAX_POINTS = 2048
113+
114+
if shouldAdd {
115+
a.app.Points = append(a.app.Points, newPoint)
116+
if len(a.app.Points) > MAX_POINTS {
117+
a.app.Points = a.app.Points[len(a.app.Points)-MAX_POINTS:]
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)