Mercurial > repos > blastem
comparison config.c @ 2306:62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 23 Mar 2023 22:37:08 -0700 |
parents | 0d1d5dccdd28 |
children | af3075c1e421 |
comparison
equal
deleted
inserted
replaced
2305:6aca1734d573 | 2306:62f316b76e9a |
---|---|
283 return; | 283 return; |
284 } | 284 } |
285 *pads = tern_insert_node(*pads, key, dupe_tree(val.ptrval)); | 285 *pads = tern_insert_node(*pads, key, dupe_tree(val.ptrval)); |
286 } | 286 } |
287 | 287 |
288 #define CONFIG_VERSION 6 | 288 static void update_menu_binding(char *key, tern_val val, uint8_t valtype, void *data) |
289 { | |
290 tern_node **key_bindings = data; | |
291 if (valtype != TVAL_PTR) { | |
292 return; | |
293 } | |
294 if (strcmp(val.ptrval, "ui.exit")) { | |
295 return; | |
296 } | |
297 *key_bindings = tern_insert_ptr(*key_bindings, key, strdup("ui.menu")); | |
298 } | |
299 | |
300 static void update_pad_menu_binding(char *key, tern_val val, uint8_t valtype, void *data) | |
301 { | |
302 tern_node **pads = data; | |
303 if (valtype != TVAL_NODE) { | |
304 return; | |
305 } | |
306 tern_node *buttons = tern_find_node(val.ptrval, "buttons"); | |
307 if (buttons) { | |
308 tern_foreach(buttons, update_menu_binding, &buttons); | |
309 val.ptrval = tern_insert_node(val.ptrval, "buttons", buttons); | |
310 } | |
311 tern_node *axes = tern_find_node(val.ptrval, "axes"); | |
312 if (axes) { | |
313 tern_foreach(axes, update_menu_binding, &axes); | |
314 val.ptrval = tern_insert_node(val.ptrval, "axes", axes); | |
315 } | |
316 *pads = tern_insert_node(*pads, key, val.ptrval); | |
317 } | |
318 | |
319 #define CONFIG_VERSION 7 | |
289 static tern_node *migrate_config(tern_node *config, int from_version) | 320 static tern_node *migrate_config(tern_node *config, int from_version) |
290 { | 321 { |
291 tern_node *def_config = parse_bundled_config("default.cfg"); | 322 tern_node *def_config = parse_bundled_config("default.cfg"); |
292 switch(from_version) | 323 switch(from_version) |
293 { | 324 { |
363 } | 394 } |
364 case 5: { | 395 case 5: { |
365 char *binding_o = tern_find_path_default(config, "bindings\0keys\0o\0", (tern_val){.ptrval = "ui.oscilloscope"}, TVAL_PTR).ptrval; | 396 char *binding_o = tern_find_path_default(config, "bindings\0keys\0o\0", (tern_val){.ptrval = "ui.oscilloscope"}, TVAL_PTR).ptrval; |
366 config = tern_insert_path(config, "bindings\0keys\0o\0", (tern_val){.ptrval = strdup(binding_o)}, TVAL_PTR); | 397 config = tern_insert_path(config, "bindings\0keys\0o\0", (tern_val){.ptrval = strdup(binding_o)}, TVAL_PTR); |
367 } | 398 } |
399 case 6: { | |
400 tern_node *key_bindings = tern_find_path(config, "bindings\0keys\0", TVAL_NODE).ptrval; | |
401 if (key_bindings) { | |
402 tern_foreach(key_bindings, update_menu_binding, &key_bindings); | |
403 config = tern_insert_path(config, "bindings\0keys\0", (tern_val){.ptrval = key_bindings}, TVAL_NODE); | |
404 } | |
405 tern_node *pad_bindings = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; | |
406 if (pad_bindings) { | |
407 tern_foreach(pad_bindings, update_pad_menu_binding, &pad_bindings); | |
408 config = tern_insert_path(config, "bindings\0pads\0", (tern_val){.ptrval = pad_bindings}, TVAL_NODE); | |
409 } | |
410 } | |
368 } | 411 } |
369 char buffer[16]; | 412 char buffer[16]; |
370 sprintf(buffer, "%d", CONFIG_VERSION); | 413 sprintf(buffer, "%d", CONFIG_VERSION); |
371 return tern_insert_ptr(config, "version", strdup(buffer)); | 414 return tern_insert_ptr(config, "version", strdup(buffer)); |
372 } | 415 } |