+198
Diff
round #0
+47
gamepad/.zed/tasks.json
+47
gamepad/.zed/tasks.json
···
1
+
[
2
+
{
3
+
"label": "Build & Run Firefly Emulator",
4
+
"command": "firefly_cli build && firefly-emulator --id voigt.go-gamepad",
5
+
//"args": [],
6
+
// Env overrides for the command, will be appended to the terminal's environment from the settings.
7
+
// "env": { "foo": "bar" },
8
+
// Current working directory to spawn the command into, defaults to current project root.
9
+
//"cwd": "/path/to/working/directory",
10
+
// Whether to use a new terminal tab or reuse the existing one to spawn the process, defaults to `false`.
11
+
"use_new_terminal": false,
12
+
// Whether to allow multiple instances of the same task to be run, or rather wait for the existing ones to finish, defaults to `false`.
13
+
// "allow_concurrent_runs": false,
14
+
// What to do with the terminal pane and tab, after the command was started:
15
+
// * `always` โ always show the task's pane, and focus the corresponding tab in it (default)
16
+
// * `no_focus` โ always show the task's pane, add the task's tab in it, but don't focus it
17
+
// * `never` โ do not alter focus, but still add/reuse the task's tab in its pane
18
+
"reveal": "always",
19
+
// What to do with the terminal pane and tab, after the command has finished:
20
+
// * `never` โ Do nothing when the command finishes (default)
21
+
// * `always` โ always hide the terminal tab, hide the pane also if it was the last tab in it
22
+
// * `on_success` โ hide the terminal tab on task success only, otherwise behaves similar to `always`
23
+
"hide": "never",
24
+
// Which shell to use when running a task inside the terminal.
25
+
// May take 3 values:
26
+
// 1. (default) Use the system's default terminal configuration in /etc/passwd
27
+
// "shell": "system"
28
+
// 2. A program:
29
+
// "shell": {
30
+
// "program": "sh"
31
+
// }
32
+
// 3. A program with arguments:
33
+
// "shell": {
34
+
// "with_arguments": {
35
+
// "program": "/bin/bash",
36
+
// "args": ["--login"]
37
+
// }
38
+
// }
39
+
"shell": "system",
40
+
// Whether to show the task line in the output of the spawned task, defaults to `true`.
41
+
"show_summary": true,
42
+
// Whether to show the command line in the output of the spawned task, defaults to `true`.
43
+
"show_command": true,
44
+
// Represents the tags for inline runnable indicators, or spawning multiple tasks at once.
45
+
// "tags": []
46
+
},
47
+
]
+4
gamepad/firefly.toml
+4
gamepad/firefly.toml
+7
gamepad/go.mod
+7
gamepad/go.mod
+8
gamepad/go.sum
+8
gamepad/go.sum
···
1
+
github.com/firefly-zero/firefly-go v0.8.1 h1:evb25qj7ELM0wy20IIHtW8+4MI1i+wqVOiCsYdTuh3M=
2
+
github.com/firefly-zero/firefly-go v0.8.1/go.mod h1:+X/XGyPdES51OESkV8NSf1mszEBZionoROM7x2pBofw=
3
+
github.com/firefly-zero/firefly-go v0.9.5 h1:BzBr4t76bDVVFwNaWJixs1XasqLNBIdg0k9JXblBfU4=
4
+
github.com/firefly-zero/firefly-go v0.9.5/go.mod h1:+X/XGyPdES51OESkV8NSf1mszEBZionoROM7x2pBofw=
5
+
github.com/orsinium-labs/tinymath v1.0.0 h1:Uzp3GmjWIBxMObx4MQi9ACDu4Q8WKjSRakB1OMo9Bu0=
6
+
github.com/orsinium-labs/tinymath v1.0.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A=
7
+
github.com/orsinium-labs/tinymath v1.1.0 h1:KomdsyLHB7vE3f1nRAJF2dyf1m/gnM2HxfTeV1vS5UA=
8
+
github.com/orsinium-labs/tinymath v1.1.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A=
+132
gamepad/main.go
+132
gamepad/main.go
···
1
+
package main
2
+
3
+
import ff "github.com/firefly-zero/firefly-go/firefly"
4
+
5
+
var (
6
+
point *ff.Point
7
+
center ff.Point
8
+
9
+
buttonN bool
10
+
buttonE bool
11
+
buttonS bool
12
+
buttonW bool
13
+
)
14
+
15
+
const (
16
+
radius = 26
17
+
third = ff.Width / 3
18
+
19
+
touchYcenter = third
20
+
touchXcenter = ff.Height/2 - radius/2
21
+
buttonYcenter = third * 2
22
+
buttonXcenter = ff.Height/2 - radius/2
23
+
)
24
+
25
+
func init() {
26
+
ff.Render = render
27
+
ff.Update = update
28
+
}
29
+
30
+
func update() {
31
+
// Buttons
32
+
buttons := ff.ReadButtons(ff.Combined)
33
+
34
+
if buttons.N {
35
+
buttonN = true
36
+
} else {
37
+
buttonN = false
38
+
}
39
+
if buttons.E {
40
+
buttonE = true
41
+
} else {
42
+
buttonE = false
43
+
}
44
+
if buttons.S {
45
+
buttonS = true
46
+
} else {
47
+
buttonS = false
48
+
}
49
+
if buttons.W {
50
+
buttonW = true
51
+
} else {
52
+
buttonW = false
53
+
}
54
+
55
+
// Touchpad
56
+
center = ff.Point{
57
+
X: touchXcenter,
58
+
Y: touchYcenter,
59
+
// X: ff.Width/2 - 45,
60
+
// Y: ff.Height / 2,
61
+
}
62
+
63
+
input, pressed := ff.ReadPad(ff.Combined)
64
+
if pressed {
65
+
point = &ff.Point{
66
+
X: center.X + input.X/20 - radius,
67
+
Y: center.Y - input.Y/20 - radius,
68
+
}
69
+
} else {
70
+
point = nil
71
+
}
72
+
}
73
+
74
+
func render() {
75
+
ff.ClearScreen(ff.ColorWhite)
76
+
77
+
// ff.DrawCircle(ff.Point{X: buttonYcenter - radius, Y: buttonXcenter - radius}, radius*3, ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1})
78
+
// ff.DrawCircle(ff.Point{X: touchYcenter - radius*2, Y: touchXcenter - radius}, radius*3, ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1})
79
+
ff.DrawLine(ff.Point{buttonYcenter, 0}, ff.Point{buttonYcenter, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
80
+
ff.DrawLine(ff.Point{touchYcenter, 0}, ff.Point{touchYcenter, ff.Height}, ff.LineStyle{ff.ColorGray, 1})
81
+
ff.DrawLine(ff.Point{0, ff.Height / 2}, ff.Point{ff.Width, ff.Height / 2}, ff.LineStyle{ff.ColorGray, 1})
82
+
83
+
// Buttons
84
+
// B
85
+
styleE := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
86
+
if buttonE {
87
+
styleE = ff.Style{FillColor: ff.ColorRed, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
88
+
}
89
+
ff.DrawCircle(ff.Point{X: buttonYcenter + radius, Y: buttonXcenter}, radius, styleE)
90
+
91
+
// A
92
+
styleS := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
93
+
if buttonS {
94
+
styleS = ff.Style{FillColor: ff.ColorGreen, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
95
+
}
96
+
ff.DrawCircle(ff.Point{X: buttonYcenter, Y: buttonXcenter + radius}, radius, styleS)
97
+
98
+
// Y
99
+
styleN := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
100
+
if buttonN {
101
+
styleN = ff.Style{FillColor: ff.ColorYellow, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
102
+
}
103
+
ff.DrawCircle(ff.Point{X: buttonYcenter, Y: buttonXcenter - radius}, radius, styleN)
104
+
105
+
// X
106
+
styleW := ff.Style{FillColor: ff.ColorWhite, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
107
+
if buttonW {
108
+
styleW = ff.Style{FillColor: ff.ColorBlue, StrokeColor: ff.ColorDarkBlue, StrokeWidth: 1}
109
+
}
110
+
ff.DrawCircle(ff.Point{X: buttonYcenter - radius, Y: buttonXcenter}, radius, styleW)
111
+
112
+
// Touchpad
113
+
style := ff.Style{
114
+
FillColor: ff.ColorWhite,
115
+
StrokeColor: ff.ColorDarkBlue,
116
+
StrokeWidth: 1,
117
+
}
118
+
119
+
ff.DrawCircle(ff.Point{
120
+
X: touchYcenter - radius*2,
121
+
Y: touchXcenter - radius,
122
+
}, radius*3, style)
123
+
124
+
style = ff.Style{
125
+
FillColor: ff.ColorBlue,
126
+
StrokeColor: ff.ColorDarkBlue,
127
+
StrokeWidth: 1,
128
+
}
129
+
if point != nil {
130
+
ff.DrawCircle(*point, radius, style)
131
+
}
132
+
}
History
1 round
0 comments
voigt.tngl.sh
submitted
#0
1 commit
expand
collapse
add gamepad demo
expand 0 comments
closed without merging