-
Notifications
You must be signed in to change notification settings - Fork 20
/
requests.go
167 lines (146 loc) · 4.8 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// This file is part of Gopher2600.
//
// Gopher2600 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Gopher2600 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
package sdlimgui
import (
"fmt"
"image"
"github.com/jetsetilly/gopher2600/bots"
"github.com/jetsetilly/gopher2600/coprocessor/developer"
"github.com/jetsetilly/gopher2600/debugger/govern"
"github.com/jetsetilly/gopher2600/gui"
"github.com/jetsetilly/gopher2600/hardware/riot/ports/plugging"
"github.com/jetsetilly/gopher2600/notifications"
)
type featureRequest struct {
request gui.FeatureReq
args []gui.FeatureReqData
}
// SetFeature implements gui.GUI interface.
func (img *SdlImgui) SetFeature(request gui.FeatureReq, args ...gui.FeatureReqData) error {
img.polling.featureSet <- featureRequest{request: request, args: args}
return <-img.polling.featureSetErr
}
// check length of arguments sent with feature request.
func argLen(args []gui.FeatureReqData, expectedLen int) error {
if len(args) != expectedLen {
return fmt.Errorf("wrong number of arguments (%d instead of %d)", len(args), expectedLen)
}
return nil
}
// featureRequests have been handed over to the featureReq channel. we service
// any requests on that channel here.
func (img *SdlImgui) serviceSetFeature(request featureRequest) {
var err error
switch request.request {
case gui.ReqSetEmulationMode:
err = argLen(request.args, 1)
if err == nil {
img.setEmulationMode(request.args[0].(govern.Mode))
}
case gui.ReqEnd:
err = argLen(request.args, 0)
if err == nil {
img.end()
}
case gui.ReqFullScreen:
err = argLen(request.args, 1)
if err == nil {
img.plt.setFullScreen(request.args[0].(bool))
}
case gui.ReqPeripheralChange:
err = argLen(request.args, 2)
if err == nil {
port := request.args[0].(plugging.PortID)
switch port {
case plugging.PortLeft:
img.playScr.peripheralLeft.set(request.args[1].(plugging.PeripheralID))
case plugging.PortRight:
img.playScr.peripheralRight.set(request.args[1].(plugging.PeripheralID))
}
}
case gui.ReqEmulationNotice:
if img.isPlaymode() {
err = argLen(request.args, 1)
if err == nil {
img.playScr.emulationNotice.set(request.args[0].(notifications.Notify))
}
}
case gui.ReqCartridgeNotice:
err = argLen(request.args, 1)
if err == nil {
notice := request.args[0].(notifications.Notify)
switch notice {
case notifications.NotifyPlusROMNewInstallation:
img.plusROMFirstInstallation = true
default:
if img.isPlaymode() {
img.playScr.cartridgeNotice.set(notice)
}
}
}
case gui.ReqROMSelector:
err = argLen(request.args, 0)
if err == nil {
if img.isPlaymode() {
img.wm.playmodeWindows[winSelectROMID].playmodeSetOpen(true)
} else {
img.wm.debuggerWindows[winSelectROMID].debuggerSetOpen(true)
}
}
case gui.ReqComparison:
err = argLen(request.args, 2)
if err == nil {
open := false
if request.args[0] != nil {
img.wm.playmodeWindows[winComparisonID].(*winComparison).render = request.args[0].(chan *image.RGBA)
open = true
}
if request.args[1] != nil {
img.wm.playmodeWindows[winComparisonID].(*winComparison).diffRender = request.args[1].(chan *image.RGBA)
open = true
}
img.wm.playmodeWindows[winComparisonID].(*winComparison).playmodeSetOpen(open)
}
case gui.ReqBotFeedback:
err = argLen(request.args, 1)
if err == nil {
f := request.args[0].(*bots.Feedback)
img.wm.playmodeWindows[winBotID].(*winBot).startBotSession(f)
}
case gui.ReqCoProcSourceLine:
err = argLen(request.args, 1)
if err == nil {
ln := request.args[0].(*developer.SourceLine)
srcWin := img.wm.debuggerWindows[winCoProcSourceID].(*winCoProcSource)
srcWin.gotoSourceLine(ln)
}
case gui.ReqScreenshot:
switch len(request.args) {
case 0:
img.glsl.shaders[playscrShaderID].(*playscrShader).screenshot.startProcess(modeSingle, "")
case 1:
img.glsl.shaders[playscrShaderID].(*playscrShader).screenshot.startProcess(modeSingle, request.args[0].(string))
default:
err = fmt.Errorf("wrong number of arguments (%d instead of 1 or zero)", len(request.args))
}
default:
err = fmt.Errorf("sdlimgui: unsupport feature request (%s)", request.request)
}
if err == nil {
img.polling.featureSetErr <- nil
} else {
img.polling.featureSetErr <- fmt.Errorf("sdlimgui: %s: %w", request.request, err)
}
}