MCPcopy Index your code
hub / github.com/AppleWin/AppleWin / ParseControllerMappingFile

Method ParseControllerMappingFile

source/SNESMAX.cpp:176–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176bool SNESMAXCard::ParseControllerMappingFile(UINT joyNum, const char* pathname, std::string& errorMsg)
177{
178 bool res = true;
179 YamlHelper yamlHelper;
180
181 try
182 {
183 if (!yamlHelper.InitParser(pathname))
184 throw std::runtime_error("Controller mapping file: Failed to initialize parser or open file");
185
186 if (yamlHelper.ParseFileHdr("AppleWin Controller Button Remapping") != 1)
187 throw std::runtime_error("Controller mapping file: Version mismatch");
188
189 std::string scalar;
190 while (yamlHelper.GetScalar(scalar))
191 {
192 if (scalar == SS_YAML_KEY_UNIT)
193 {
194 yamlHelper.GetMapStartEvent();
195 YamlLoadHelper yamlLoadHelper(yamlHelper);
196 std::string hid = yamlLoadHelper.LoadString("HID");
197 std::string desc = yamlLoadHelper.LoadString("Description");
198 for (UINT i = 0; i < SNESMAXCard::NUM_BUTTONS; i++)
199 {
200 const std::string buttonNum = StrFormat("%d", i + 1);
201 bool found = false;
202 std::string buttonStr = yamlLoadHelper.LoadString_NoThrow(buttonNum, found);
203 SNESMAXCard::Button button = SNESMAXCard::UNUSED;
204 if (found)
205 {
206 if (buttonStr == "A") button = SNESMAXCard::A;
207 else if (buttonStr == "B") button = SNESMAXCard::B;
208 else if (buttonStr == "X") button = SNESMAXCard::X;
209 else if (buttonStr == "Y") button = SNESMAXCard::Y;
210 else if (buttonStr == "LB") button = SNESMAXCard::LB;
211 else if (buttonStr == "RB") button = SNESMAXCard::RB;
212 else if (buttonStr == "SELECT") button = SNESMAXCard::SELECT;
213 else if (buttonStr == "START") button = SNESMAXCard::START;
214 else if (buttonStr == "") button = SNESMAXCard::UNUSED;
215 else throw std::runtime_error("Controller mapping file: Unknown button: " + buttonStr);
216 }
217 m_altControllerButtons[joyNum][i] = button;
218 }
219 }
220 else
221 {
222 throw std::runtime_error("Unknown top-level scalar: " + scalar);
223 }
224
225 break; // TODO: extend to support multiple controllers
226 }
227 }
228 catch (const std::exception& szMessage)
229 {
230 errorMsg = "Error with yaml file: ";
231 errorMsg += pathname;
232 errorMsg += "\n";
233 errorMsg += szMessage.what();

Callers

nothing calls this directly

Calls 8

StrFormatFunction · 0.85
InitParserMethod · 0.80
ParseFileHdrMethod · 0.80
GetScalarMethod · 0.80
GetMapStartEventMethod · 0.80
LoadStringMethod · 0.80
LoadString_NoThrowMethod · 0.80
FinaliseParserMethod · 0.80

Tested by

no test coverage detected